StackMonkey

What happens when a message queue fills up?

A queue absorbs bursts, not sustained overload. How backlogs grow, what RabbitMQ, Kafka and SQS do at the limit, and where backpressure, retries and dead-letter queues fit.

By StackMonkey, . 13 minute read.

Line chart of queue depth growing by 200 messages a second until it hits a 500,000-message limit after 42 minutes, after which the broker must block, reject or drop messages

When a message queue fills up, the broker has to do one of three things with new messages: make the producer wait, refuse them, or throw old messages away. Which one happens depends on the broker and how it is configured, and some brokers have no fixed limit at all, so the backlog just gets older. In every case the cause is the same: for long enough, messages arrived faster than consumers removed them. A queue absorbs bursts. It cannot absorb sustained overload.

Key takeaways

  • A backlog grows by (arrival rate − drain rate) every second. At 1,200 messages a second in and 1,000 out, a 500,000-message queue is full in about 42 minutes.
  • At the limit, a RabbitMQ queue with a length limit drops its oldest messages by default, Kafka keeps data until retention deletes it, and SQS keeps accepting messages and deletes each one when its retention period ends.
  • Backpressure means bounding every buffer and slowing producers down when consumers fall behind, instead of letting the backlog grow without limit.
  • Retries without backoff and limits multiply load. Messages that will never succeed belong in a dead-letter queue, with an alarm on it.

Why does a message queue fill up?

A queue fills when producers add messages faster than consumers remove them, on average, for long enough. The arithmetic is simple:

backlog growth per second = arrival rate − drain rate
time until the limit      = queue limit ÷ (arrival rate − drain rate)

Take an order pipeline where producers publish 1,200 messages a second and 10 consumers each process 100 a second, so the queue drains 1,000 a second. The backlog grows by 200 messages every second. If the queue is capped at 500,000 messages, it is full after 500,000 ÷ 200 = 2,500 seconds, about 42 minutes.

The size of the backlog is also a delay. Consumers clear 1,000 messages a second, so a message that joins the back of a 500,000-message queue waits about 500 seconds, more than 8 minutes, before anyone reads it. Long before the queue is technically full, the messages in it can already be too old to be useful.

The Google SRE book makes the same point about request queues: "Queued requests consume memory and increase latency", and if the request rate is constant "there is no reason to queue requests" at all (Site Reliability Engineering, Addressing Cascading Failures). A queue earns its place when demand rises above capacity for a while and then falls back below it.

0k100k200k300k0 min4 min8 min12 minBurst ends: 240,000 queuedEmpty at 11 minTime since the burst started
A 60-second burst of 5,000 messages a second against consumers that drain 1,000 a second, followed by normal traffic of 600 a second. Illustrative rates; backlog = (arrival − drain) × time.

In the burst above, consumers keep up with normal traffic and fall behind for one minute. The queue absorbs the spike and is empty again 11 minutes after the burst began, 10 minutes after it ended. That is a queue doing its job. In the 1,200-in, 1,000-out example, traffic never falls below capacity, so no queue size is big enough.

What does the broker do when the queue is full?

Brokers handle the limit in different ways, and the defaults matter:

Broker What sets the limit What happens at the limit
RabbitMQ queue x-max-length or x-max-length-bytes on the queue By default, drops or dead-letters messages from the front of the queue (the oldest). With reject-publish, refuses new messages instead
RabbitMQ node Memory or disk alarm; the memory threshold defaults to 60% of RAM Blocks publishing connections until the alarm clears. Consumers keep running
Apache Kafka Retention by time (default 168 hours) or size (no size limit by default) Keeps accepting writes and deletes old data when retention expires, whether or not slow consumers have read it. A producer that cannot send fast enough blocks for up to max.block.ms (default 60 seconds) and then fails
Amazon SQS Message retention period (default 4 days, maximum 14) No limit on stored messages, though there is a quota on messages being processed at once (in flight). Messages older than the retention period are deleted

Sources: RabbitMQ queue length limit, RabbitMQ memory and disk alarms, RabbitMQ memory threshold, Kafka broker configs, Kafka producer configs, SQS SetQueueAttributes.

Two default behaviours lose data quietly: RabbitMQ's overflow setting for queues with a length limit, and retention expiry in Kafka and SQS. With the default overflow, a full RabbitMQ queue keeps the newest messages and discards the oldest. In the order pipeline, messages now leave the front of the queue at 1,200 a second (1,000 consumed and 200 dropped), so orders that have waited about 7 minutes (500,000 ÷ 1,200 ≈ 417 seconds) disappear to make room for new ones. Kafka and SQS do not refuse writes either, but a consumer that stays behind for longer than the retention period never sees the messages that expired.

The safer pattern is to make the limit visible to producers. RabbitMQ's reject-publish overflow mode refuses new messages instead of discarding old ones, so the producer can find out (for example through publisher confirms) and slow down or fail the request. Its reject-publish-dlx mode also dead-letters the rejected messages.

What is backpressure in a message queue?

Backpressure is a signal that travels from a slow consumer back to the producer, telling it to slow down. Without it, the only places left for extra messages are an ever-growing buffer or the floor.

The Reactive Streams specification describes the goal: "the receiving side is not forced to buffer arbitrary amounts of data", and back pressure exists "to allow the queues which mediate between threads to be bounded". Brokers apply the same idea at different layers:

  • Block the producer. When a RabbitMQ node hits its memory or disk alarm, "publishing connections will be blocked by TCP back pressure" (RabbitMQ alarms). A Kafka producer whose 32 MiB send buffer (buffer.memory) is full blocks the calling thread. That only happens when the brokers cannot accept data fast enough; a slow Kafka consumer never slows producers down, it just falls further behind.
  • Refuse the message. A bounded queue that rejects publishes turns overload into an error the producer can handle: retry later, shed the request, or tell the user. A rate limiter in front of the producer applies the same idea one step earlier.
  • Limit what each consumer takes. Google Cloud Pub/Sub's subscriber flow control caps how many messages a client holds at once. Its documentation notes that needing flow control at all "indicates that messages are being published at a higher rate than they are being consumed", and recommends adding subscriber instances when the imbalance persists rather than only tuning flow control (Pub/Sub flow control).

Backpressure does not make the work disappear. It moves the decision about what to do with excess load to the producer, which is usually the only part of the system that knows whether a message can wait, be dropped, or should fail fast.

How do retries make a full queue worse?

A consumer that fails to process a message usually retries it. If the failure is caused by overload, those retries add work to a system that is already behind.

Go back to the order pipeline and suppose a downstream payment service starts failing (the payment system template models one). If every message is now attempted four times (the first try plus three immediate retries), each consumer does four times the work per message. The queue drains 250 messages a second instead of 1,000, the backlog grows by 950 a second instead of 200, and the 500,000-message queue is full in under 9 minutes instead of 42.

Retries also multiply across layers. Amazon's Builders' Library gives the example of a five-layer service where each layer retries three times: load on the database "will increase 243x" (Timeouts, retries, and backoff with jitter). Three practices keep retries from becoming the outage:

  1. Back off exponentially, with jitter. Wait longer after each failure, and randomise the wait so consumers do not retry in lockstep. In Marc Brooker's simulation of 100 contending clients, jittered backoff cut the number of calls by more than half, and he calls it "a standard approach for remote clients" (AWS Architecture Blog, Exponential Backoff And Jitter).
  2. Limit retries with a budget. The Google SRE book caps each request at three attempts and keeps retries below 10% of a client's requests, which limits the extra load to about 1.1× instead of nearly 3× (Site Reliability Engineering, Handling Overload).
  3. Retry at one layer only. The same chapter recommends retrying only "at the layer immediately above the layer that is rejecting them", so retries do not stack.

What is a dead-letter queue, and when do messages go there?

A dead-letter queue (DLQ) holds messages that could not be processed, usually after a set number of attempts and, in some brokers, also when they expire or are dropped by a length limit. Its main job is to stop a poison message, one that fails every time, from blocking or slowing a consumer forever.

In Amazon SQS, a redrive policy moves a message to the DLQ once it has been received more than maxReceiveCount times; the default is 10 (SQS SetQueueAttributes). Google Cloud Pub/Sub dead-letter topics take a maximum delivery attempts value between 5 and 100, with a default of 5 (Pub/Sub handling message failures).

RabbitMQ dead-letters a message to a dead letter exchange, set with the x-dead-letter-exchange queue argument or a policy, when a consumer rejects it without requeueing, when it expires, when a length limit drops it, or when it is returned to a quorum queue more times than the queue's delivery-limit (RabbitMQ dead letter exchanges). Kafka's classic consumer groups have no dead-letter queue in the broker; an accepted proposal, KIP-1191, adds dead-letter topics for the newer share groups, so check the release you run. Kafka Connect sink connectors can write failed records to a dead letter queue topic named by errors.deadletterqueue.topic.name (Kafka Connect user guide); other Kafka consumers usually publish failures to a separate retry or dead-letter topic themselves.

The attempt count trades off against time. In SQS, a received message that is not deleted becomes visible again after the visibility timeout, 30 seconds by default (SQS visibility timeout). If a poison message crashes the consumer every time, 10 receives at 30 seconds each keep it cycling for about 5 minutes before it reaches the DLQ. AWS advises setting the count "high enough to allow for sufficient retries", so transient failures are not dead-lettered on the first try (SQS dead-letter queues).

A dead-letter queue is only useful if someone looks at it:

  • Alarm on it. Any message in the DLQ means something failed repeatedly. Alert on its depth, not only on the main queue.
  • Give it longer retention than the source queue. For SQS standard queues, a message keeps its original enqueue timestamp when it moves to the DLQ, so AWS recommends that the DLQ's retention always be longer than the source queue's. Otherwise dead-lettered messages can expire before anyone reads them.
  • Plan the redrive. Once the bug is fixed, move the messages back. SQS redrive can be rate-limited (up to 500 messages a second), and AWS suggests starting with a small value and checking that "the source queue doesn't get overwhelmed" (SQS dead-letter queue redrive).

How long does a backlog take to drain?

A backlog only shrinks when consumers process messages faster than producers add them:

time to drain = backlog ÷ (drain rate − arrival rate)

If arrival stays above drain, the answer is never, no matter how long you wait. In the order pipeline, a full 500,000-message queue with 1,200 arriving and 1,000 draining each second does not shrink at all. Doubling the consumers to drain 2,000 a second clears it at 800 a second, in about 10 minutes. Adding just one consumer (1,100 a second) still leaves the queue growing.

The burst example drains on its own because traffic drops to 600 a second after the spike: 240,000 messages at a net 400 a second take 600 seconds, 10 minutes.

When you scale consumers up to clear a backlog, check what sits behind them. Twice the consumers means twice the load on the database or API they call, and that may move the bottleneck rather than remove it. The same queueing results that limit a queue's drain rate apply to every component behind it.

Checklist: designing a queue that fails safely

  1. Compare average arrival and drain rates. If arrival can exceed drain for longer than a burst, size consumers for it or plan to shed load; a bigger queue only delays the problem.
  2. Bound every queue and buffer, and decide what happens at the limit: block, reject, or drop. Prefer an outcome the producer can see.
  3. Alarm on queue age, not just depth. The age of the oldest message tells you how far behind consumers are in time, which is what users feel.
  4. Use backoff with jitter and a retry budget, and retry at one layer only.
  5. Add a dead-letter queue with an attempt limit, longer retention than the source, an alarm, and a redrive plan.
  6. Work out the drain time before an incident: backlog ÷ (drain − arrival).

To see these effects without building the system, you can model a producer, a queue and a pool of consumers in StackMonkey, a free browser-based system design simulator. The notification system template uses priority queues, and you can slow its provider and watch the push queue back up.

About this article

Written by the team that builds StackMonkey. The worked-example rates are illustrative and were chosen for this article; the arithmetic follows from the formulas shown. Broker behaviour and defaults are taken from each vendor's documentation, linked inline, as of November 2026; check the current docs for the version you run. If you find an error, email [email protected] and we will correct it and note the change here. More about the project is on the about page, and what the site collects is in the privacy policy.

Sources

Watch a queue back up

Open the notification system template, slow the push provider and watch its queue grow.