← Lessons

quiz vs the machine

Gold1350

System Design

Delay and Scheduled Messages

Asking a broker to hold a message until a future moment instead of delivering it now.

4 min read · core · beat Gold to climb

Sending into the future

Sometimes you want an action to happen later, not now: remind a user in 24 hours, retry a failed payment in 5 minutes, or expire a cart after an hour. A delayed message is sent now but only becomes visible to consumers after a delay. A scheduled message targets a specific timestamp.

How brokers do it

  • A visibility delay keeps the message hidden in the queue until its delay elapses, then it becomes deliverable.
  • A delay queue holds timed messages and moves them to the live queue when due, often using a timer wheel internally.
  • Some systems implement delay with a dead letter hop: publish with a short time to live, and when it expires it routes to the real queue.

Tradeoffs

  • Long delays measured in days are better handled by a scheduler or a database row with a due time, since broker memory is precious.
  • Delays are approximate, so do not rely on millisecond precision.

Key idea

Delayed and scheduled messages let a broker hold work until a future time but long horizons belong in a scheduler rather than the queue.

Check yourself

Answer to earn rating on the learn ladder.

1. What happens to a delayed message before its delay elapses?

2. Why are multi day delays better handled outside the broker?