Fargate vs Lambda
Lambda runs short, event-driven functions with instant scaling and scale-to-zero billing but a 15-minute cap. Fargate runs long-lived containers with full runtime control but slower starts. They are complementary; pick by workload shape.
Overview
AWS Fargate and AWS Lambda are both serverless: you do not manage servers. The difference is the abstraction. Fargate runs containers with no fixed time limit. Lambda runs functions that respond to events and are capped at 15 minutes. They solve different problems and are often used together.
Key Differences
Lambda is event-driven and granular. A function spins up in response to an HTTP request, queue message, file upload, or schedule, runs briefly, and stops. It scales from zero to thousands of concurrent invocations almost instantly and bills per request and per GB-second. This makes it ideal for bursty, unpredictable, or sporadic work where paying only for actual execution matters. The trade-offs are the 15-minute limit, a constrained runtime, and cold starts that can add latency unless you use provisioned concurrency.
Fargate runs full containers under ECS or EKS. There is no hard execution timeout, so it suits long-running APIs, background workers, and processes that must stay up. You control the entire container image, including OS-level dependencies and large binaries that would not fit Lambda. The cost is slower startup (tens of seconds to launch a task) and billing for the whole time a task runs, even when idle, because Fargate does not scale to zero as gracefully.
In short, Lambda optimizes for fine-grained, event-driven elasticity. Fargate optimizes for steady, container-shaped workloads with full runtime control.
When to Choose Fargate
Choose Fargate for long-running services: web APIs, streaming consumers, batch jobs that exceed 15 minutes, and anything needing custom system dependencies or a specific container image. It is also a good fit when you already use containers and want a serverless way to run them without managing nodes.
When to Choose Lambda
Choose Lambda for short, event-driven functions and spiky traffic. It excels as glue between AWS services, for webhooks, scheduled jobs, and APIs with unpredictable load where scale-to-zero saves money. Provisioned concurrency mitigates cold starts when low latency is required.
Verdict
These are complementary rather than competing. Use Lambda for event-driven, short-lived, highly elastic tasks, and Fargate for long-running, container-based services. A common pattern combines them: Lambda handles ingestion and events, while Fargate runs the durable services behind them. Match the tool to the workload shape rather than picking one for everything.