Architectural Styles Deep Dive · 4 of 8

Serverless — Functions That Wake Up on Demand

You hand a function to the platform; it scales from zero to thousands of concurrent invocations on demand and bills you per request and per ms of execution. There are servers — they're just not yours to patch, scale, or wake up at 3 a.m. for. The trade-off is a tightly constrained execution model.

FaaSEvent-DrivenPay-per-useAuto-Scale
← Back to Architecture
Quick Facts

What Serverless Is

Basic Concepts

  • Function-as-a-Service (FaaS): deploy a single function; the platform invokes it on every event.
  • Event-driven: triggered by HTTP requests, queue messages, scheduled timers, file uploads, DB changes.
  • Scale to zero: no idle cost. No traffic, no charge.
  • Stateless: each invocation gets a fresh execution context (or maybe a warm one — you don't get to choose).
  • The platforms: AWS Lambda, Google Cloud Functions / Cloud Run, Azure Functions, Cloudflare Workers, Vercel/Netlify Functions.
  • Beyond FaaS: "serverless" also covers managed DBs, queues, and storage where you don't pick instance sizes (Aurora Serverless, DynamoDB on-demand).
Why It Wins

What You Buy

No Servers to Run

No OS patches. No autoscaling groups. No fleet rotation for security CVEs. The platform runs everything; you write business logic.

Spiky Traffic, Cheap

If you're idle 23 hours a day and slammed for one, a serverless function pays for the busy hour and nothing for the rest. Compared to a always-on EC2 instance, it can be 10–100× cheaper.

Tiny Unit of Deployment

Each function is its own deployable. Roll out, roll back, version, alias — all per function. Trial a fix on 5% of traffic; promote if metrics hold.

Native Event Plumbing

The cloud provider's event sources wire directly to functions: S3 upload → Lambda; new row in DynamoDB → Lambda; queue message → Lambda; cron → Lambda. Glue work that would take a service in microservices is one config block here.

Where It Hurts

The Sharp Edges

Cold Starts

The first request after idle time pays for spinning up a fresh container. Latency: ~10ms (Cloudflare V8 isolates) to several seconds (Java on Lambda with a fat dependency tree). For latency-sensitive APIs, mitigate with provisioned concurrency, smaller bundles, or warm-up pings — or pick a different style.

Execution Limits
  • Wall-clock timeout: Lambda 15 min, Cloud Functions 9–60 min, Cloudflare Workers 30s. Long jobs need step functions or a different runtime.
  • Memory caps: a few GB at most.
  • Payload size: 6 MB sync, 256 KB async on Lambda. No streaming gigabytes through.
  • Package size: ~50–250 MB depending on platform. Native binaries and ML models often don't fit.
DB Connection Storms

Each function instance opens its own connection. Scale to 1,000 concurrent invocations and your Postgres collapses. Front the DB with a pooler (RDS Proxy, PgBouncer, Supabase) or use HTTP-native datastores (DynamoDB, Firestore, PlanetScale's edge driver).

No Local State

You can't keep an in-memory cache, a websocket connection, or a long-running session in the function. Push state to Redis, Durable Objects, or a database. Even "warm" instances can be killed at any moment.

Vendor Lock-in

Function signatures, event shapes, IAM, observability tooling — all platform-specific. Lambda code doesn't run on Cloud Functions without rewrites. Frameworks like Serverless Framework, SST, and OpenFaaS reduce this but don't eliminate it.

Local Dev & Debugging

Reproducing the cloud event shape and IAM context on your laptop is awkward. Tools (LocalStack, SAM, SST live mode) help but don't match production exactly. Distributed traces are essential — without them, debugging multi-function flows is guesswork.

Variants

Beyond Plain FaaS

Serverless Containers

Cloud Run, AWS App Runner, Azure Container Apps, Fargate. Bring a container, get scale-to-zero and per-request billing without function-style constraints. Same image runs locally and in prod. The middle ground between FaaS and Kubernetes.

Edge Functions

Cloudflare Workers, Vercel Edge, Lambda@Edge. Code runs in PoPs close to the user — single-digit-ms latency. Constrained runtimes (V8 isolates, no Node-native modules) but the cold start is near-zero. Sweet spot: auth, A/B routing, personalization, geolocation, image transforms.

Step Functions / Workflows

Orchestrate multiple functions into durable workflows that survive crashes and run for days. AWS Step Functions, Google Workflows, Temporal, Azure Durable Functions. Used for sagas, ETL, long-running approvals.

Decision

When to Pick Serverless

WorkloadServerless Fit
Webhooks, integrationsExcellent — bursty, stateless, short.
Scheduled jobs / cronExcellent — pay only when running.
Image / file processing on uploadExcellent — event-driven by nature.
Low-traffic APIs & admin toolsGreat — scale-to-zero saves money.
BFF / API gateway logicGreat — especially at the edge.
High-throughput latency-sensitive APIsIffy — cold starts hurt; cost surprises at scale.
Long-running jobs (>15 min)No — use containers or Step Functions.
Heavy in-memory state, ML inferenceNo — package limits, cold starts, GPU access.
WebSockets, persistent connectionsUse specialized runtimes (API Gateway WebSockets, Durable Objects).
Continue

Other Architectural Styles