# How do you scale an API on AWS?

By Vishal Kumar · Published 2026-11-05 · Updated 2026-11-13
Source: https://fungyaan.com/p/scale-an-api-on-aws
Tags: aws, scaling, system-design, architecture

**The verdict, which each step below earns:** the same steps as anywhere: find the bottleneck, then apply the cheapest fix. On AWS, each step has a managed building block:
- **CloudFront** and **ElastiCache** for caching;
- **an Application Load Balancer** in front of an **Auto Scaling group or ECS service** for stateless replicas;
- **RDS Proxy** for database connections;
- **Aurora or RDS read replicas** for read load;
- **SQS** to absorb write spikes;
- **AWS WAF** rate-based rules to stop abusive clients at the edge.

Add them in the order the bottleneck demands, not all at once.

> **Case file**
>
> | | |
> |---|---|
> | **The case** | Traffic climbs, latency follows, and the console offers a hundred services |
> | **Suspects** | Every AWS service at once |
> | **Culprit** | One specific limit: repeats, CPU, connections, reads, spikes or one client |
> | **The fix** | Find the bottleneck, then add the matching managed block |

## The case

Traffic climbs, latency follows, and the AWS console offers a hundred services that each promise to help. The temptation is to round them all up at once. But the culprit in a slow API is always one specific limit, and the detective's job is to find which one.

The reassuring clue: none of the ideas change on AWS. Caching, pooling, queueing and limiting are the same ideas you'd use anywhere; AWS hands you each one as a managed piece, ready to slot in when the evidence points to it.

The companion case, [How do you scale an API?](/p/scale-an-api), measures what each technique buys on one machine. This one maps those techniques to AWS services. Prices aren't quoted here because they vary by region and change; use the AWS Pricing Calculator for your own traffic.

## The map of suspects

Here's how each bottleneck lines up with its building block:

| Bottleneck | Technique | AWS service | Notes |
|---|---|---|---|
| Repeated reads of public data | Cache at the edge | **CloudFront** | Honours `Cache-Control`; even a 1-second cache collapses most repeats |
| Repeated reads of private or shared data | Shared cache | **ElastiCache** (Redis or Valkey) | Version cached values; protect hot keys |
| CPU in the API | More stateless replicas | **ALB + EC2 Auto Scaling** or **ECS (Fargate or EC2)** | Scale on CPU or request count per target; keep state out of instances |
| Too many database connections | Pooling | **RDS Proxy** (or PgBouncer on EC2) | Essential with Lambda or many small containers |
| Read load on the database | Read replicas | **RDS read replicas**, **Aurora replicas** | Replicas lag: route read-your-writes to the primary |
| Write spikes, slow work | Queue it | **SQS** (+ Lambda or workers) | Alarm on the age of the oldest message |
| One client flooding you | Limits at the edge | **AWS WAF** rate-based rules; **API Gateway** usage plans and throttling | Per-API-key limits for fairness |
| Global users | Serve from nearby | **CloudFront**; multi-region for data that must be local | Latency is mostly round trips |
| The database itself | Bigger instance, then partitioning and sharding | **RDS/Aurora** instance classes; partitioning inside PostgreSQL | Sharding is an application design, not a setting |

```mermaid
flowchart LR
  C["Clients"] --> W["WAF rate rules"]
  W --> CF["CloudFront cache"]
  CF --> ALB["Application Load Balancer"]
  ALB --> API["Stateless API: ECS or Auto Scaling"]
  API --> EC["ElastiCache"]
  API --> PX["RDS Proxy"]
  PX --> PR[("Primary")]
  PX --> RR[("Read replicas")]
  API --> Q[["SQS"]]
  Q --> WK["Workers"]
  WK --> PX
```

## Step 1: cache what repeats

**CloudFront in front of the API**, even for "dynamic" endpoints. If a response is the same for everyone for a second or a minute (a public catalogue, a leaderboard, a feed page), set `Cache-Control: public, max-age=…` and let CloudFront answer the repeats. In my measurements, a one-second cache in front of the app raised sustainable throughput by over 60× for a costly read. One second of staleness for that much headroom is one of the best bargains in system design, and I never stop admiring how little it asks.

**ElastiCache** for data shared across instances but not public. The [cache case](/p/cache-made-data-wrong) covers how not to serve wrong data from it.

## Step 2: stateless replicas behind a load balancer

**Application Load Balancer** (layer 7, health checks, path- and host-based routing) in front of either:
- an **EC2 Auto Scaling group**: target tracking on CPU (~50-70%) or on requests per target; or
- an **ECS service** on Fargate (no servers to manage) or on EC2 (cheaper at steady load; the [Lambda, Fargate or EC2 case](/p/lambda-fargate-ec2-cost) works through the numbers), with service auto scaling.

**Make the app stateless first.** This is the step that makes everything else easy, and the elegant reason is that once instances are interchangeable, adding one is arithmetic:
- sessions in Redis or a database, or signed cookies;
- uploads in S3;
- background work on queues;
- nothing important on local disk.

Scale out before the edge: capacity collapses suddenly past saturation, so keep headroom and scale on a leading signal.

**API Gateway** is the alternative front door when you want per-key throttling, usage plans, request validation and built-in auth, or when the backend is Lambda. Weigh its per-request pricing against an ALB at your traffic level.

## Step 3: protect the database

- **RDS Proxy** solves one of the most common scaling surprises. It pools and shares connections, so hundreds of containers or Lambda invocations don't open hundreds of database connections. Without a pooler, scaling the app out is how you take the database down ("too many connections"), a twist where the fix itself becomes the culprit.
- **Read replicas** (RDS: several per primary; Aurora: up to 15 replicas sharing one storage volume, as of Nov 2026) take read traffic. They lag behind the primary, so reads that follow a write go to the primary (the [CAP/PACELC case](/p/cap-pacelc) measures how stale "slightly behind" is).
- **Then a bigger instance**, then partitioning big tables, and sharding last (the [replicas/partitioning case](/p/replicas-partitioning-sharding)).

## Step 4: queue the spikes

**SQS** between the API and anything slow or spiky: emails, exports, integrations, heavy processing. The API accepts and enqueues; workers (EC2, ECS, or Lambda with an SQS event source) process at their own pace and scale on queue depth. A burst becomes a backlog instead of errors. Use an outbox so a message is published if and only if the database change committed ([when to queue a write](/p/queue-vs-api-writes) shows how). Alarm on `ApproximateAgeOfOldestMessage`, not only queue length.

## Step 5: limit each client

**AWS WAF rate-based rules** on CloudFront or the ALB stop floods per IP (or per header value) before they reach your code. **API Gateway usage plans** give per-API-key quotas and throttles. Fairness by customer or tenant still belongs in the app: one office behind one IP shouldn't be mistaken for one abusive client.

## How the case usually unfolds

The platform I run at CapGrid serves about 100,000 users at 5,000-10,000 requests per second, with 99.9% uptime and sub-200 ms API latency. It's built on AWS (EC2, Lambda, SQS, RDS, S3). Most products follow a similar progression:
1. **One instance** behind a load balancer, managed PostgreSQL, CloudFront for static assets.
2. **Caching and a pooler** as reads grow; **SQS** for anything slow.
3. **Auto Scaling replicas** once the app is stateless.
4. **Read replicas** when the primary's reads dominate.
5. **Partitioning and bigger instances,** and only then sharding or cells.

> **Remember this**
> - Find the limit first, then add the one block that fixes it.
> - Make the app stateless, and adding an instance becomes arithmetic.
> - Without a pooler, scaling out is how you take the database down.

## What I'd do on Monday

1. **CloudFront in front of everything**, with honest `Cache-Control` headers.
2. **ALB + ECS on Fargate** (or an EC2 Auto Scaling group) for a stateless API, scaling on CPU or requests with headroom.
3. **RDS or Aurora PostgreSQL with RDS Proxy** from the first scale-out.
4. **SQS for anything slow**, with an outbox and an age alarm.
5. **WAF rate rules at the edge**, and per-tenant limits in the app.
6. **Measure before each step:** CloudWatch metrics, traces and CloudWatch Database Insights tell you which step comes next.

The managed pieces let you spend your attention on the interesting question, which limit you're hitting, rather than on running the machinery that fixes it.
