Design a Scheduled Job Execution System
Design a durable one-time and recurring job service with priority classes, stable occurrence identity, at-least-once execution safety, and private object-storage logs for every run.
Problem statement
For this exercise, assume you are designing a multi-tenant service for one-time and recurring scheduled jobs. A client can submit a one-time job with a scheduled time, or create a recurring schedule with a validated UTC cron expression.
Both carry a job type, an opaque payload reference, a bounded resource class, and a retry policy. Every intended recurring firing has a stable logical firing key derived from the schedule and intended firing time plus an auditable disposition.
Only firing work admitted for execution materializes an immutable occurrence with a stable identity. The service durably accepts definitions and jobs, keeps future work queued, dispatches an occurrence at or shortly after its intended time, and exposes current and terminal status.
For this exercise, assume every one-time job and recurring schedule also has a priority class: HIGH, NORMAL, or LOW, with NORMAL as the default, and each occurrence of a recurring schedule has its schedule's class.
Priority only decides the order of work that is already due: it never lets a job start before its scheduled time and never interrupts work that is already running.
When more work is due than the service can dispatch at once, higher-priority work should start first, but lower-priority work must not starve, meaning it must not wait without limit behind a steady stream of higher-priority work: a due NORMAL or LOW occurrence must still start within 5 minutes of its intended time.
Each tenant has a quota for HIGH work: a cap on how many HIGH one-time jobs and HIGH recurring schedules it may have active at once, with a size you choose. A create request that would exceed it is rejected rather than silently given a lower class.
Clients can pause or resume a recurring schedule and cancel its future occurrences. For this exercise, a lifecycle mutation affects only intended firing times after that mutation commits; already claimed occurrences continue under the ordinary lease and fencing rules.
Each schedule chooses one explicit misfire policy: SKIP marks every missed logical firing as skipped without an occurrence, while COALESCE marks a contiguous missed interval as coalesced into one catch-up occurrence.
That catch-up identity is derived from the schedule ID, lifecycle version, and exact first and last covered firing times, and every covered firing records that identity in its disposition. The service must not silently create an unbounded catch-up storm.
Workers may fail or receive duplicate deliveries, so recovery must preserve stable logical firing, occurrence, and attempt identities and prevent a stale worker from overwriting a newer outcome.
Use these additional practice assumptions: accept up to 1,000 one-time jobs or newly materialized occurrences per second, retain as many as 50 million not-yet-due occurrences and 5 million active recurring schedules, and normally begin eligible work within 30 seconds of its intended time.
Use at-least-once worker delivery, retain compact status and execution metadata for 30 days, survive one process or availability-zone loss after acknowledgment, and allow schedules up to one year ahead.
Dependency graphs, arbitrary workflow authoring, cross-region failover, changing a job's priority after it is accepted, and worker business logic are outside scope. Do not assume a particular scheduler or workflow product; explain where a durable workflow engine such as Temporal would or would not fit.
Each admitted occurrence must also retain its execution logs in private object storage.
Define stable log identity and ownership, how workers upload bounded chunks or a finalized object without a stale attempt overwriting newer evidence, how clients obtain authorized reads, and how redaction, quotas, retention, lifecycle deletion, failure, and reconciliation work.
For this exercise, log size, duration, format, and compliance policy are not fixed, so state your own assumptions for them. At-least-once execution plus idempotency and deduplication remains the execution model; object storage does not turn business effects into exactly once.
Worker-capacity discussion variant: Also explain how the design changes if execution workers are available without a capacity limit. In this variant, an eligible dispatched job does not wait for a free execution worker.
This assumption does not make the scheduler, metadata store, dispatch path, external dependencies or log storage unlimited or failure-free. Keep the same timing, priority, recurrence, lifecycle, delivery and recovery rules.
State which worker-capacity concern can be removed and which scheduling and correctness concerns remain. The production-capacity discussion in the baseline remains part of the exercise; compare the two assumptions explicitly.
What to build
- A client can idempotently create one-time jobs and recurring schedules with a priority class, and inspect, pause, resume, or cancel them, with stable schedule and occurrence identities and explicit already-claimed outcomes.
- The service dispatches each eligible occurrence at or after its scheduled time, starts higher-priority due work first without starving lower-priority work, retries under an at-least-once model, and durably records one authoritative terminal disposition without claiming exactly-once side effects.
- A client can read schedule, occurrence, and attempt state plus authorized per-attempt logs retained in private object storage with stable identity and bounded reads.
- Operators can detect and repair missed scheduling work, stale claims, duplicate delivery, partial log uploads, missing objects, retention deletion, and database or object-store partial failures.
At scale
- Assume up to 1,000 newly accepted one-time jobs or newly materialized recurring occurrences per second, as many as 50 million not-yet-due occurrences, 5 million active recurring schedules, and scheduled times up to one year ahead.
- Assume an eligible occurrence should normally begin within 30 seconds of its intended firing time; when more work is due than can be dispatched at once, HIGH work goes first but a due NORMAL or LOW occurrence still begins within 5 minutes. Future occurrences must remain unclaimable and schedule changes must have deterministic effective times.
- Assume worker delivery is at least once; stable schedule, logical-firing, occurrence, job, and attempt identities plus fencing or idempotency must prevent duplicate admission, duplicate effects, or stale completion from corrupting authoritative state.
- Assume acknowledged jobs, schedules, lifecycle mutations, and committed outcomes survive one process or availability-zone failure; retain compact occurrence and attempt metadata for 30 days and bound catch-up with SKIP or COALESCE misfire policy.
- Assume job logs are retained in private object storage. Log volume, retention duration, format, and compliance policy are not fixed, so the design must state bounded assumptions and keep logs separate from compact 30-day status metadata.