One Tuesday afternoon, a region went through a two-hour cell tower outage. About 3,000 vehicle tracking devices went offline. The devices were smart: while they had no connection, they stored their locations in memory. At 16:20 the network came back, and 3,000 devices started unloading two hours' worth of accumulated data each, all at the same time. Our RabbitMQ queue ballooned to 6.2 million messages in 20 minutes, the broker hit its memory alarm, and it paused publisher connections. That was the real disaster: the live data from the 27,000 devices that hadn't been affected by the outage at all could no longer get into the queue either. One region's delayed data froze the live map for the entire country.
That day, we learned the concept of backpressure not from a book but on the battlefield.
The First Reflex: More Consumers
The classic move in a moment of panic: increase the number of consumers. We went from 4 consumers to 16, and the rate at which the queue drained barely changed. That's because the consumers weren't the bottleneck in the first place: every message was being INSERTed into MySQL one at a time, and the database disk saturated at about 3,500 writes per second. The 16 consumers just formed a bigger crowd at the same narrow door; with row locks in the mix, total throughput went up by 8 percent, and that was it. In a backpressure problem, the first question shouldn't be "how many workers do I have?" but "how fast does the slowest link in the chain let things through?" In our chain, the slowest link was the disk, and adding workers didn't make the disk any faster.
The First Leg of the Real Solution: Batch Writes
We turned the consumer from a loop that processed one message at a time into a structure that collects 500 messages and sends a single multi-row INSERT, and we set the prefetch value to 1000 to match this buffer. Acks went out in bulk after the batch commit. The number of statements sent to the database dropped to one in 500, and the same disk went from taking 3,500 rows per second to 41,000. In the drain test, a 6-million-message queue cleared in 22 minutes instead of 5.5 hours. It's a technique that has been known for years; the painful part is that you need to remember it on design day, not on disaster day.

When you switch to batch writes, there's a trap to watch out for, and we fell into it once ourselves. A single bad message inside a batch of 500 (an invalid coordinate, an unparseable packet) would fail the INSERT for the whole batch, and the consumer would retry the same batch in an infinite loop. Instead of draining, the queue was spinning around a single poison message. The solution has two layers: if a batch fails, split it in half and retry (binary split), and if a single message still fails once you get down to it, send that message to the dead-letter queue and move on. We review the dead-letter queue weekly, too; what lands there is often the first sign that a new device firmware has broken the protocol.
The Second Leg: Not All Messages Are Created Equal
Batch writes solved throughput but not fairness: while 6 million historical packets waited in line, live packets were queuing up behind them. Yet the urgency of the two is diametrically opposed. A customer looking at the live map wants to see their vehicle now, while the route from two hours ago is something a report will need. We split the traffic in two: based on the timestamp in the device protocol, we routed packets older than 5 minutes to the backfill queue and fresh ones to the live queue. Live queue consumers always take priority, and backfill consumers automatically throttle themselves when database write latency crosses a threshold. This way, the system's answer changed from "let everyone choke equally" to "let the live stream breathe no matter what."
This split had another visible benefit: the queue metrics finally started to mean something. Before, the length of the single queue was the sum of the live stream and the historical data, so it gave a clear answer to no question at all. Now the age of the live queue, meaning how many seconds the oldest message has been waiting, is the system's health indicator all by itself. If it goes above 5 seconds, something is wrong, and with an alert threshold that clear, the on-call engineer's life gets a lot easier. The length of the backfill queue, on the other hand, isn't an alert; it's capacity planning data. The same number taking on two different meanings in two separate queues was the sign that the design had been split in the right place.

The Third Leg: If You're Going to Choke, Choose Where
The essence of backpressure design is giving an honest answer to this question: when data arrives faster than the system's capacity, where does the excess wait, who slows down, and what gets sacrificed? If you leave it unanswered, the worst possible place makes that decision for you; for us, it was the broker's memory alarm. So we wrote the decisions down explicitly. Queues were switched to lazy mode so that millions of messages would wait on disk instead of in RAM. Queue lengths got limits and overflow policies. A separate real-time layer was set aside for the live map feed: only the latest location of each vehicle is kept, overwritten by key. The map looks at the latest state rather than at every single point at 30-second intervals, while the raw record side keeps storing every point on disk.
We also finally put the capacity math in writing, at least roughly. If the system's ingestion rate is 41,000 rows per second and the worst plausible outage scenario is a 4-hour backlog from 30,000 devices, the drain time is more or less known, and whether that time is acceptable is a business decision, not an engineering one. We brought this calculation to the customer side as well: being able to say after major outages that "historical data will be complete within at most this many minutes" visibly reduced the load on the support line. Uncertainty generates more complaints than delay does.
We also made changes on the producer side. In the device firmware, sending accumulated data started at full throttle as soon as a connection was established. In the new configuration, backfill sending puts small delays between packets and slows its pace if the server's responses slow down. The cheapest place for flow control is the source; managing 6 million messages that have already entered your data center is always more expensive than making sure they never come in at that rate.
Six weeks after the incident, we deliberately relived the same scenario; internally, we call this a fire drill. In the staging environment, we silenced 3,000 virtual devices for two hours and then released them all at once. The first drill exposed a gap in the new architecture: the backfill consumers were throttling themselves, but because they shared the same database connection pool with the live queue's consumers, the slowed-down backfill operations held on to connections in the pool and indirectly choked the live side. We separated the pools. Dependencies like these (a shared connection pool, a shared thread pool, a shared disk) quietly punch holes in isolation that exists on paper, and they only become visible under load. Backpressure design without drills is like a play that has never been rehearsed: you find out on opening night.

Not the Alert Threshold, the Slope
The last lesson is about monitoring. Our old alert said "fire if there are more than 100,000 messages in the queue," and by the time it fired on the day of the disaster, it was already too late. The new alert looks not at an absolute number but at the balance: if, over a five-minute window, the production rate exceeds the consumption rate and the gap keeps growing, it warns us while the queue is still at 50,000. Queue length is a snapshot; the gap between production and consumption is where the film is heading. You recognize a system that's choking from the film, not from the snapshot. If the answer to "what happens when it overflows?" isn't written down for your own queue architecture, write to us through our contact page. Writing that answer together on a calm day is much cheaper than writing it on a night full of alarms.