Requirements of a Messaging Queue 00:00:01 A message survives its producer A shop has accepted an order. Sending the receipt can wait for an email worker, but the intent to send must survive the worker being busy. Follow one message through the queue until somebody can safely acknowledge it. The producer creates M4 with a payload and metadata. M4 is stored behind M3. The producer gets the message id. The next consumer polls. The broker hands it the first available message with a receipt and temporarily hides that message from other consumers. The consumer runs the business logic. M1 is still stored. The work is done. The consumer sends the receipt. M1 is gone. M2 is next. The broker's acknowledgement and the customer's email are different events. Define precisely when a worker declares success, because recovery begins at that boundary. 00:00:56 The worker disappears after charging A worker can finish an external action and stop before acknowledging the message. Once the visibility period expires another worker can receive it. What stops a second receipt being mistaken for a second customer purchase? Consumer 1 receives message 7. It is hidden until 30 s. In this example the charge is a local ledger change. The worker records it and message identifier seven in one database transaction. An external payment provider requires its own repeat-safe contract. Consumer 1 dies. Nothing reaches the queue. The timeout ends, and consumer 2 receives message 7. Id 7 is already stored, so nothing is charged. Consumer 2 acknowledges. A stable business identifier lets the destination recognize a repeat. Waiting longer before redelivery changes timing, but cannot make an ambiguous external effect happen exactly once. 00:01:55 Compete for jobs Five messages wait while multiple eligible consumers become free. Competing consumers share the work. Under this example's simplifying timings, adding useful parallel workers shortens the time needed to drain the queue. M1 to M5 are in the queue. M1, M2 and M3 go to different consumers. After one second all three are done. M4 and M5 go to the first two. Five messages in two seconds. One consumer needs five seconds. Parallel completion can rearrange results. If jobs for one customer must be ordered, define the scope of that ordering and how the broker and workers preserve it. 00:02:38 Both email and inventory need the news Now a single paid-order event must reach two different functions. If both workers compete on the same queue, whichever one wins could remove the only copy before the other function sees it. The order service publishes one event to the exchange. The exchange puts a copy in each bound queue. The email worker is down. Its copy waits, and stock is updated. The email worker returns and handles its copy. Give each subscription its own progress. An email outage can build an email backlog without requiring inventory to process the same event again solely because another team fell behind. 00:03:15 One impossible job cannot hold the line A malformed message repeatedly returns after its worker fails. A retry budget lets the system move that item aside after a bounded number of attempts and continue with later work. Message 9 is received. The count is 1. The worker crashes. It comes back after the timeout, twice more. The count is 3. The next time it is visible, the count is at the limit. It moves to the dead letter queue. Message 10 is handled. Keep enough evidence to inspect and safely replay the quarantined job. The queue buys time between producer and consumer, but someone still owns a message that never succeeds.