KatInterview

Build a Delayed-Task Platform with a Fast Status Cache

System DesignModel answer
HardModel answerSystem Designsystem-designjob-queuecaching

Last updated

Design a distributed platform that runs delayed and immediate background tasks with retries and durable state, plus a cache that serves task status in under 10 ms at 10k requests/second.

Build a Delayed-Task Platform with a Fast Status Cache

You are asked to design a backend service that lets clients submit units of work to be executed asynchronously, either right away or at a later time. The service must track each task through its lifecycle and let clients find out what happened to it. A cache in front of the task metadata must keep status lookups fast even when load is heavy.

Functional requirements

  • Clients can submit a task for immediate execution or with a delay or a target start time.
  • Each task moves through the durable states PENDING, PROCESSING, COMPLETED and FAILED.
  • Failed attempts are retried automatically using exponential backoff.
  • Clients can poll for status or be notified when it changes.

Non-functional requirements

  • The system must sustain about 10,000 requests per second overall.
  • Running the same task twice must not cause duplicate side effects (idempotency).
  • Status reads must complete in under 10 ms.
  • The service must be highly available and tolerate node and zone failures.

What to cover in your answer

  1. API design: Public endpoints for submitting tasks and checking status, plus the interface that internal workers use to claim and report on work.
  2. Data model: A storage schema, and how you make state transitions safe when several actors race.
  3. Caching strategy: The cache design, including eviction, write-through versus write-behind consistency, and how you handle hot keys, for example thousands of workers or clients reading the same task's status.
  4. Architecture: The main components (queues, workers, scheduler, cache, durable store) and how they fit together, including failure handling.

State your assumptions about traffic mix and delivery semantics, and discuss the trade-offs behind your main choices.

Hints

Hint 1

Split the 10k req/s into submits, status reads and state-change writes. Reads usually dominate, and each task causes several writes as it moves through its states.

Hint 2

Assume at-least-once delivery and make the handlers safe to repeat. Think about conditional (compare-and-set) updates, lease tokens that fence out stale workers, and idempotency keys on submission.

Hint 3

Message brokers rarely support delays natively, so consider keeping future-dated tasks in the database or a sorted structure and having a scheduler release them when due.

Hint 4

For the cache, ask what happens if a cache write is lost or arrives out of order. Versioned writes and a change-data-capture repair path help. For hot keys, consider request coalescing, local in-process caches with short TTLs, and long-polling or push instead of tight polling.