Lag, backpressure and the queue that grows forever
An asynchronous system does not remove load, it stores it. The queue depth is the bill.
What you will be able to do
- Compute time-to-drain from arrival rate, service rate and backlog
- Choose a backpressure strategy for a given stage
- Distinguish a burst from a capacity deficit
- Explain why an unbounded queue is an outage in slow motion
Little's law, used out loud
The average number of items in a system equals arrival rate times time spent in the system. For a queue that means backlog ≈ arrival rate × wait. Two consequences matter: a stable backlog with growing wait means throughput is falling, and a growing backlog means arrival is beating service.
arrival = 2,000 events/s service = 2,400 events/s backlog = 1,200,000 events drain = 1,200,000 / (2,400 - 2,000) = 3,000 s = 50 min if service drops to 1,900 events/s: backlog grows by 100 events/s, never drains
Fifty minutes of drain at current rates — and the moment service dips below arrival, the arithmetic stops producing a number. That is the shape of every consumer-lag incident: healthy for weeks, then a deploy, a retry storm, or a hot partition tips it over.
What lag actually measures
| Metric | Meaning | Why it misleads |
|---|---|---|
| Lag count | Messages between newest and consumer offset | Meaningless without rate; 10k can be seconds or days |
| Lag age | Timestamp of newest message minus last processed | The one to alert on |
| Processing latency | Time per message inside the handler | Hides queueing time before the handler |
| Redelivery rate | Share of messages delivered more than once | Rises before lag does when a dependency is failing |
Four ways to push back
There is a fifth option people reach for first: add consumers. It works only if partitions exceed consumers. With twelve partitions and twelve consumers, the thirteenth consumer idles, no matter how much CPU the machine has.
Hot partitions break the average
Aggregate lag can be zero while one partition is hours behind. A single large customer or a popular product id concentrates traffic on one key. You see it only if you graph lag per partition. Fixes: split the hot key with a suffix and merge downstream, move that entity to a dedicated topic, or accept the limit and scale the handler for that key path.
Worth remembering
- Backlog divided by (service rate − arrival rate) is the drain time; when arrival exceeds service, that number is infinite.
- A queue converts a latency problem into a memory and money problem.
- Backpressure is a product decision: drop, delay, degrade, or refuse.
- Alert on lag age, not just lag count — a thousand messages behind in a fast stream is seconds, in a slow one it is hours.