Topic lessonTopic: Designing event-driven processing
Backpressure: manage SQS backlog and downstream overload
Backpressure uses evidence of overload to slow the upstream flow of work. In a fictional image-processing system, limit concurrent consumers to protect the downstream database, then adjust intake to limit the time work waits in the queue.
Estimate backlog from arrival and completion rates, interpret queue depth and oldest-message age, and explain which upstream or downstream controls to adjust.
An SQS queue holds work between producers and consumers. The figures below are fixed teaching examples. They require no live AWS metrics or configuration changes.
A queue buys time to catch up
Unfinished work accumulates while arrivals outpace completions. A queue can absorb a short burst. If the gap persists, some requests will miss their required completion time.
- Image-processing intake → SQS queueEnqueues accepted work
- SQS queue → Lambda consumerDelivers batches
- Lambda consumer → Downstream databaseWrites results
- SQS queue → Image-processing intakeUses backlog signals to adjust intake
- Image-processing intake
- Adjusts the rate of new work
- SQS queue
- Holds work that is waiting
- Lambda consumer
- Limits concurrent work
- Downstream database
- Accepts result writes
Use arrival and completion rates to estimate recovery
| Interval | Arrival rate | Completion rate | Change in unfinished work |
|---|---|---|---|
| First 120 seconds | 80/s | 50/s | Adds 30 per second and leaves 3,600 unfinished. |
| After the peak | 30/s | 50/s | After serving new arrivals, drains 20 per second. |
| Until the backlog clears | 30/s | 50/s | 3,600 ÷ 20 = 180 seconds. |
New work continues after the peak, leaving 20 completions per second to clear the backlog. Dividing by the total completion rate of 50 per second instead models a complete stop in new arrivals. In an actual system, update the estimate as processing time, failures, and retries change.
Read depth, age, and downstream health together
Use ApproximateNumberOfMessagesVisible to follow the trend in messages available to receive. ApproximateAgeOfOldestMessage estimates the age in seconds of the oldest unprocessed message. Compare in-flight counts and end-to-end time from intake to result commit to see whether work is waiting elsewhere.
These metrics have approximation and reporting limits. In standard queues, repeatedly received messages that never complete can be left out of the oldest-age metric. When oldest age improves, also check failures, dead-letter records, and elapsed time for completed requests.
| Evidence | Control to consider | Recovery evidence |
|---|---|---|
| Database latency and failures increase | Cap consumer concurrency and reduce new intake. | Downstream error rate, completion rate, and backlog age. |
| Database has spare capacity and consumers hit a limit | Raise the limit in steps while checking available capacity. | Higher completion rate with acceptable downstream latency. |
| Low-priority batches monopolize intake | Separate admission limits and defer work that can wait. | Age for priority work and the number of deferred requests. |
With a standard-mode SQS event source mapping, Lambda maximum concurrency caps how many function instances the mapping can invoke at once. Batch size and processing duration also affect throughput, so translate concurrency into completions per second using observations.
Choose which control can restore throughput
Choose an option to see the result and explanation.
Check, then explain in your own words
- Compare accepted work and successful completions over the same observation window.
- Check oldest-message age, in-flight counts, and downstream latency together.
- Check downstream capacity before adjusting consumer concurrency and the intake rate.
Check your understanding: Lower Lambda concurrency protected the database. What should you check to keep waits acceptable too?
Compare the intake rate with the current completion rate and observe the trend in oldest-message age.
A consumer limit leaves the rate of new work unchanged. Adjust intake as needed and observe both completed work and the remaining backlog.
Sources and conditions checked
The official references used in this lesson are collected here with their scope, conditions and corresponding sections. Independent expert review and live AWS comparison have not been performed.
Scope and conditionsStandard-mode maximum concurrency, an event-source setting distinct from reserved concurrency.
Used in this lessonRead depth, age, and downstream health together
Scope and conditionsApproximate visible and in-flight counts, oldest age and its exclusions.
Used in this lessonRead depth, age, and downstream health together
Scope and conditionsQueue growth, backpressure and prioritization under sustained demand.
Used in this lessonA queue buys time to catch up Use arrival and completion rates to estimate recovery Read depth, age, and downstream health together