← Lessons

quiz vs the machine

Gold1430

System Design

Delayed Message Delivery

Scheduling a message to become visible only after a chosen delay.

5 min read · core · beat Gold to climb

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.

Check yourself

Answer to earn rating on the learn ladder.

1. What does delayed message delivery do?

2. Why is a timer wheel useful for delayed delivery?

3. How does exponential backoff use delayed delivery?