Architecture

AWS Lambda vs Fargate: how to choose compute

A decision guide for AWS Lambda and AWS Fargate: workload shape, limits, cost at different utilization levels, operational effort, and hybrid architectures.

  • 4 min read
  • Updated December 2, 2026

"Should this run on Lambda or on containers?" is one of the most common architecture questions on AWS. Both AWS Lambda and AWS Fargate remove server management, but they suit different workload shapes. This guide gives a practical way to decide — and explains why many good architectures use both.

The short answer

  • Lambda is best for event-driven, short-lived, spiky, or low-to-moderate steady traffic, where scaling to zero and per-request billing matter.
  • Fargate is best for long-running processes, steady high-throughput services, workloads that need more than Lambda's limits, or software already packaged as a container that expects to run continuously.

How each one runs your code

Lambda runs a function per request or event in an isolated execution environment. AWS handles scaling: more concurrent events means more environments. You configure memory (CPU scales with it) and a timeout. You pay per request and per millisecond of execution.

Fargate runs containers as ECS tasks (or EKS pods) with a fixed vCPU and memory size. You decide how many tasks run, usually with auto scaling rules based on CPU, memory, or request count. You pay per second for the vCPU and memory of running tasks, whether they are busy or idle.

Hard limits that decide for you

Lambda has limits that make some workloads a poor fit:

  • Maximum execution time of 15 minutes.
  • Up to 10,240 MB of memory and roughly 6 vCPUs.
  • Synchronous request and response payloads up to 6 MB.
  • Up to 10 GB of ephemeral `/tmp` storage.
  • No long-lived inbound connections to a running function (WebSockets go through API Gateway, which invokes Lambda per message).

If a task routinely needs more time, memory, or a persistent process — a WebSocket server holding connections, a video transcoder running for an hour, a message broker client that must stay connected — Fargate is the natural home.

Cost: utilization is everything

Comparing price lists is misleading; what matters is how busy the compute is.

  • A service handling a few requests per minute, or traffic concentrated in business hours, costs very little on Lambda because idle time is free. The same service on Fargate pays for at least one task (usually two, for availability) 24 hours a day.
  • A service running at high, steady utilization all day can be cheaper on Fargate, because you pay for capacity once and keep it busy, instead of paying per request.

A useful exercise: estimate monthly Lambda cost from requests × average duration × memory, then estimate Fargate cost for the number of tasks needed at peak (with auto scaling at off-peak). Add the costs around each — an Application Load Balancer for Fargate, API Gateway for Lambda — and compare. Graviton (arm64) lowers the price of both, and Fargate Spot can cut costs further for interruption-tolerant work.

Operational effort

Both are "serverless" in the sense that you never patch hosts, but the operating model differs:

  • Lambda: no capacity planning, no container images to maintain (unless you choose image packaging), built-in scaling and retries for event sources. You manage concurrency limits, timeouts, and cold starts.
  • Fargate: you maintain images (base image updates, vulnerability scanning), task definitions, health checks, load balancer configuration, and auto scaling policies. In exchange you get a standard container runtime and long-lived processes.

Latency

Lambda adds occasional cold starts when new environments are created; well-bundled Node.js functions keep them short, and provisioned concurrency removes them where needed. Fargate tasks are always running, so there's no per-request start-up — but scaling out new tasks takes tens of seconds to minutes, so sudden spikes need headroom or pre-scaling.

Portability and existing code

If your application is a framework app (Express, NestJS, Spring Boot, Django) that expects to run as a long-lived server, Fargate runs it unchanged. Lambda can run it too — via adapters such as the AWS Lambda Web Adapter — but you get the most value from Lambda when code is organized as handlers responding to events.

A decision checklist

Choose Lambda when most of these are true:

  • Work is triggered by events: HTTP requests, queue messages, file uploads, schedules, stream records.
  • Each unit of work finishes in seconds to a few minutes.
  • Traffic is spiky, unpredictable, or low at times.
  • You want scaling and per-request billing without tuning.

Choose Fargate when most of these are true:

  • The process runs continuously or for longer than 15 minutes.
  • Traffic is high and steady around the clock.
  • The software is an existing container that expects a long-lived server.
  • You need more memory or CPU than Lambda offers, or specialized runtimes and sidecars.

The hybrid architecture

Real systems mix both. A typical pattern:

  • API Gateway and Lambda for the public API and event handlers.
  • SQS and Step Functions to coordinate background work.
  • Fargate tasks for the few steps that exceed Lambda's limits — started on demand by Step Functions (ecs:runTask integration) so they still only run when there is work.

This keeps the "pay for what you use" profile while removing Lambda's limits where they bite.

Summary

Decide by workload shape, not by preference: event-driven and spiky goes to Lambda; continuous, heavy, or long-running goes to Fargate; and many systems benefit from both behind the same API and queues.

If you're planning a move from EC2 or Elastic Beanstalk, our migration service starts with exactly this assessment for every component.

Services

Related services

How we can help you put this guide into practice.

Guides

More guides

Keep reading.

Let's make your serverless workload simpler, safer, and cheaper.

Start with a free 30-minute intro call with a serverless engineer.

Book a consultation