Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Design a Fault-Tolerant Distributed
Cron & Job Scheduler.

Scaling a distributed cron scheduler to 50,000 triggers/sec requires partitioning schedules into time-bucketed shards, issuing monotonic fencing tokens via etcd/Raft leases, and enforcing idempotency keys at target executors.
Start the journey5 stages· Last modified Nov 21, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

If latency budgets leave no room for synchronous retries, never rely on a single SQL polling loop or unfenced distributed locks; pair time-bucketed shards with monotonic fencing tokens (epoch) and target-side idempotency keys.

TL;DR30-second simplified summary
▾

Core Mechanics: Polling a single SELECT ... FOR UPDATE table at 50,000 triggers/sec collapses under index lock contention, while unfenced worker leases allow GC-paused zombie workers to double-execute jobs.

Visual & Structural Flow: Depicts a Hashed Time-Wheel (Minute Buckets) feeding a Partitioned Job Store (shard by bucket), an etcd Coordinator Lease issuing Fencing Token (epoch=42) to the active Worker Pool, while a Zombie Worker (GC Pause, epoch=41) is blocked by a Storage Fence Check (epoch >= 42) before reaching Target Executor + Idempotency Key and Retry + DLQ.

Trade-Offs & Production: Partitioning by (minute_bucket, shard_id) keeps scans bounded in RAM/SSD, while monotonic fencing tokens + deterministic (job_id, scheduled_at) idempotency keys guarantee at-most-once side effects.

Failure Modes & Application: Isolate slow webhook targets with per-tenant worker bulkheads and route exhausted retries to a Dead Letter Queue (DLQ).

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Distributed Cron & Scheduling
Distributed cron and scheduling systems execute time-based and delayed jobs reliably across a fleet of stateless workers without single-point-of-failure downtime or duplicate runs.
Distributed Locking & Redlock Algorithm
Distributed locking coordinates mutually exclusive access to a shared resource across independent processes that share no memory, using a network-accessible lease store such as Redis, etcd, or ZooKeeper.
Dead Letter Queues
A secondary quarantine queue that captures messages a consumer repeatedly fails to process after a bounded number of retries, preventing poison pills from blocking healthy traffic.
Full walkthrough · 5 stages
01
STAGE 01 · REQUIREMENTS & MATHL5 · APPLIED DESIGN

Clarify Scale, Drift SLO & Execution Semantics.

Why this matters: The problem: size storage, peak trigger QPS, and exact execution guarantees.

Think of Clarify Scale, Drift SLO & Execution Semantics as the intuition layer for Design a Fault-Tolerant Distributed Cron & Job Scheduler: The problem: size storage, peak trigger QPS, and exact execution guarantees.

With 10M active schedules (~1 KB metadata each = ~10 GB), metadata fits easily in a sharded database, while 50,000 triggers/sec at top-of-minute spikes demands horizontal partitioning. Target <2s trigger drift, at-least-once dispatch with idempotency_key = hash(job_id, fire_ts), and zero split-brain double execution when workers pause or partition.

Design Trade-Off

Clarify Scale, Drift SLO & Execution Semantics

Before · Unbounded Coupling
  • No backpressure on spikes
  • Implicit shared state
  • Cascading tail latency
After · Bounded & Observable
  • Explicit capacity budgets
  • Isolated failure domains
  • Predictable p99 latency
02
STAGE 02 · NAIVE BOTTLENECKSL5 · APPLIED DESIGN

Why Central Polling & Unfenced Locks Fail.

Why this matters: The failure mode: see how single-table polling and GC-paused workers corrupt job state.

Think of Why Central Polling & Unfenced Locks Fail as the intuition layer for Design a Fault-Tolerant Distributed Cron & Job Scheduler: The failure mode: see how single-table polling and GC-paused workers corrupt job state.

A single SELECT * FROM jobs WHERE next_run <= NOW() FOR UPDATE SKIP LOCKED creates severe B-Tree hot-page contention at top-of-minute boundaries. Worse, if Worker A acquires a 10s Redis lock, hits a 12s stop-the-world GC pause, and wakes up after Worker B took over, both workers fire the same billing webhook unless downstream storage checks a monotonic fencing token.

Engineering Decision Framework
Problem
How to implement Design a Fault-Tolerant Distributed Cron & Job Scheduler without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
If latency budgets leave no room for synchronous retries, never rely on a single SQL polling loop or unfenced distributed locks; pair time-bucketed shards with monotonic fencing tokens (epoch) and target-side idempotency keys.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Design a Fault-Tolerant Distributed Cron & Job Scheduler experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
STAGE 03 · ENTERPRISE ARCHITECTUREL6 · SCALE & TRADE-OFFS

Time-Bucket Sharding + Etcd Fencing Tokens + Idempotent Executors.

Why this matters: The mechanism: partition by time bucket and guard execution with monotonic epochs.

Shard schedules by (minute_bucket, shard_id) so each scheduler node owns disjoint time-bucket partitions via an etcd lease.

When Worker B takes over a partition, etcd increments the monotonic fencing token (epoch=42).

Scheduler Data & Control Flow

Time-Bucket Sharded Cron & Fencing Pipeline

Time-Wheel BucketsShard by (min, id)Etcd Lease + FenceMonotonic epoch=42Worker PoolBounded + bulkheadExecutor + DLQIdempotency key

1.Bucket Sharding: Eliminates top-of-minute full-table index contention.

2.Fencing Token: Rejects delayed zombie worker writes with epoch < max_seen_epoch.

3.Idempotent Dispatch: Deterministic (job_id, scheduled_epoch) key deduplicates retries.

Caption: Combining time-bucket sharding with monotonic fencing tokens and idempotent executors prevents both hot-shard stalls and GC-pause double execution.

def execute_fenced_job(db_conn, job_id: str, scheduled_ts: int, epoch: int, webhook_fn) -> str:
    """Assumes db_conn enforces epoch >= last_epoch atomically before side effects."""
    cur = db_conn.execute(
        "UPDATE scheduled_runs SET status = 'RUNNING', last_epoch = %s "
        "WHERE job_id = %s AND scheduled_ts = %s AND status = 'PENDING' AND last_epoch < %s",
        (epoch, job_id, scheduled_ts, epoch),
    )
    if cur.rowcount != 1:
        db_conn.rollback()
        return "SKIPPED_STALE_OR_DUPLICATE"
    db_conn.commit()

    idem_key = f"{job_id}:{scheduled_ts}"
    return webhook_fn(job_id=job_id, idempotency_key=idem_key)
04
STAGE 04 · SCALE & BURST CONTROLL6 · SCALE & TRADE-OFFS

Absorbing Top-of-Minute Spikes & Slow Webhook Targets.

Why this matters: Operational control: smooth cron alignment bursts and isolate slow targets.

Think of Absorbing Top-of-Minute Spikes & Slow Webhook Targets as the intuition layer for Design a Fault-Tolerant Distributed Cron & Job Scheduler: Operational control: smooth cron alignment bursts and isolate slow targets.

When 1M users schedule 0 * * * *, all jobs fire at :00 seconds. Apply deterministic jitter (hash(job_id) % 5s) for non-strict jobs, pre-fetch upcoming 60s buckets into an in-memory hashed time wheel, and dispatch through Kafka/SQS with per-tenant concurrency bulkheads and a Dead Letter Queue (DLQ) for failing webhooks.

05
STAGE 05 · INTERVIEW FOLLOW-UPSL7 · STAFF / PRINCIPAL

Multi-Region Failover & Catch-Up Policies.

Why this matters: Applied problems: handle missed runs during outages and cross-region promotion.

Think of Multi-Region Failover & Catch-Up Policies as the intuition layer for Design a Fault-Tolerant Distributed Cron & Job Scheduler: Applied problems: handle missed runs during outages and cross-region promotion.

Support explicit per-job misfire policies (SKIP_MISSED, FIRE_ONCE, BACKFILL_ALL) so a 10-minute outage does not accidentally fire 10x duplicate billing runs on recovery.

Lifecycle & Failure Recovery

Multi-Region Failover & Catch-Up Policies

admitsucceedbudget exceededInitializedProcessingInvariant MetDegraded Fallback
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Worker A holds a 10s Redis lease for job J, pauses for 15s due to JVM GC, and wakes up after Worker B already took over J. What prevents Worker A from double-executing J?

Recommended Learning Flow