The interview problem
Design a service that accepts 100 million one-time messages per day, scheduled up to 30 days ahead. Messages must not be dispatched before their due time; under healthy, admitted load, 99% should begin dispatch within five seconds afterward. Support rescheduling, cancellation and recovery after a ten-minute outage. Distinguish dispatch from successful processing by a destination.
Original system-design practice, not a reported company interview. Scale, timing and storage assumptions are hypothetical. Official AWS references retrieved September 27, 2026.
1. Define the observable delivery contract
Store due times as UTC instants. If clients enter a local time, resolve its time zone and any daylight-saving ambiguity before accepting the schedule. This exercise covers one-time schedules, not recurrence rules. Reject invalid horizons and define whether past-due requests are rejected or accepted for immediate eligible dispatch.
“Begin dispatch” means starting the authorized outbound delivery attempt. It does not mean the destination has committed the business action. Promise durable acceptance and at-least-once attempts within a bounded retry policy, not exactly-once external effects. A destination needs stable operation IDs and its own deduplication if repeated attempts must not repeat the action.
A five-second healthy-load objective is conditional on admission limits and functioning dependencies. Specify overdue behavior during outages and expiry for stale messages. A reminder delivered ten minutes late may still be useful; an expired offer may need to become EXPIRED instead. Record lateness rather than changing the original due time to conceal it.
2. Use durable time buckets and a short ready path
create / reschedule / cancel API
↓
transactional schedule store + due-time index
↓
sharded bucket scanners → durable ready queue
↓
version-checking dispatchers → destination
↓
attempt history + retries + terminal outcomesA schedule record contains tenant, schedule ID, generation, due instant, expiry, payload reference/hash, target, state and request-idempotency key. Partition the due index by time bucket plus a hash shard, not time alone: a popular hour boundary should not put every message on one partition. Scan upcoming buckets into a short ready horizon. Scanning and queue publication are durable work with recoverable checkpoints, not process-local timers.
Atomically write a schedule and its index entry where possible. If the store cannot transact across them, write an outbox event in the schedule transaction and maintain a replayable index with measured lag. Accepted work is not safely scheduled merely because its primary row exists; index lag belongs in the deadline budget. A repair scan must eventually discover accepted rows missed by indexing.
A queue entry is a hint containing schedule ID and generation. The schedule store remains authoritative. Duplicate promotions are acceptable because dispatch rechecks state. Prefer this over marking a row delivered before a queue write, which can lose work if the process crashes between those steps.
3. Recheck time before dispatch
Prefetching a future bucket must not cause early delivery. Workers recheck the actual due instant at the authorization boundary. In-memory timers may reduce polling but are disposable; recovery reconstructs pending work from durable state.
Suppose the dispatcher's wall-clock error is known to be at most 200 milliseconds. Requiring local time to be at least due time plus 200 milliseconds ensures real time is not earlier than due under that bound. With a clock 200 milliseconds slow, this guard can add 400 milliseconds of real delay. Network and scheduling delay can add more lateness but cannot make that already-authorized send earlier.
This reasoning fails if the clock jumps outside its stated bound. Monitor synchronization health and stop new time-sensitive authorizations when the bound is unavailable. Use monotonic clocks for local durations, but persist an absolute due instant for restart recovery. Exact real-time guarantees cannot be derived from an unbounded, untrusted wall clock.
As an illustrative five-second budget, allocate up to one second for scan/index visibility, one second for ready-queue delay, 0.4 seconds for the conservative clock guard and one second for dispatch scheduling. The sum is 3.4 seconds, leaving 1.6 seconds of margin. These are component budgets to validate together; adding individually measured p99 values does not prove an end-to-end p99.
4. Give cancellation a precise linearization point
Use states SCHEDULED, AUTHORIZED, DELIVERED, FAILED, CANCELED and EXPIRED, with separate attempt details. Immediately before external work, a dispatcher atomically changes the current due generation from SCHEDULED to AUTHORIZED. Cancellation can atomically change SCHEDULED to CANCELED. Both operations serialize on the same authoritative record.
If cancellation wins, return “canceled” and reject all stale queue hints for that generation. If authorization wins, cancellation returns “too late to guarantee cancellation,” even if the network call has not started yet. Do not return a successful cancellation while allowing an already-authorized send to proceed under the same promised semantics.
Rescheduling is allowed only while SCHEDULED: increment the generation and install the new due time. A queued hint for generation 7 cannot authorize generation 8. An old index row may remain temporarily, but it must fail the generation check. For stronger cancellation after authorization, integrate a cooperating destination protocol; deleting a local queue entry cannot recall an external action.
5. Recover ambiguous attempts without inventing success
In the authorization transaction, persist a stable destination operation ID derived from tenant, schedule ID and generation, plus a durable dispatch obligation. A recovery sweeper or transactional outbox must rediscover AUTHORIZED work even if the worker crashes before sending. Retry deadlines and ownership changes are durable too; a process-local backoff timer is not sufficient. A crash after the destination commits but before its acknowledgment leaves an unknown outcome. Query the destination by that ID when supported, or retry the same operation ID under its deduplication contract.
A worker lease helps assign ownership but cannot stop a paused old worker from making a late request. Recovery must tolerate duplicate attempts or fence them at a cooperating destination. Never claim exactly-once effects merely because only one lease is current. Retain deduplication records at the destination for the full possible retry horizon; after that horizon, reject automatic retries or explicitly accept the renewed duplicate risk. A delayed old worker can outlive a local retry horizon, so a strong effect guarantee also needs destination-enforced request expiry or fencing, or deduplication retention covering that delay.
Retries use bounded exponential backoff and jitter, constrained by message expiry and tenant limits. Keep due time, first-attempt time and next-retry time separate. Check expiry before each new attempt. Expiry does not retract an already-sent request: if business effects must never occur afterward, the destination must validate the deadline when applying them. Exhausted work enters a visible terminal failure or dead-letter workflow. Replaying it is an explicit new operational decision with a checked operation ID, not a silent reset of delivery history.
6. Size bursts and outage recovery
At 100 million messages/day, average acceptance is approximately 1,157 messages/second. If one million messages share the same due instant, dispatching 99% within five seconds needs at least 990,000/5 = 198,000 attempt starts/second during that burst, before retries and ordinary traffic. A system sized for the daily average cannot meet that promise. Apply per-due-window admission limits, reserve burst capacity, or negotiate a delivery window with the customer.
At a steady 1,200 due messages/second, a ten-minute outage accumulates 720,000 messages. If restored dispatch capacity is 3,000/second while new work continues at 1,200/second, net backlog drain is 1,800/second. Clearing that backlog takes 400 seconds, or six minutes 40 seconds, assuming destinations accept the load and no retries add work. This is a catch-up estimate, not compliance with the original five-second objective.
Separate overdue recovery capacity from current deadlines and use tenant fairness so one customer's burst does not consume all dispatchers. Capacity partitions trade faster backlog recovery against timely new work; publish both oldest-overdue age and fresh-message lateness. Rate-limit at each destination as well as globally.
If all accepted schedules remain pending for 30 days, 100 million/day implies three billion pending records. At 400 bytes of metadata each, raw metadata is 1.2 TB, before indexes, replicas, payloads and attempt history. For a ten-million-row minute bucket spread across 100 hash shards, the average is 100,000 rows/shard; skew and hot tenants still need measurement. Payload references keep large bodies out of the hot scheduling index.
7. Make missed work discoverable
Checkpoint bucket scans by durable key and revisit overlapping ranges so concurrent inserts and reschedules near a scan boundary are not skipped. An index may be eventually consistent, so repeatedly scan a safety interval and track outstanding index work. Only retire old buckets after reconciling accepted schedules, not because wall time moved past them.
Measure accepted-to-indexed lag, due-to-authorized lateness, authorization-to-attempt delay, destination acknowledgments, unknown outcomes and expired messages. Test a crash at every transition, a stale generation after rescheduling, cancel-versus-authorize races, backward clock jumps, a hot time bucket and recovery with a slow destination.
AWS SQS delay queues and message timers support delays up to 15 minutes according to the cited documentation. That alone does not implement the requested 30-day horizon. A managed scheduling product may be appropriate, but verify its precision, quotas, cancellation semantics and retry behavior against this contract rather than assuming all scheduling services are interchangeable.
8. Follow-ups and self-review
Follow-ups: Does a ready-queue entry mean delivery occurred? No. Can successful cancellation promise that a previously authorized request will never arrive? Not under this contract. Can a database TTL implement a five-second scheduler? Expiry cleanup is not automatically a precise dispatch mechanism. Can overdue work be marked on time by changing its timestamp? That destroys the measurement. Can strict ordering coexist with retries? Define the ordering domain and whether a failed earlier message blocks later ones; this design makes no global ordering promise.
Score 0–2 each for due-time semantics, durable discovery, cancellation/generation races, ambiguous delivery handling and burst/recovery arithmetic. A strong answer separates guaranteed cancellation from best-effort recall and average capacity from deadline capacity.
Sources and next steps
- AWS: SQS delay queues — delay horizon and distinction from message visibility.
- AWS: Scheduler dead-letter queues — failed target invocation handling.
The state machine, timing proof, architecture and capacity calculations are original. Continue with distributed execution admission for limiting in-flight work.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.