What is Serverless?
Running code without managing servers. Lambda functions, edge functions, and why vibecoders love serverless platforms.
The idea
Traditional servers:
You: Set up server, install dependencies, configure networking,
deploy code, monitor health, handle scaling, apply patches...Serverless:
You: Upload function
Cloud: We'll handle literally everything elseYou write a function. The cloud provider runs it when triggered, scales to handle load, and bills you per execution.
How it works
Traditional server
Server runs 24/7
↓
Handles requests when they arrive
↓
Sits idle when no requests
↓
You pay for idle timeServerless function
Function is dormant
↓
Request arrives
↓
Cloud spins up instance
↓
Function handles request
↓
Instance shuts down after timeout
↓
You pay only for execution timeWhat serverless functions look like
Vercel/Next.js API route
// app/api/hello/route.js
export async function GET(request) {
return Response.json({ message: 'Hello!' });
}
// Automatically deployed as serverless functionAWS Lambda
export const handler = async (event) => {
const name = event.queryStringParameters?.name || 'World';
return {
statusCode: 200,
body: JSON.stringify({ message: `Hello, ${name}!` }),
};
};Cloudflare Workers
export default {
async fetch(request) {
return new Response('Hello!', {
headers: { 'content-type': 'text/plain' },
});
},
};Popular serverless platforms
| Platform | Best for | Notes |
|---|---|---|
| Vercel Functions | Next.js apps | Zero config, automatic |
| Netlify Functions | Jamstack sites | Easy to set up |
| AWS Lambda | Everything | Most powerful, most complex |
| Cloudflare Workers | Edge computing | Runs closest to users, very fast |
| Supabase Edge Functions | Supabase projects | Integrates with Supabase |
| Railway | Full apps | Not strictly serverless but very easy |
When serverless makes sense
Good for serverless
API endpoints:
// Perfect: stateless request → response
export async function POST(req) {
const data = await req.json();
const result = await processData(data);
return Response.json(result);
}Webhooks:
// Receive webhook, process, return
export async function POST(req) {
const event = await req.json();
await handleStripeWebhook(event);
return new Response('OK');
}Scheduled tasks:
// Run daily at midnight
// (configured in platform)
export async function handler() {
await sendDailyReport();
await cleanupOldData();
}Background jobs:
// Triggered by queue/event
export async function handler(event) {
await processUploadedImage(event.imageId);
}Less ideal for serverless
Long-running processes:
// Problem: might hit timeout (often 10-30 seconds)
export async function handler() {
await veryLongProcess(); // Takes 5 minutes
}WebSocket connections:
// Problem: serverless functions are stateless
// Can't maintain persistent connections
// (Some platforms now support this, but it's limited)High consistent traffic:
// If you have 10,000 requests/second consistently,
// a traditional server is probably cheaperCold starts
The main gotcha with serverless.
What happens:
- Your function hasn’t been called in a while
- Request comes in
- Cloud needs to start a new instance (cold start)
- 100ms-2s delay before your code runs
- Subsequent requests hit the warm instance (fast)
Mitigations:
- Keep functions small (faster to start)
- Minimize dependencies (less to load)
- Use edge functions (Cloudflare Workers) for lowest latency
- Some platforms offer “warm” instances (costs more)
Serverless vs edge functions
Serverless functions:
- Run in specific regions (us-east-1, eu-west-1)
- More resources (memory, CPU, time)
- Standard Node.js environment
Edge functions:
- Run at 200+ locations worldwide
- Closest to users (lowest latency)
- More restricted environment
- Best for: fast responses, personalization, A/B testing
// Edge function (Cloudflare Workers, Vercel Edge)
export const config = { runtime: 'edge' };
export default function handler(request) {
// Runs close to user, very fast
return new Response('Hello from the edge!');
}Pricing model
Serverless pricing is based on:
- Invocations: Number of times function runs
- Duration: How long each run takes
- Memory: How much memory allocated
Example (rough AWS Lambda pricing):
- 1 million requests: ~$0.20
- Execution time: ~$0.0000166667 per GB-second
For most small apps: effectively free (generous free tiers).
At scale: can be cheaper or more expensive than servers, depending on traffic patterns.
Limits to know
| Limit | Typical value |
|---|---|
| Execution timeout | 10-30 seconds (some platforms allow more) |
| Memory | 128MB-3GB |
| Payload size | 5-10MB |
| Concurrent executions | 1000 (can be increased) |
| Cold start | 100ms-2s |
If you hit these limits, you might need:
- Break work into smaller chunks
- Use a background job queue
- Consider traditional servers
Serverless in practice
Next.js app on Vercel
// app/api/users/route.js
import { db } from '@/lib/db';
export async function GET() {
const users = await db.user.findMany();
return Response.json(users);
}
export async function POST(request) {
const data = await request.json();
const user = await db.user.create({ data });
return Response.json(user);
}
// Deploy to Vercel → automatically serverlessScheduled function (cron)
// Vercel cron job (configured in vercel.json)
export async function GET() {
await sendDailyEmails();
return new Response('Done');
}
// vercel.json
{
"crons": [{
"path": "/api/daily-emails",
"schedule": "0 8 * * *" // Every day at 8am
}]
}Serverless for vibecoders
Why vibecoders love serverless:
- No server management: Deploy and forget
- Auto-scaling: Handles 0 or 10,000 requests
- Pay for use: Free tier covers most small projects
- Fast deployment: Push code, it’s live
- Framework integration: Next.js, Remix just work
Most vibecoder projects never outgrow serverless. And if they do, migrating isn’t that hard.
Quick reference
// Vercel/Next.js API route
// app/api/example/route.js
export async function GET(request) {
return Response.json({ data: 'value' });
}
// With edge runtime (faster, more global)
export const config = { runtime: 'edge' };
// AWS Lambda format
export const handler = async (event, context) => {
return {
statusCode: 200,
body: JSON.stringify({ data: 'value' }),
};
};
// Cloudflare Workers
export default {
async fetch(request, env, ctx) {
return new Response('Hello!');
},
};Further reading
- What is a server? : Traditional alternative
- What is an API? : What serverless functions often implement
- What is deployment? : How serverless gets deployed
- What is scaling? : How serverless handles load
Frequently asked questions