Quick revision
The short answer
I would make it an organisational rule that every queue, in-process or between services, is bounded and has an explicit overload behaviour, with a lightweight exception process. Unbounded queues hide overload as growing latency until memory or disk fails, while a bound forces a decision to block, reject or shed that is visible and testable; by Little's law a bound is really a latency budget. The rule comes with metrics on depth, wait time and rejections, because a rule left to each team repeats the same incident.
What to remember
In this answer, I took the position that every queue must be bounded and have an explicit overload behaviour. Unbounded queues convert overload into growing latency, wasted work and eventually a crash, while a bound forces a visible, testable choice to block, reject or shed. Little's law shows that a bound is a latency budget, and a rule with an exception process is enforceable, while leaving it to each team repeats the same incident. The rule is backed by shared helpers, automated checks, and metrics on depth, wait time and rejections.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would make it an organisational rule that every queue, in-process or between services, is bounded and has an explicit overload behaviour, with a lightweight exception process. Unbounded queues hide overload as growing latency until memory or disk fails, while a bound forces a decision to block, reject or shed that is visible and testable; by Little's law a bound is really a latency budget. The rule comes with metrics on depth, wait time and rejections, because a rule left to each team repeats the same incident.
Background to this question
This debate appears in every growing engineering organisation, usually right after an incident. One side says unbounded queues are simpler and memory is cheap; the other says every unbounded queue is an outage waiting for a slow day. A senior engineer is expected to take a position, explain it in terms both sides accept, and make it workable rather than bureaucratic. In this answer, we will look at what an unbounded queue really does under overload, why a bound turns a hidden problem into a decision, how Little's law connects queue size to latency, why the rule must be organisational, and how to make it enforceable and measurable.
1What an Unbounded Queue Does Under Overload
A queue only matters when work arrives faster than it is processed. For short bursts any queue is fine: it fills and drains. The difference appears under sustained overload, for example when a downstream slows down for twenty minutes. An unbounded queue keeps accepting work, so the system reports success while the backlog grows. Every new item waits behind the whole backlog, so latency grows steadily. Eventually memory is exhausted, or for a broker, disk or retention, and the failure is sudden and total: an OutOfMemoryError that loses everything queued, or a long garbage collection storm.
The cheap-memory argument misses the point. Memory is not the first resource we run out of; time is. A request that waits 10 minutes in a queue behind a backlog is useless if the client timed out after 30 seconds. We then spend CPU processing work that nobody is waiting for, which slows recovery further. So an unbounded queue does not absorb overload; it converts it into latency, then wasted work, then a crash.
| Moment | Unbounded queue | Bounded queue (800) |
|---|---|---|
| Minute 1 | backlog 17,000, wait 28 min | full at 800, wait 2 s, rejections start |
| Minute 10 | backlog 170,000, heap at 80% | still 800, rejections alerted |
| Minute 20 | OutOfMemoryError, backlog lost | downstream recovers, rejections stop |
| Visibility | success responses until the crash | 503s and alerts from minute 1 |
2A Bound Forces a Decision
A bounded queue cannot just keep accepting, so when it is full the code must do something, and that something has to be chosen: block the producer so it slows down, reject the new item with an error the caller can retry, or shed load by dropping low-value or old items. Each is a legitimate design. The point is that the choice is made deliberately, written in the code, and visible.
That visibility is what makes the system manageable. Overload produces rejections or slower producers immediately, which appear on dashboards and trigger alerts at minute one, not at the crash. And the behaviour is testable: a load test can fill the queue and check that the service returns 503 with a Retry-After header, or that the consumer loop slows down, instead of discovering the behaviour during an incident.
3Little's Law: The Bound Is a Latency Budget
Little's law says that the average number of items in a queue equals the rate at which they leave times the average time they wait: L = lambda x W. If a worker pool completes 400 items per second and the queue holds 800, an item at the back waits about 2 seconds. If the queue holds 400,000, it waits about 1,000 seconds, almost 17 minutes.
So choosing a bound is choosing the maximum queueing delay we are willing to give users. Teams find this easier to reason about than an abstract number: we ask what wait is acceptable for this work, multiply by the healthy throughput, and that is the bound. An unbounded queue is the same as saying any delay is acceptable, which is almost never true when someone is waiting for the result.
4Why a Rule, Not Team Discretion
Leaving the choice to each team sounds respectful of autonomy, but in practice it repeats the same incident. The unbounded option is the default in many APIs, such as Executors.newFixedThreadPool, a LinkedBlockingQueue without capacity, or buffering operators in reactive libraries, so teams choose unboundedness without knowing they did. Each team then learns the lesson separately, in production.
A clear rule with an exception process captures the lesson once. The rule says: every queue has a bound and a documented overload behaviour. The exception process says: if you believe a queue should be unbounded, for example because its producer is itself strictly bounded, write two sentences explaining why, get a review, and record it with an owner. Exceptions are rare and visible, and the default protects everyone else.
- Find the latency budgethow long may an item wait?
- Compute the boundhealthy throughput x budget (Little's law)
- What should happen when it is full?YesBlock, reject or shed: write it in codeNoNo answer yet: design not done
- Is unbounded truly needed?YesRequest an exception with a reason and ownerNoUse the bound
- Export depth, wait time, rejectionsalert on sustained rejections
5 steps in order. Play them, or step through them one at a time.
5Making the Rule Enforceable and Measurable
We enforce what tools can check automatically. An ArchUnit or static analysis rule can flag calls to Executors.newFixedThreadPool, newSingleThreadExecutor and LinkedBlockingQueue constructors without capacity, pointing to a shared helper that builds a bounded executor with metrics. Service templates include bounded defaults for HTTP clients, executors and consumers. Design review templates ask what happens when the consumer is slower than the producer.
The rule is paired with metrics everywhere: queue depth, time spent waiting, and rejections or drops. Without them, a bound just moves the failure to a place nobody watches. With them, the organisation can see where queues run near their bounds, which tells us about real capacity needs, and the rejections during an incident tell us exactly which dependency is slow. I would roll it out by applying it first to new code and to the queues involved in past incidents, then work through the inventory over a few quarters.
6Follow-up questions
What about Kafka topics? They are effectively unbounded.
They are bounded by retention and disk, which is a bound, just a large one with a specific failure: old data is deleted. The rule still applies in its own form: we define acceptable consumer lag in time, alert well before retention, and decide what happens if consumers cannot catch up, such as scaling consumers or pausing low-priority producers.
Is rejecting work not worse for users than making them wait?
For a short wait, waiting is better, and the bound allows exactly that much waiting. Beyond the budget, the user has usually given up or retried already, so the work is wasted. A fast, clear rejection lets clients retry with backoff and lets the system recover instead of collapsing.
How do you answer the simplicity argument?
Agree that bounded queues need one more decision, and make that decision cheap with a shared helper and defaults. The simplicity of unbounded queues is borrowed: the complexity comes back during an incident, with less time to think and higher stakes.
7Conclusion
In this answer, I took the position that every queue must be bounded and have an explicit overload behaviour. Unbounded queues convert overload into growing latency, wasted work and eventually a crash, while a bound forces a visible, testable choice to block, reject or shed. Little's law shows that a bound is a latency budget, and a rule with an exception process is enforceable, while leaving it to each team repeats the same incident. The rule is backed by shared helpers, automated checks, and metrics on depth, wait time and rejections.
Open with
I would back the rule: every queue, in-process or between services, must be bounded and have an explicit overload behaviour, with a simple exception process. The argument that memory is cheap misses what an unbounded queue does under sustained overload.
Then, if they want more
It keeps accepting work, so everything looks fine while each new item waits behind a growing backlog. Latency grows first, then we waste capacity processing requests whose clients already timed out, and finally memory or disk runs out and we lose everything at once. A bounded queue cannot do that silently.
When it is full, the code must block the producer, reject with a retryable error, or shed low-value work, and that choice is visible on dashboards from the first minute and testable in a load test.
Little's law makes the bound easy to set: queue length equals throughput times wait time, so a pool doing 400 per second with a two-second budget gets a bound of about 800. Choosing a bound is choosing a latency budget.
I would make this an organisational rule rather than team discretion, because the unbounded option is the default in common APIs like newFixedThreadPool, so leaving it to each team means each team learns it in an incident. Exceptions are fine with a written reason and an owner.
To make it stick, I would provide a shared bounded executor helper, automated checks for unbounded constructors, and require metrics on depth, wait time and rejections for every queue.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Collections Framework, overview, java.util, package documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Some engineers argue that every queue in your systems, in-process or between services...": https://scrivio-interview-library.netlify.app/java/queues-and-deques/dd47a3a7f2/