Serverless Node.js: AWS Lambda, Vercel and Cloudflare Workers
Serverless platforms run your Node.js code on demand, scale automatically, and charge per execution. They're great for APIs with variable traffic, webhooks, and scheduled jobs.
AWS Lambda
export const handler = async (event) => {
const body = JSON.parse(event.body || '{}');
return {
statusCode: 200,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ received: body }),
};
};
Triggered by API Gateway, SQS, S3, EventBridge schedules, and more.
Vercel and Netlify Functions
Functions live alongside your frontend. Ideal for Next.js API routes, form handlers, and CMS webhooks (like Contentstack publish events).
Cloudflare Workers and Edge Runtimes
Run at the edge using Web Standard APIs (Request/Response), with very fast startup. Node.js API compatibility is good and improving, but not identical to full Node.
Cold Starts
The first request after idle time is slower. Reduce impact by:
- Keeping bundles small
- Lazy-loading heavy dependencies
- Using provisioned concurrency (Lambda) for critical paths
Database Connections
Many function instances can exhaust database connections. Use:
- Connection poolers (RDS Proxy, PgBouncer)
- Serverless-friendly databases and HTTP-based drivers
When Not to Use Serverless
- Long-running processes
- Steady high traffic (containers may be cheaper)
- WebSocket-heavy apps (unless the platform supports them well)
Serverless removes server management, not architecture decisions. Design for statelessness and short executions.