Temporal logoTemporal
System DesignFree preview

Firing Scheduled Events On Time at Scale

Design a service that accepts events with a future fire time and delivers them accurately, at scale, with no loss and no duplicates. It exposes create, cancel and lookup APIs and must stay available through worker and database failures.

SWE
Infra Eng
system-design
scheduling
database
distributed-systems
idempotency
retry
queueing
data-structure
Frequency
Single report
Last asked
2026-02-11
Stage
phone-screen · onsite-system-design

Problem

Design a service that accepts events to be fired at a future time and delivers them accurately when that time arrives. It must scale to a backlog of 10M+ pending events, never lose an event, and never fire one twice. Timing accuracy matters: the target is under one second of jitter.

API

POST /events
{eventId, fireAt, payload, dedupKey}

DELETE /events/{eventId}
GET /events/{eventId}

Requirements:

  • Accept an event with a fireAt timestamp and a client-supplied dedupKey so client retries are safe.
  • Fire it at the scheduled time by webhook or message queue, with acknowledgement, retry and a dead-letter path.
  • Support cancellation and status lookup; an event is pending, fired or cancelled.
  • Stay available with multiple workers and a replicated database.
  • Partition the load so it scales horizontally.

Hints

Talking Points

  • The claim is the heart of exactly-once. Walk through two workers draining the same slot and show how the conditional update resolves it.
  • Justify the tiers. A wheel alone cannot hold 10M events and a database alone cannot give sub-second jitter; name the promotion path.
  • State the rebuild procedure. In-memory structures are disposable caches rebuilt from pending rows due within the hour.
  • Give concrete numbers. 10M events, 116/sec, 60 slots holding about 7K events, about 410K heap entries.
  • Cover the unhappy path. Retry policy, backoff, dead-letter queue and resulting status.
  • dedupKey is the client idempotency story. It makes a retried POST safe.

Follow-ups

Preparation

  • Implement a 60-slot timing wheel with add, tick and drain, and test that an event added mid-second lands in the right slot.
  • Write the claim query and a test with two concurrent workers proving only one fires.
  • Sketch the crash-recovery routine that rebuilds the wheel and heap from the database and estimate its runtime.
Was this article helpful?

Comments

Sign in to join the discussion
Loading...