The need for delay
Some work should happen later: retry in thirty seconds, send a reminder in one hour, cancel an unpaid order in a day. Delayed delivery makes a message invisible to consumers until its scheduled time.
Implementation approaches
- Visibility timeout per message: store a become visible at timestamp and hide the message until then.
- Timer wheel: bucket messages by their fire time into slots advanced by a ticking clock, efficient for many timers.
- Delay queue tiers: route to fixed delay queues such as five seconds or one minute, then forward to the main queue.
Precision versus cost
Exact per message scheduling needs a sorted structure or timer wheel and more bookkeeping. Fixed tier delays are cheap but only approximate the requested delay.
A common use
Exponential backoff retries lean on delayed delivery: each failed attempt re enqueues the message with a longer delay than the last.
Flow
Key idea
Delayed delivery hides a message until its scheduled time, powering retries with backoff, reminders, and timed cancellations.