Serverless & Edge Computing
Functions as a service and serverless containers — the event-driven model, cold starts, scaling and concurrency, statelessness, pricing, edge runtimes built on V8 isolates, and when serverless is (and isn't) the right choice.
Serverless doesn't mean no servers — it means you don't manage them. You deploy code; the platform provisions, scales (including to zero) and patches the infrastructure, and you pay per request or per unit of execution time.
The model
// AWS Lambda handler (Node.js)
export const handler = async (event) => {
const { orderId } = JSON.parse(event.body);
const order = await db.get(orderId);
return { statusCode: 200, body: JSON.stringify(order) };
};Functions are event-driven: triggered by HTTP requests (via an API gateway or function URL), queue messages, file uploads to object storage, database change streams, schedules (cron) or other events.
| Platform type | Examples | Unit |
|---|---|---|
| Functions (FaaS) | AWS Lambda, Google Cloud Run functions, Azure Functions | A function per event |
| Serverless containers | Google Cloud Run, AWS Fargate/App Runner, Azure Container Apps | Any container that serves HTTP, scaled to zero |
| Edge functions | Cloudflare Workers, Vercel/Netlify Edge, Deno Deploy, Fastly Compute | Code running at hundreds of CDN locations |
| Serverless data | DynamoDB, Aurora Serverless, Neon, PlanetScale, Upstash, Firestore | Databases that scale and bill by usage |
How it scales
Each concurrent request gets its own execution environment (a microVM or isolate). 1,000 simultaneous requests → up to 1,000 environments, created on demand, reused for later requests, and discarded after idling.
Cold starts
When no warm environment is available, the platform must create one: start the microVM, load the runtime, download your code, run initialisation. That's a cold start — from ~100 ms (small Node/Go/Rust functions) to several seconds (large JVM apps). Later requests to a warm environment skip all of it.
Mitigations:
- Keep deployment packages small; lazy-load heavy modules.
- Choose fast-starting runtimes (Node, Python, Go, Rust); for Java, use SnapStart, GraalVM native images or CRaC.
- Provisioned concurrency / minimum instances keep environments warm (at a cost).
- Do expensive initialisation (SDK clients, DB connections) outside the handler so warm invocations reuse it.
Design constraints
- Stateless: environments can vanish at any time; keep state in databases, caches or object storage.
- Time limits: e.g. 15 minutes on Lambda; long jobs need step functions/workflows or containers.
- Database connections: thousands of concurrent functions can exhaust a database's connection limit — use a connection pooler/proxy (RDS Proxy, PgBouncer) or HTTP-based serverless databases.
- Idempotency: event sources deliver at least once, so handlers must tolerate duplicates (Message queues).
- Observability: distributed, short-lived executions need structured logs and tracing.
- Local development and testing is harder; emulators help partially.
Pricing
Typical FaaS pricing: a small charge per million requests plus GB-seconds (memory × duration). For example, a function with 512 MB running 100 ms costs 0.5 × 0.1 = 0.05 GB-s per call.
| Traffic pattern | Serverless | Always-on servers |
|---|---|---|
| Spiky or low, idle most of the time | Cheap — pay nothing when idle | Pay for idle capacity |
| Steady high load (24/7) | Often more expensive per request | Cheaper with reserved instances |
| Unpredictable bursts | Scales instantly | Needs headroom or autoscaling lag |
Edge computing
Edge runtimes run your code in CDN points of presence close to users — often within 50 ms of most of the world.
Many (Cloudflare Workers, Vercel Edge, Deno Deploy) use V8 isolates instead of containers or microVMs: thousands of lightweight sandboxes inside one V8 process (V8 internals). Isolates start in under 5 ms, so cold starts practically disappear.
| Isolate-based edge | Container/microVM FaaS | |
|---|---|---|
| Cold start | ~0–5 ms | ~100 ms–seconds |
| Location | Hundreds of PoPs | A few regions |
| Runtime | Web-standard APIs (fetch, Request/Response, Web Crypto); limited Node compatibility | Full Node, Python, Java, Go, containers |
| Limits | Tight CPU time and memory per request | Generous |
// Cloudflare Worker
export default {
async fetch(request, env) {
const url = new URL(request.url);
if (url.pathname.startsWith("/api/flags")) {
const flags = await env.FLAGS.get("flags", "json"); // KV store replicated to the edge
return Response.json(flags, { headers: { "Cache-Control": "max-age=30" } });
}
return env.ASSETS.fetch(request); // static files
},
};Good edge use cases: redirects and rewrites, auth checks, A/B testing and feature flags, personalisation, geolocation routing, image transformation, API gateways, static sites (this site is a static export served by Workers), and SSR with edge-friendly data.
The data problem: computing at the edge doesn't help if every request then queries a database in one region. Use edge caches, globally replicated key–value stores, read replicas, or keep data-heavy rendering near the database.
When to use serverless
| Great fit | Poor fit |
|---|---|
| APIs with variable traffic, startups and prototypes | Steady, high-throughput services where cost matters |
| Event processing: uploads, queues, webhooks, cron jobs | Long-running jobs, WebSocket servers (unless the platform supports them, e.g. Durable Objects) |
| Glue code between managed services | Latency-critical paths sensitive to cold starts |
| Edge logic close to users | Workloads needing GPUs, special hardware or full OS control |
- Serverless: deploy code or containers; the platform scales to zero and back; pay per use.
- Each concurrent request gets an execution environment; cold starts occur when one must be created.
- Mitigate cold starts with small packages, fast runtimes, init outside the handler, provisioned concurrency.
- Design stateless, idempotent handlers; pool database connections; respect time limits.
- Edge runtimes on V8 isolates start in milliseconds near users, with web-standard APIs and tight limits.
- Serverless suits spiky, event-driven work; steady heavy workloads are often cheaper on reserved servers.