
Serverless Computing: Beginner's Blog Tutorial
Serverless Computing: Beginner's Blog Tutorial
Serverless computing runs code on-demand without provisioning servers. Cloud handles scaling, patching, and availability—you focus on code.
AWS Lambda (backend), Vercel/Netlify (frontend+functions) lead in 2026. Perfect for APIs, websites, automation.
Serverless computing runs code on-demand without provisioning servers. Cloud handles scaling, patching, and availability—you focus on code.
AWS Lambda (backend), Vercel/Netlify (frontend+functions) lead in 2026. Perfect for APIs, websites, automation.
Why Serverless in 2026?
Zero ops: No servers, patching, scaling
Pay-per-use: Free tier + $0.000016 per GB-second
Speed: Deploy in seconds, auto-scale to millions
DevOps boost: 70% faster deployments (State of Serverless 2026)
Zero ops: No servers, patching, scaling
Pay-per-use: Free tier + $0.000016 per GB-second
Speed: Deploy in seconds, auto-scale to millions
DevOps boost: 70% faster deployments (State of Serverless 2026)
Quick Start: Vercel (Easiest)
For frontend + API (Next.js recommended):
Connect GitHub: vercel.com → New Project → Import repo
Auto-deploy: Push to main → live URL instantly
Add API: Create /api/hello.js:
javascriptexport default function handler(req, res) {
res.status(200).json({ message: 'Hello Serverless!' });
}
Test: yourapp.vercel.app/api/hello
Zero config—handles builds, domains, SSL.
For frontend + API (Next.js recommended):
Connect GitHub: vercel.com → New Project → Import repo
Auto-deploy: Push to main → live URL instantly
Add API: Create
/api/hello.js:javascriptexport default function handler(req, res) { res.status(200).json({ message: 'Hello Serverless!' }); }Test:
yourapp.vercel.app/api/hello
Zero config—handles builds, domains, SSL.
AWS Lambda: Backend Power
Install CLI: aws.amazon.com/cli
serverless.yml (Serverless Framework):
textservice: my-api
provider:
name: aws
runtime: nodejs22.x
stage: dev
functions:
hello:
handler: handler.hello
events:
- http:
path: hello
method: get
handler.js:
javascriptexport const hello = async (event) => {
return {
statusCode: 200,
body: JSON.stringify({ message: 'Hello from Lambda!' })
};
};
Deploy:
bashnpm install -g serverless
serverless deploy
Test: curl https://abc123.execute-api.us-east-1.amazonaws.com/dev/hello
Install CLI: aws.amazon.com/cli
serverless.yml (Serverless Framework):
textservice: my-api provider: name: aws runtime: nodejs22.x stage: dev functions: hello: handler: handler.hello events: - http: path: hello method: get
handler.js:
javascriptexport const hello = async (event) => { return { statusCode: 200, body: JSON.stringify({ message: 'Hello from Lambda!' }) }; };
Deploy:
bashnpm install -g serverless serverless deploy
Test: curl https://abc123.execute-api.us-east-1.amazonaws.com/dev/hello
Netlify Functions: Jamstack APIs
netlify.toml:
text[build]
functions = "functions"
[functions]
node_bundler = "esbuild"
functions/create-user.js:
javascriptexports.handler = async (event) => {
const { name } = JSON.parse(event.body);
return {
statusCode: 201,
body: JSON.stringify({ id: 1, name })
};
};
Deploy: Connect GitHub at netlify.com → auto-deploys
Test: POST to /.netlify/functions/create-user
netlify.toml:
text[build] functions = "functions" [functions] node_bundler = "esbuild"
functions/create-user.js:
javascriptexports.handler = async (event) => { const { name } = JSON.parse(event.body); return { statusCode: 201, body: JSON.stringify({ id: 1, name }) }; };
Deploy: Connect GitHub at netlify.com → auto-deploys
Test: POST to /.netlify/functions/create-user
Serverless Databases
No servers for data either!
Service Best For Free Tier Supabase Postgres + auth 500MB DB + 50K monthly active users PlanetScale MySQL No free tier (paid plans only) DynamoDB NoSQL 25GB storage
Quick Supabase API (Vercel):
javascript// lib/supabase.js
import { createClient } from '@supabase/supabase-js';
const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY);
export default async function handler(req, res) {
const { data, error } = await supabase.from('todos').select('*');
res.json(data);
}
No servers for data either!
| Service | Best For | Free Tier |
|---|---|---|
| Supabase | Postgres + auth | 500MB DB + 50K monthly active users |
| PlanetScale | MySQL | No free tier (paid plans only) |
| DynamoDB | NoSQL | 25GB storage |
Quick Supabase API (Vercel):
javascript// lib/supabase.js import { createClient } from '@supabase/supabase-js'; const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY); export default async function handler(req, res) { const { data, error } = await supabase.from('todos').select('*'); res.json(data); }
Project: Serverless Todo API
Full-stack with Vercel + Supabase:
Next.js frontend (pages/index.js):
jsxexport default function Home() {
const [todos, setTodos] = useState([]);
useEffect(() => {
fetch('/api/todos').then(res => res.json()).then(setTodos);
}, []);
return (
<ul>{todos.map(todo => <li key={todo.id}>{todo.text}</li>)}</ul>
);
}
API (pages/api/todos.js):
javascriptimport supabase from '../../lib/supabase';
export default async function handler(req, res) {
const { data } = await supabase.from('todos').select('*');
res.json(data);
}
Deploy: git push → vercel.com auto-builds everything
Live at your-project.vercel.app with database!
Full-stack with Vercel + Supabase:
Next.js frontend (
pages/index.js):jsxexport default function Home() { const [todos, setTodos] = useState([]); useEffect(() => { fetch('/api/todos').then(res => res.json()).then(setTodos); }, []); return ( <ul>{todos.map(todo => <li key={todo.id}>{todo.text}</li>)}</ul> ); }API (
pages/api/todos.js):javascriptimport supabase from '../../lib/supabase'; export default async function handler(req, res) { const { data } = await supabase.from('todos').select('*'); res.json(data); }Deploy:
git push→ vercel.com auto-builds everything
Live at your-project.vercel.app with database!
Multi-Provider Comparison
Platform Best For Cold Start Free Tier Vercel Frontend + API ~200ms 100GB bandwidth Netlify Static sites ~500ms 125K function calls AWS Lambda Heavy backend ~100ms 1M requests/mo Cloudflare Workers Edge ~1ms 100K requests/day
| Platform | Best For | Cold Start | Free Tier |
|---|---|---|---|
| Vercel | Frontend + API | ~200ms | 100GB bandwidth |
| Netlify | Static sites | ~500ms | 125K function calls |
| AWS Lambda | Heavy backend | ~100ms | 1M requests/mo |
| Cloudflare Workers | Edge | ~1ms | 100K requests/day |
Common Pitfalls & Fixes
Issue Fix Cold starts Keep functions warm (cron ping) or use edge platforms Timeout Lambda: 15min max; Vercel Hobby: 10s default (raisable via maxDuration) Package size Tree-shake, use esbuild/webpack Vendor lock Abstract DB calls, use standard HTTP
Local dev: vercel dev, netlify dev, serverless offline
| Issue | Fix |
|---|---|
| Cold starts | Keep functions warm (cron ping) or use edge platforms |
| Timeout | Lambda: 15min max; Vercel Hobby: 10s default (raisable via maxDuration) |
| Package size | Tree-shake, use esbuild/webpack |
| Vendor lock | Abstract DB calls, use standard HTTP |
Local dev: vercel dev, netlify dev, serverless offline
Production Checklist
Set env vars (API keys, DB URLs)
Custom domain + SSL
Monitoring (Vercel Analytics, AWS CloudWatch)
CI/CD (GitHub Actions)
Rate limiting + CORS
Set env vars (API keys, DB URLs)
Custom domain + SSL
Monitoring (Vercel Analytics, AWS CloudWatch)
CI/CD (GitHub Actions)
Rate limiting + CORS
Code Templates
Vercel API:
javascriptexport default async (req, res) => {
// Your code
res.status(200).json({ success: true });
};
Lambda handler:
javascriptexport const main = async (event) => {
return { statusCode: 200, body: 'OK' };
};
Vercel API:
javascriptexport default async (req, res) => { // Your code res.status(200).json({ success: true }); };
Lambda handler:
javascriptexport const main = async (event) => { return { statusCode: 200, body: 'OK' }; };
Next Steps
Migrate existing API to Vercel
Add auth (Supabase Auth, Clerk)
Real-time (Supabase Realtime)
Challenge: Build URL shortener → deploy free
Serverless = ship faster. Pick one platform, master it, then expand. Drop your deployed URL in comments! ⚡
Migrate existing API to Vercel
Add auth (Supabase Auth, Clerk)
Real-time (Supabase Realtime)
Challenge: Build URL shortener → deploy free
Serverless = ship faster. Pick one platform, master it, then expand. Drop your deployed URL in comments! ⚡
Comments
No comments yet. Be the first to share your thoughts.


