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.

Intermediate 4 min readLesson 6 of 9

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

JavaScript
// 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 typeExamplesUnit
Functions (FaaS)AWS Lambda, Google Cloud Run functions, Azure FunctionsA function per event
Serverless containersGoogle Cloud Run, AWS Fargate/App Runner, Azure Container AppsAny container that serves HTTP, scaled to zero
Edge functionsCloudflare Workers, Vercel/Netlify Edge, Deno Deploy, Fastly ComputeCode running at hundreds of CDN locations
Serverless dataDynamoDB, Aurora Serverless, Neon, PlanetScale, Upstash, FirestoreDatabases 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: provision envCold: load runtime+codeInit (connect DB)Handler0250550700760

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 patternServerlessAlways-on servers
Spiky or low, idle most of the timeCheap — pay nothing when idlePay for idle capacity
Steady high load (24/7)Often more expensive per requestCheaper with reserved instances
Unpredictable burstsScales instantlyNeeds 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 edgeContainer/microVM FaaS
Cold start~0–5 ms~100 ms–seconds
LocationHundreds of PoPsA few regions
RuntimeWeb-standard APIs (fetch, Request/Response, Web Crypto); limited Node compatibilityFull Node, Python, Java, Go, containers
LimitsTight CPU time and memory per requestGenerous
JavaScript
// 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 fitPoor fit
APIs with variable traffic, startups and prototypesSteady, high-throughput services where cost matters
Event processing: uploads, queues, webhooks, cron jobsLong-running jobs, WebSocket servers (unless the platform supports them, e.g. Durable Objects)
Glue code between managed servicesLatency-critical paths sensitive to cold starts
Edge logic close to usersWorkloads needing GPUs, special hardware or full OS control
Key takeaways
  • 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.