How would you decide how big a queue should be?
Sketch your own answer first, then compare it with the one below.
A strong answer
Start from the latency you can accept, not the memory you have. By Little's law, the wait of a full queue is about its capacity divided by the drain rate. Pick the longest wait after which a message is still useful, and multiply by the drain rate.
Check the other side too. The queue should be big enough to hold the longest burst you expect, given how fast consumers drain it. If the two requirements conflict, the consumers are too slow, and the fix is capacity.
The limit itself should be a deliberate policy. Watch queue age as well as depth, and alarm when the queue stays full. The sizing assumes bounded bursts and service times without heavy tails, so if either fails the numbers are optimistic.
Sources
- John D. C. Little (1961). A Proof for the Queuing Formula: L = λ W.
- Mor Harchol-Balter (2013). Performance Modeling and Design of Computer Systems.