Choose Lambda or ECS Fargate for an API.
Choose the compute model from the API workload and operating needs, then budget its database and network dependencies. Compare representative traffic and the complete cost path rather than assuming faster scaling or a smaller compute bill determines the better architecture.
Inside this article 5 sections +
Choose Lambda or ECS Fargate for an API by comparing the workload's execution shape, dependency limits, and operating responsibilities. Invocation-based Lambda can fit short, irregular requests with clear boundaries. An ECS service on Fargate can fit an application that benefits from a continuously running process, explicit runtime control, and managed container scheduling.
The useful comparison is the complete request path, including its database, network, front door, and background work. A compute service that scales quickly can still overwhelm a dependency or produce an expensive idle baseline elsewhere.
Define the API workload before comparing platforms
Consider an illustrative procurement API. Most calls read account settings or update a draft; a smaller set generates large supplier exports. Traffic is uneven across the working day, and each account has its own access rules. The interactive calls and exports should be evaluated as separate workload classes.
Record request rate over time, duration distributions, payload size, database connection occupancy, and the behavior of slow dependencies. Include authentication, startup work, and failed requests. An average duration alone cannot reveal whether occasional long operations dominate resource use or exceed a front-door timeout.
This guide compares a conventional invocation-based Lambda API path with an ECS service using Fargate capacity. Lambda has several deployment and serving modes with different capabilities, so confirm the exact mode, integration, Region, and quotas in the proposed design. Do not transfer a limit or concurrency assumption from one Lambda offering to another without checking it.
| Question | Invocation-based Lambda | ECS service on Fargate |
|---|---|---|
| How does work arrive? | Individual invocations with configured concurrency controls | Requests handled by running tasks and service scaling |
| What remains warm? | Execution-environment reuse is an optimization to understand | Application processes and pools live with each task |
| Who limits database demand? | Function admission and connection design | Task count, per-task pools, and request admission |
| Where do long exports go? | A separate asynchronous execution path | A worker path with its own capacity and lifecycle |
Treat runtime control as a concrete requirement
List the capabilities the application needs: native dependencies, startup initialization, connection reuse, streaming behavior, local temporary files, or sidecar processes. Then test those requirements against the selected runtime and HTTP integration. Container packaging by itself does not make Lambda and Fargate execution semantics identical.
With ECS, the team controls the container process and task definition while AWS manages Fargate's underlying compute. The team still owns health checks, deployment capacity, shutdown behavior, and application resource limits. With Lambda, the invocation model changes how process reuse and execution limits must be handled.
Keep durable state outside either runtime. A reused process can cache configuration or connections, but the application must survive replacement. A long export should have a durable operation record rather than depending on one HTTP connection remaining open until completion.
Budget concurrency at the database
For an illustrative steady arrival rate of 80 requests per second and average database occupancy of 0.15 seconds per request, expected active database occupancy is 12 connections under stable assumptions. If occupancy rises to 0.6 seconds, the same arrivals demand 48 active connections. These figures estimate pressure; they are not throughput benchmarks.
Lambda admission settings can limit the number of simultaneous invocations that reach the database. An ECS fleet can limit requests and pool sizes, but every additional task may add another pool. Six tasks with a maximum pool of 20 expose a potential 120 client connections before background workers and administrative access are considered.
Choose an explicit database budget and preserve headroom for recovery. A proxy can help manage connection reuse, but it cannot make expensive queries inexpensive. The dependency capacity guide explains why scaling callers without controlling occupancy can worsen the bottleneck.
Compare cost using a workload ledger
Model a representative period, including quiet time and bursts. For invocation-based compute, record invocation count, configured resources, billed duration behavior, and any provisioned capacity. For Fargate, record task size, running duration, minimum task count, and scaling behavior. Apply current regional prices only after these quantities are established.
Add the components outside compute: gateway or load balancer, logs and traces, NAT or endpoints, data transfer, database capacity, and required availability. A tiny compute bill can coexist with a larger fixed network or database bill. Do not infer the cheaper architecture from one service's pricing unit.
Separate normal operation from migration and incident costs. A design that saves idle compute but needs frequent manual recovery may not fit the team. The cloud cost allocation worksheet helps connect those pools to product usage without presenting speculative savings as measured results.
Run the smallest experiment that settles the choice
Implement one representative read and one write against the same controlled database fixture. Test warm requests, fresh capacity, a burst, and a slow dependency. Record successful throughput, tail latency, rejected work, connection pressure, and recovery after the burst. Include an account-isolation check so performance work does not bypass authorization.
Compare deployment and operation as well as request speed. Can the team diagnose a failed call, stop excessive work, rotate credentials, and release a new version without losing accepted operations? Those answers determine whether the platform fits the organization, not merely whether a sample endpoint runs.
Architecture design can turn this evidence into a compute decision, a downstream capacity budget, and a cost model that remains useful as the API grows. Keep the decision revisable when workload shape or operating needs change.