TECH_COMPARISON
Lambda vs Fargate: A Detailed Comparison for System Design
Compare AWS Lambda and Fargate for serverless compute — cold starts, pricing, runtime limits, and which fits your workload best.
Lambda vs Fargate
AWS Lambda and AWS Fargate are both serverless compute options, but they serve different workload profiles. Lambda runs event-driven functions with sub-second scaling. Fargate runs long-lived containers without managing servers.
Execution Model
Lambda — Functions as a Service
Lambda executes code in response to events: HTTP requests via API Gateway, S3 object uploads, DynamoDB stream changes, SQS messages, and dozens more triggers. Each invocation is isolated, stateless, and capped at 15 minutes. You write a handler function and AWS manages everything else.
Fargate — Serverless Containers
Fargate runs Docker containers as tasks in ECS or pods in EKS, but without provisioning or managing EC2 instances. You define CPU, memory, and your container image, and Fargate allocates the compute. Tasks can run indefinitely, making Fargate suitable for web servers, API backends, and background workers.
Pricing Deep Dive
Lambda charges per invocation ($0.20 per million) plus GB-seconds of compute. For sporadic workloads with low traffic, Lambda is extremely cheap — you may stay within the free tier. However, at sustained high throughput, Lambda costs escalate quickly.
Fargate charges per vCPU-hour and GB-hour. You pay for provisioned resources whether the container is busy or idle. For steady-state workloads running 24/7, Fargate is significantly cheaper than Lambda at equivalent compute.
Scaling Characteristics
Lambda scales near-instantly to thousands of concurrent executions. This makes it ideal for handling traffic spikes. Fargate scales by launching new tasks, which takes 30–60 seconds. For applications needing instant elasticity, Lambda wins.
Choosing Between Them
Many architectures use both: Lambda for event-driven glue and API endpoints, Fargate for long-running services and background processing. Understanding when to use each is a common system design interview topic. Explore related concepts and interview questions for deeper practice. Visit pricing for full access to architecture guides.
GO DEEPER
Master this topic in our 12-week cohort
Our Advanced System Design cohort covers this and 11 other deep-dive topics with live sessions, assignments, and expert feedback.