Scale compute against a measured bottleneck
Choose an execution model, instance family and scaling signal that move with useful work.
Task 3.2 · Scale compute against a measured bottleneck
Classify the work
Record duration, arrival pattern, CPU and memory profile, startup delay, dependencies and acceptable queue time. Lambda handles bounded events up to its invocation time limit. Memory allocation also changes CPU entitlement, so benchmark total duration and cost. Containers preserve a runtime image. ECS on Fargate removes instance fleet management. EKS suits teams that need Kubernetes. AWS Batch queues and schedules jobs with resource requirements, and EMR runs distributed data frameworks such as Spark.
Choose a metric that falls as capacity grows
An ALB request count per target can track stateless request load. Backlog per available worker can track queued work. Overall queue depth alone does not indicate how much work each worker faces. Target tracking needs a metric that falls predictably as capacity increases at constant load. Keep sufficient minimum capacity for startup delays, account for warm-up and scale in carefully. For predictable daily peaks, pre-scale ahead of demand.
Size the individual worker
Benchmark representative memory, CPU, disk and network pressure. A larger general-purpose instance may hide a memory-bound workload at high cost. Try a memory-optimized family when the data set spills, or a compute-optimized family for CPU-bound work. Save durable state outside replaceable workers. Reserved concurrency can protect downstream systems by bounding Lambda concurrency. Provisioned concurrency can reduce initialization delay for a latency-sensitive alias.
Convert the latency target into a scaling target
If a worker completes one item every five seconds and queue wait must stay near one minute, an initial target is 60/5 = 12 waiting items per active worker. More workers reduce that metric while arrival rate stays fixed. Monitor oldest-message age separately, account for slow items and test startup delays. Use a scheduled minimum for known peaks. For work constrained by an external API, cap concurrency and work out whether the resulting queue delay still meets the service target.
The queue age climbs at lunch
An image worker processes 2 jobs per second. With arrivals at 24 per second and 480 already queued, the team wants to clear the backlog within 60 seconds while accepting new work. Assume constant measured rates and negligible startup delay for this calculation.
How many workers are needed, and what would you measure before shipping the policy?
Compare your design with the worked answer
Capacity must cover new arrivals plus 480/60 = 8 extra jobs per second. At 2 jobs per worker per second, 16 workers are needed. Monitor the oldest-message age, completion rate, failure count and saturation in the output store. Allow extra headroom in a real fleet for startup and job variance.
If the workers spend most of their time waiting on a throttled downstream API, adding workers can worsen throttling. Bound concurrency and adjust the downstream limit or buffer delay first.
Apply the video example
In the scaling-policy demonstration, identify the target metric, the desired fleet size and the maximum. A fleet capped at 12 workers cannot reach a calculated requirement of 16. Build an alarm for the workload delay at maximum size as well as an alarm for scaling activity.
freeCodeCamp at 21:46:50 · Scaling a fleet from an SQS backlog
Size a worker pool and replay a backlog
Save this as workers.py and run python3 workers.py. Each worker processes 60 jobs per minute. Model whole minutes, immediate scaling and a constant measured rate per worker. Predict when the queue clears in each run.
from math import ceil
def replay(starting_jobs, arrivals, rate, drain_minutes):
workers = ceil((arrivals + starting_jobs / drain_minutes) / rate)
remaining = starting_jobs
for minute in range(1, drain_minutes + 1):
remaining = max(0, remaining + arrivals - workers * rate)
print(f"minute {minute}: {workers} workers, {remaining} waiting")
replay(starting_jobs=240, arrivals=180, rate=60, drain_minutes=2)
replay(starting_jobs=240, arrivals=240, rate=60, drain_minutes=2)
Check the output and change one assumption
minute 1: 5 workers, 120 waiting
minute 2: 5 workers, 0 waiting
minute 1: 6 workers, 120 waiting
minute 2: 6 workers, 0 waitingThe first minute starts at the calculated target capacity. Increasing arrivals by 60 jobs per minute needs one additional worker just to maintain the same drain rate. Modify the loop to use only two workers in minute one. The original deadline is missed unless later capacity compensates for startup delay.
AWS exam guide for this domain · Return to the objective map
Scale compute against a measured bottleneck quiz
Answer 5 questions. Check each answer for an explanation.