Serverless Architecture Patterns: Lambda, Edge Functions, and When to Go Serverless
Serverless Architecture Patterns#
Serverless means you don't manage servers. You write functions, deploy them, and the platform handles scaling, availability, and infrastructure. Pay per invocation, not per hour.
But serverless isn't free — there are trade-offs. This guide covers when it works, when it doesn't, and the architecture patterns that matter.
What Serverless Actually Means#
Not "no servers" — the servers exist, you just don't manage them.
| You manage | Platform manages |
|---|---|
| Code / business logic | Servers, OS, patching |
| Configuration | Scaling (0 to 10K instances) |
| Permissions (IAM) | Availability, fault tolerance |
| Cost optimization | Load balancing, networking |
Serverless Platforms#
| Platform | Runtime | Cold Start | Best For |
|---|---|---|---|
| AWS Lambda | Node, Python, Go, Java, .NET | 100ms-10s | Event processing, APIs |
| Cloudflare Workers | JS/TS (V8 isolates) | < 5ms | Edge logic, low latency |
| Vercel Functions | Node, Edge Runtime | 50ms-500ms | Next.js API routes |
| Deno Deploy | TS/JS (V8 isolates) | < 10ms | Edge APIs, global |
| GCP Cloud Functions | Node, Python, Go, Java | 100ms-5s | GCP event triggers |
| Azure Functions | .NET, Node, Python, Java | 100ms-5s | Azure ecosystem |
| Supabase Edge | Deno | < 50ms | Supabase backend logic |
Architecture Patterns#
1. Serverless API#
Replace a traditional API server with functions:
Client → API Gateway → Lambda /users → DynamoDB
→ Lambda /orders → DynamoDB + SQS
→ Lambda /payments → Stripe API
Pros: Auto-scales to zero, no idle cost, per-request billing Cons: Cold starts affect latency, 15-minute max execution (Lambda) Best for: APIs with variable traffic, webhook handlers, MVPs
2. Event Processing Pipeline#
React to events from queues, databases, or file uploads:
S3 upload → Lambda (resize image) → S3 (thumbnails)
SQS message → Lambda (process order) → DynamoDB
DynamoDB Stream → Lambda (sync to Elasticsearch)
CloudWatch Event → Lambda (daily cleanup job)
This is where serverless shines. No idle servers waiting for events.
3. Edge Functions (Global Low-Latency)#
Run code at the CDN edge, closest to the user:
User (Tokyo) → Edge PoP (Tokyo) → Worker executes in < 5ms
User (NYC) → Edge PoP (NYC) → Worker executes in < 5ms
Use cases:
- A/B testing (decide variant at the edge)
- Authentication (validate JWT before hitting origin)
- Geolocation-based content
- Request rewriting / routing
- Personalization without origin round-trip
Tools: Cloudflare Workers, Vercel Edge Functions, Deno Deploy
4. Backend for Frontend (BFF)#
One serverless function per client type:
Mobile App → Lambda (mobile BFF) → aggregates 3 services → response
Web App → Lambda (web BFF) → aggregates 5 services → response
Internal → Lambda (admin BFF) → aggregates all services → response
Each BFF tailors the response shape for its client.
5. Fan-Out / Fan-In#
Process work in parallel, then aggregate:
Request → Orchestrator Lambda
→ Worker Lambda 1 (process chunk 1) → results
→ Worker Lambda 2 (process chunk 2) → results
→ Worker Lambda 3 (process chunk 3) → results
← Aggregator Lambda ← combines results → response
Use cases: Map-reduce, batch processing, parallel API calls
6. Scheduled Tasks (Cron)#
CloudWatch Events (every 5 min) → Lambda (health check)
EventBridge (daily at midnight) → Lambda (generate reports)
Vercel Cron → Edge Function (revalidate cache)
Replace cron servers with event-triggered functions.
The Cold Start Problem#
When a function hasn't been called recently, the platform must:
- Provision a container/isolate
- Load your code
- Initialize dependencies
- Execute your function
| Platform | Cold Start | Warm Invocation |
|---|---|---|
| Lambda (Node.js) | 200-500ms | < 10ms |
| Lambda (Java) | 2-10s | < 10ms |
| Cloudflare Workers | < 5ms | < 1ms |
| Vercel Edge | < 50ms | < 5ms |
Mitigation strategies:
- Provisioned concurrency (Lambda) — keep N instances warm ($$$)
- Edge functions — V8 isolates start in < 5ms (no container)
- Smaller bundles — less code = faster cold start
- Avoid Java/.NET for latency-sensitive paths
When NOT to Use Serverless#
| Scenario | Why Not |
|---|---|
| Long-running processes (> 15 min) | Lambda timeout limit |
| Consistent high traffic | Cheaper to run containers 24/7 |
| WebSocket connections | Serverless is request/response |
| GPU workloads (ML inference) | No GPU in Lambda |
| Low-latency P99 (< 10ms) | Cold starts break SLOs |
| Large memory (> 10GB) | Lambda max is 10GB |
| Stateful applications | Functions are stateless by design |
Cost Comparison#
Low traffic (10K requests/day)#
| Option | Monthly Cost |
|---|---|
| Lambda | ~$0.20 |
| EC2 t3.micro | ~$8.50 |
| Fargate (1 task) | ~$15 |
High traffic (10M requests/day)#
| Option | Monthly Cost |
|---|---|
| Lambda | ~$200 |
| EC2 c5.xlarge | ~$125 |
| Fargate (4 tasks) | ~$120 |
Rule of thumb: Serverless wins at low/variable traffic. Containers win at consistent high traffic.
Serverless + Traditional Hybrid#
Most production systems use both:
Client → CloudFront (CDN + Edge Functions for auth/routing)
→ API Gateway → Lambda (API handlers)
→ ECS Fargate (long-running workers, WebSocket)
→ Lambda (event processing from SQS/S3/DynamoDB)
Use serverless for event-driven and variable-traffic workloads. Use containers for predictable, long-running services.
Summary#
- Serverless = no server management, auto-scale, pay per use
- Edge functions for global low-latency (< 5ms cold start)
- Lambda for event processing and variable-traffic APIs
- Cold starts are the main trade-off — use edge or provisioned concurrency
- Don't go 100% serverless — hybrid is usually the right call
- Cost — cheaper at low traffic, more expensive at sustained high traffic
Design serverless architectures at codelit.io — generate interactive diagrams with cost estimates and infrastructure exports (Terraform, Pulumi, Railway).
Try it on Codelit
Chaos Mode
Simulate node failures and watch cascading impact across your architecture
Related articles
AI Agent Tool Use Architecture: Function Calling, ReAct Loops & Structured Outputs
6 min read
AI searchAI-Powered Search Architecture: Semantic Search, Hybrid Search, and RAG
8 min read
AI safetyAI Safety Guardrails Architecture: Input Validation, Output Filtering, and Human-in-the-Loop
8 min read
Try these templates
Netflix Video Streaming Architecture
Global video streaming platform with adaptive bitrate, CDN distribution, and recommendation engine.
10 componentsSearch Engine Architecture
Web-scale search with crawling, indexing, ranking, and sub-second query serving.
8 componentsGoogle Search Engine Architecture
Web-scale search with crawling, indexing, PageRank, query processing, ads, and knowledge graph.
10 componentsBuild this architecture
Generate an interactive Serverless Architecture Patterns in seconds.
Try it in Codelit →
Comments