Compare Amazon API Gateway and the Application Load Balancer for a container or Lambda backend: timeouts, payload limits, auth, throttling, WebSockets, pricing models and how traffic reaches private services.

Amazon API Gateway and the Application Load Balancer both put an HTTPS endpoint in front of your code, and both can route by path to Lambda functions or private services, which is why teams end up comparing them.
They come from different places: API Gateway is an API-management product with usage plans, authorizers and request validation, billed per request; the ALB is a layer 7 load balancer, billed per hour and per unit of load, built to spread traffic across targets with no opinion about what the API looks like.
This page compares them on the limits and features that decide most projects, and covers what Encore puts in front of services in your account.
For many projects the deciding factor is how long a request may run, and API Gateway's REST API quotas set the integration timeout at 50 ms to 29 seconds; Regional and private REST APIs can request more through Service Quotas, at the possible cost of a lower account-level throttle, while edge-optimized APIs cannot. HTTP APIs cap integrations at 30 seconds with no increase. Both cap payloads at 10 MB. An ALB's idle timeout defaults to 60 seconds and can be raised to 4,000, and container targets have no fixed body limit, so report generation, large uploads and slow LLM calls fit without workarounds.
API Gateway's strength is what it does before your code runs: REST APIs have usage plans and API keys for metering third-party clients, per-method throttling, request validation against a model, caching, and Lambda or Cognito authorizers; HTTP APIs add native JWT authorizers that check an identity provider's tokens. If you sell API access and need per-customer quotas without building them yourself, that is a genuine advantage. The ALB offers an OIDC or Cognito authentication action suited to browser logins, plus AWS WAF integration, which API Gateway REST APIs also support, and nothing for API keys or quotas.
The ALB supports WebSockets, HTTP/2 and gRPC to targets, while API Gateway WebSocket APIs are a separate product that turns each connection into Lambda or HTTP invocations per message, which is a different programming model from a long-lived socket in your service, and API Gateway does not proxy gRPC.
API Gateway charges per request, with HTTP APIs cheaper than REST APIs, so it costs nothing at zero traffic and grows linearly with volume. The ALB charges per hour plus load balancer capacity units, so it has a baseline cost and becomes cheaper per request as traffic grows. Spiky, low-volume Lambda APIs tend to favor API Gateway; steady container traffic tends to favor the ALB. Run your own numbers with real request volume, payload sizes and connection counts.
An ALB lives in your VPC and registers ECS tasks or EKS pods in private subnets as targets directly. API Gateway sits outside your VPC and reaches private services through a VPC link, which for HTTP APIs points at an ALB, NLB or Cloud Map service, so "API Gateway in front of ECS" usually means API Gateway in front of an internal load balancer. That is two products to configure and pay for, which is worth it only if you need the API Gateway features on top.
Encore is a backend framework with built-in infrastructure for TypeScript and Go, and the request path is part of the application. On deploy to your own AWS account Encore provisions an Application Load Balancer in public subnets in front of services running on ECS Fargate or EKS in private subnets, with certificates from ACM, and provisions an IAM role for the service. Encore's own API gateway runs as part of the app: it routes requests to endpoints, runs your auth handler before any endpoint marked auth: true, and validates requests against the endpoint's types.
Run in your terminal to get started locally.
// reports/reports.ts
import { api, Header } from "encore.dev/api";
import { getAuthData } from "~encore/auth";
interface ExportParams {
from: string;
to: string;
idempotencyKey?: Header<"Idempotency-Key">;
}
// A slow export that would hit a 29-second integration timeout behind API Gateway.
export const exportCsv = api(
{ expose: true, auth: true, method: "POST", path: "/reports/export" },
async (p: ExportParams): Promise<{ rows: number }> => {
const { userID } = getAuthData()!;
const rows = await buildReport(userID, p.from, p.to); // your query
return { rows };
},
);
Throttling and per-customer quotas are code in this model, for example a counter in an Encore cache keyspace keyed by the caller, rather than usage plans. If you need API Gateway's metering for a public API product, you can still put API Gateway in front of the Encore-provisioned load balancer; for a product backend serving its own clients, the ALB and the in-app gateway cover routing and auth.
A coding agent adding an endpoint only declares it with expose and auth; there is no route to add to a gateway configuration or a target group to create.
Best fit: TypeScript or Go backends on AWS that want an ALB in front of private services with auth and routing defined in application code, in their own account.
Choose the ALB for container services with steady traffic, long requests, WebSockets or gRPC. Choose API Gateway when the API itself is the product and you want usage plans, API keys and throttling managed for you, or when a mostly Lambda backend sees spiky, low traffic. Use both only when you genuinely need API Gateway's features in front of private container services.
For a container service on ECS that serves a regular HTTP API, an ALB is the simpler and usually cheaper front door at steady traffic, with long timeouts, WebSockets and gRPC. Choose API Gateway when you need its API-management features, such as usage plans with API keys, per-client throttling, request validation or JWT authorizers, or when the backend is mostly Lambda with spiky traffic.
The default integration timeout is 29 seconds for REST APIs, and Regional and private REST APIs can request a higher limit through Service Quotas, which may lower the account's throttle quota. HTTP APIs have a fixed maximum of 30 seconds. An ALB's idle timeout defaults to 60 seconds and can be raised to 4,000 seconds.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.