TL;DR: Cloudflare Workers and AWS Lambda@Edge both execute code at the edge, but differ significantly in cold starts, pricing, and capabilities. Workers offer sub-5ms cold starts and generous free tier; Lambda@Edge integrates natively with AWS services. If you're evaluating edge computing for the first time, start with our Cloudflare Workers Introduction. Compare both at tanstackship.com.
Introduction
Edge computing brings code execution close to users, reducing latency from hundreds of milliseconds to single digits. Cloudflare Workers and AWS Lambda@Edge are the two dominant platforms. Choosing the right one depends on your cloud ecosystem, performance requirements, and budget. For context on why edge architecture matters for latency, see Reducing Time to First Byte (TTFB).
Architecture Comparison
| Feature | Cloudflare Workers | AWS Lambda@Edge |
|---|---|---|
| Runtime | V8 Isolates (isolated JS contexts) | Firecracker microVMs |
| Cold start | <5ms (typical) | 50-200ms (typical) |
| Memory limit | 128 MB (free), up to 128 MB | 128 MB to 10,240 MB |
| CPU time | 30s (free), 60s (bundled) | 5s (viewer), 30s (origin) |
| Language | JavaScript, TypeScript, WASM | Node.js, Python, Go, etc. |
| Request body size | 100 MB (free) | 1 MB (viewer), 30 MB (origin) |
| Deployment regions | 330+ locations | 13+ CloudFront edge locations |
Cold Start Analysis
Request # Workers (ms) Lambda@Edge (ms)
1 2 187
2 1 12
3 1 8
4 2 195 (scale event)
5 1 9
Average 1.4ms 82.2ms
P99 4ms 412ms
Pricing Comparison
| Scenario | Cloudflare Workers (10M requests) | Lambda@Edge (10M requests) |
|---|---|---|
| Compute cost | $0.50 (included in free tier) | $6.00 (first 10M free) |
| Additional request cost | $0.30 per million | $0.60 per million |
| Duration cost | Included | $0.00005 per 128MB-second |
| Free tier | 100k requests/day | 1M requests/month |
| Monthly cost (100M req) | ~$27 | ~$60-100 |
Code Examples
// Cloudflare Worker
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const url = new URL(request.url)
const cacheKey = `page:${url.pathname}`
// Check KV cache
const cached = await env.KV.get(cacheKey, 'json')
if (cached) {
return Response.json(cached, {
headers: { 'X-Cache': 'KV' }
})
}
// Fetch from origin
const response = await fetch(`https://origin.example.com${url.pathname}`)
const data = await response.json()
// Cache in KV (async)
env.KV.put(cacheKey, JSON.stringify(data), { expirationTtl: 300 })
return Response.json(data)
}
}
// AWS Lambda@Edge (origin request)
exports.handler = async (event) => {
const request = event.Records[0].cf.request
const response = event.Records[0].cf.response
// Add security headers
response.headers['strict-transport-security'] = [{
key: 'Strict-Transport-Security',
value: 'max-age=63072000; includeSubdomains; preload'
}]
response.headers['x-content-type-options'] = [{
key: 'X-Content-Type-Options',
value: 'nosniff'
}]
return response
}
Developer Experience
| Aspect | Cloudflare Workers | AWS Lambda@Edge |
|---|---|---|
| Local dev | wrangler dev (instant) | sam local or amplify mock |
| Deployment | wrangler deploy (2-3s) | CloudFormation / CDK (minutes) |
| Debugging | Console + tail logs | CloudWatch Logs |
| TypeScript | First-class support | Via esbuild/webpack |
| Testing | workerd (local runtime) | Docker or mock AWS |
When to Choose Which
| Scenario | Recommended Platform | Reason |
|---|---|---|
| Greenfield SaaS | Cloudflare Workers | Low cost, fast cold starts, simple DX |
| Already on AWS | Lambda@Edge | Native integration with CloudFront, S3, DynamoDB |
| High-traffic API | Cloudflare Workers | Sub-5ms cold starts at 330+ locations |
| Complex data processing | Lambda@Edge | Higher CPU and memory limits |
| Developer tool platform | Cloudflare Workers | Workers for Platforms, Durable Objects |
| Enterprise with AWS compliance | Lambda@Edge | SOC 2, HIPAA via AWS compliance |
Conclusion
Cloudflare Workers excels in cold start performance, global distribution, and developer experience — ideal for latency-sensitive SaaS applications. Lambda@Edge is the right choice if your infrastructure is deeply integrated with AWS. For most new SaaS projects, Cloudflare Workers offers better performance at lower cost.
To understand Workers' unique runtime, see Cloudflare Workers: JavaScript Runtime vs V8 Isolates. For infrastructure decisions around content delivery, our CDN Selection and Configuration Guide provides a broader perspective on edge services.