Edge ComputingCloudflare WorkersAWS LambdaServerlessComparison

Edge Computing: Cloudflare Workers vs AWS Lambda@Edge

Compare Cloudflare Workers and AWS Lambda@Edge across cold starts, pricing, runtime limits, and developer experience to choose the right edge platform for your SaaS.

Alex Chen
Alex Chen
June 1, 202615 min read
Also available in:Deutsch · 中文

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

FeatureCloudflare WorkersAWS Lambda@Edge
RuntimeV8 Isolates (isolated JS contexts)Firecracker microVMs
Cold start<5ms (typical)50-200ms (typical)
Memory limit128 MB (free), up to 128 MB128 MB to 10,240 MB
CPU time30s (free), 60s (bundled)5s (viewer), 30s (origin)
LanguageJavaScript, TypeScript, WASMNode.js, Python, Go, etc.
Request body size100 MB (free)1 MB (viewer), 30 MB (origin)
Deployment regions330+ locations13+ 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

ScenarioCloudflare 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 costIncluded$0.00005 per 128MB-second
Free tier100k requests/day1M requests/month
Monthly cost (100M req)~$27~$60-100

Code Examples

ts
// 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)
  }
}
js
// 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

AspectCloudflare WorkersAWS Lambda@Edge
Local devwrangler dev (instant)sam local or amplify mock
Deploymentwrangler deploy (2-3s)CloudFormation / CDK (minutes)
DebuggingConsole + tail logsCloudWatch Logs
TypeScriptFirst-class supportVia esbuild/webpack
Testingworkerd (local runtime)Docker or mock AWS

When to Choose Which

ScenarioRecommended PlatformReason
Greenfield SaaSCloudflare WorkersLow cost, fast cold starts, simple DX
Already on AWSLambda@EdgeNative integration with CloudFront, S3, DynamoDB
High-traffic APICloudflare WorkersSub-5ms cold starts at 330+ locations
Complex data processingLambda@EdgeHigher CPU and memory limits
Developer tool platformCloudflare WorkersWorkers for Platforms, Durable Objects
Enterprise with AWS complianceLambda@EdgeSOC 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.