Scale workers without overwhelming the database
Use a durable queue and proportional metric to scale workers, then cap concurrency at the safe rate of the downstream database.
LESSON GOALS
By the end, you can
- Choose proportional scaling signals such as backlog per worker or request count per target instead of misleading totals.
- Use queueing, throttling, concurrency caps, warm-up, and draining to absorb bursts without moving failure downstream.
01
Translate demand into a safe capacity target
Start with arrival rate, service time, acceptable queue age or request latency, warm-up time, and the safe capacity of every downstream dependency. The largest queue number is not enough by itself.
For queue workers, raw queue depth is not proportional to capacity: 10,000 messages means something different with 10 versus 100 workers. Backlog per worker and oldest-message age relate demand to capacity and the SLO. For HTTP fleets, request count per target or a correlated utilization metric can drive target tracking. CPU is useful only when it moves with demand.
Select target tracking for a stable desired metric, step scaling for severity bands, scheduled scaling for recurring events, and predictive scaling only for forecastable patterns. Include minimum, maximum, warm-up, scale-in protection, draining, and failure headroom. Elasticity is bounded by quotas, subnet IPs, startup, registration, and downstream connections. A correct policy states what happens while capacity catches up: queueing, backpressure, or controlled rejection.
02
Let producers and consumers scale independently
A durable queue allows producers to accept work while consumers process at another rate. It also makes waiting work measurable through backlog and age signals. Worker ASGs, ECS services, or EKS deployments can scale independently from an API. Lambda scales environments for concurrent invocations, but account and function concurrency plus downstream limits still apply.
Reserved concurrency reserves and caps a function; provisioned concurrency prepares environments to reduce startup latency. Neither makes a database accept more connections. Containers do not dictate one mechanism: ECS and EKS maintain desired tasks or pods, while the capacity layer must have room. Fargate removes host scaling; EC2-backed clusters need instance capacity. Serverless fits invocation or task boundaries, but long-lived services can use autoscaled containers.
Messaging is the demand buffer and signal; delivery guarantees are separate. Scale each tier against its constraint and preserve a hard ceiling before the fragile dependency.
03
Protect the bottleneck with an explicit ceiling
Elastic compute should stop growing before it overloads the finite database, API, or external service underneath it. If workers process 40 jobs per second each while a database safely accepts 400 writes per second, ten workers are the safe ceiling even if compute can launch 100. Target tracking can add workers until ten while queue-age alarms expose an SLO breach.
To process more, improve or partition the database path; raising compute maximum turns backlog into connection storms. Use bounded retries with jitter, batch where safe, and defer noncritical work. Reserve capacity for critical functions sharing an account, but do not confuse reservation with latency preparation. Observe desired, actual, healthy, and effective capacity; queue age; throttles; downstream connections; and completed rate.
Test a burst and AZ failure. Scale to zero only when startup meets the SLO, and keep minimum multi-AZ capacity when immediate availability is required. Admission control belongs before the dependency that can be exhausted. For a synchronous API, API Gateway throttling can shape accepted request rate and return an overload response, but its token-bucket targets are best-effort rather than a substitute for backend protection.
For asynchronous work, SQS accepts a durable backlog while worker maximums enforce the database-safe processing rate. These branches are observable: synchronous excess appears as throttled requests, queued excess appears as rising oldest-message age, and a missing consumer cap appears as database saturation. Decide deliberately which outcome callers can tolerate.
A payment lookup may reject quickly so clients retry with jitter; a render job may wait in a queue; a low-priority enrichment may be dropped. Preserve tenant isolation with per-client authorization and, where appropriate, usage controls so one noisy caller cannot consume every worker.
Compare the cost of retained backlog, idle minimums, and retries against the business cost of rejection, while never buying compute that merely accelerates failure at the database.
DECISION TABLE
Compare the architecture constraints
| requirement | choose | because | reject |
|---|---|---|---|
| Metric must stay near target as workers change | Target tracking on backlog per worker | Metric is proportional to capacity | Raw depth is not proportional |
| Known daily demand before 09:00 | Scheduled scaling plus reactive protection | Capacity is ready before demand | Reactive-only scaling pays warm-up |
| Lambda must not exceed 300 DB connections | Reserved concurrency or source maximum | A hard cap protects the DB | Provisioned concurrency does not impose this cap |
| Producer burst may queue | SQS between producer and workers | Work is retained and scaling is independent | Synchronous calls propagate overload |
GUIDED WORKED SCENARIO
Reason from the stated constraints
This is a guided example, not a question to memorise. The knowledge check uses new situations to test the same reasoning.
A processor receives 3,000 jobs per minute for ten minutes. Each worker completes 60 per minute, but the database safely permits 20 concurrent workers. Jobs must finish within 15 minutes.
Requirements
- Accept burst work durably
- Keep database concurrency at or below 20
- Keep oldest-message age below 15 minutes
- Drain active jobs on scale-in
Reasoning path
- Queue jobs so rates are independent.
- Use backlog per worker or age, not producer CPU.
- Set maximum to 20 unless connection use changes.
- Configure warm-up, draining, alarms, and bounded retries.
Why it wins
- The queue absorbs bursts while proportional metrics add useful capacity.
- The cap protects the actual bottleneck.
Why the alternatives lose
It causes database connection exhaustion.
Becomes correct when: Downstream capacity is proven for 200.It does not represent queued demand.
Becomes correct when: Producer CPU is the measured bottleneck and proportional.It addresses initialization, not safe database concurrency.
Becomes correct when: Cold starts decide and downstream supports 200.INTERACTIVE ARCHITECTURE VISUAL
Scale until the dependency—not the queue—says stop
The queue can absorb the burst, but the database-safe worker ceiling remains twenty.
× Request stopsCompute scaled beyond the database-safe ceiling. Cap workers at twenty or increase proven downstream capacity.
Read the diagram as text
Backpressure trace: producer rate, queue depth, oldest-message age, worker count, work per worker, database-safe concurrency, throttle result, retry behavior, and first unsafe scaling step.
KNOWLEDGE CHECK
Answer one question at a time
Pass every question to complete this lesson. Each answer includes reasoning before you continue.
KEY TERMS
Glossary
- Elasticity
- Adding or removing capacity as demand changes.
- Backlog
- Accepted work waiting to be processed.
- Backlog per worker
- Queue depth divided by active processing capacity; a proportional scaling signal.
- Oldest-message age
- How long the oldest unprocessed queue item has waited.
- Target tracking
- Scaling that adjusts capacity to keep a chosen metric near a target.
- Scheduled scaling
- Preparing capacity before a known recurring demand period.
- Backpressure
- Slowing, queueing, or rejecting work so a finite dependency is not overwhelmed.
- Reserved concurrency
- A Lambda setting that reserves and caps concurrency for a function.
- Provisioned concurrency
- Prepared Lambda execution environments used mainly to reduce startup latency.
- Draining
- Allowing active work to finish safely before capacity is removed.
PRIMARY SOURCES
Verify the claims
- primaryWhat is Amazon EC2 Auto Scaling?aws-compute-asg · retrieved 2026-07-29
- primaryTarget tracking scaling policies for Amazon EC2 Auto Scalingaws-asg-target-tracking · retrieved 2026-07-30
- primaryUnderstanding Lambda function scalingaws-lambda-function-scaling · retrieved 2026-07-30
- primaryLambda quotasaws-lambda-quotas · retrieved 2026-07-30
- primaryWhat is Amazon Elastic Container Service?aws-compute-ecs · retrieved 2026-07-29
- primaryWhat is Amazon Elastic Kubernetes Service?aws-compute-eks · retrieved 2026-07-29
- primaryAmazon SQS Developer Guideaws-int-sqs · retrieved 2026-07-29
- primaryApi Gateway Throttlingaws-api-gateway-throttling · retrieved 2026-07-30