8. Queues and backpressure
One-liner. A queue converts a spike into a backlog — and moves the failure to the consumer.
Memorize
- Decouple: producer acks fast, consumer drains at its own rate.
- Visibility timeout must exceed processing time, or you get duplicate work.
- DLQ after N attempts; alert on depth, not just errors.
- Backpressure: bound the queue, shed load (429), or scale consumers on queue depth.
- Ordering only exists per partition/message group; global order costs throughput.
- Fan-out (SNS/EventBridge → many queues) when multiple consumers each need the event.
Trap. Unbounded queues — latency grows silently until the backlog is hours deep. Do this. Define the max acceptable lag and alert on it.
Check
A consumer occasionally takes 3 minutes, but the visibility timeout is 60 s, causing duplicate processing. What is the correct fix?
Why
The message reappears while still being processed. Timeout > p99 processing time (or heartbeat/extend it) is the fix.