How it works
A queue smooths a burst only if the average arrival rate stays below the service rate. As an example, 1,200 jobs arrive per second and workers finish 1,000. The backlog grows by 200 per second. After 10 minutes it holds 120,000 jobs, and a new job waits 2 minutes. With no limit, this continues until memory runs out or every job is too old to matter. The queue has not fixed the overload, only hidden it.
A bound makes this visible, and you can size it from the wait you can accept: at 1,000 per second, a limit of 5,000 jobs means about 5 seconds of waiting at most. Backpressure is a signal telling producers to slow down. It works only when a producer can, such as a batch importer reading a file. A person waiting on an HTTP response cannot be slowed without holding their connection open until they give up.
So choose by the work. Block the producer when it can wait and the data matters. Reject new work with an explicit error when the caller can decide what to do next, as with API requests. Drop the oldest when fresh data replaces stale data, as with live locations. Spill to disk when work must survive, remembering that disk is a larger queue with its own limit and a backlog to repay. Watch the age of the oldest item, not only depth.
Chat System limits each gateway’s outbound queues, Notification System reserves capacity so a campaign cannot delay receipts, and News Feed bounds fanout with backpressure.
One service has two full queues. One holds live driver locations, sent every 4 seconds per driver. The other holds payment capture jobs. What should each queue do at its limit?
Locations should drop the oldest, or keep only the latest per driver, because a stale position is worthless and a newer one is seconds away. Payments must not be dropped silently: keep them durable, slow or reject new intake with an explicit error so the caller can try later, and alert. One policy for both would either lose payments or waste work on stale locations.
Use this as a guide for self review; written answers are not graded.Keep in mind
- A queue hides sustained overload until memory or latency exposes it.
- Size the bound from the longest wait the work can tolerate.
- Backpressure needs a producer that can slow down; otherwise reject or drop.