advanced
Serverless
Use managed functions or containers to reduce server ownership while accounting for cold starts, limits, observability, and vendor coupling.
Serverless platforms (Lambda, Cloud Functions, Cloud Run, Azure Functions, Workers) run your code without managing servers — billing often ties to invocations, duration, and memory. FullStack JS teams use them for webhooks, cron, image thumbnailing, and BFF endpoints while keeping long-lived WebSockets or heavy CPU on containers or VMs.
| Factor | Implication | |--------|-------------| | Cold start | Keep bundles small; provisioned concurrency if needed | | Timeout | Split long jobs to queues | | State | Externalize to DB, cache, or object storage | | Observability | Structured logs, traces, cold-start metrics |
Package with esbuild or similar; avoid shipping entire `node_modules` when a minimal handler suffices. Use environment-specific config and secrets managers, not committed env files.
On interviews: when serverless beats containers, cold-start mitigation, VPC-attached Lambda trade-offs, local dev parity, and vendor limits (payload size, concurrency).
Common pitfalls: 15-minute batch jobs in functions; connection per invocation to Postgres; giant dependencies; assuming full Node API surface on edge runtimes.
The trade-off is ops simplicity and elastic scale versus unpredictable latency, execution limits, and platform coupling.
Checklist:
- Right-size memory after profiling duration cost.
- Use queues for work exceeding timeout budgets.
- Share nothing; externalize session and cache state.
- Measure cold starts in staging with realistic bundles.