Skip to content

Part 7 · Blueprint 39

Distributed Task & Cron Scheduler (Temporal / Quartz Scale)

12 min reading · Sources · Editorial review pending

A missed timer and a duplicated occurrence are different failure cases.

More
20px
Reading list
Page details

Published date · Last edited:

Draft edition. Editorial review and supplementary reading recommendations are still being completed.

Format: Architecture walkthrough. Prerequisites: the beginner bootcamp. Chapter prerequisites: Message Queues & Event Streams: Kafka vs. RabbitMQ, Idempotency Keys & Distributed Retries, Distributed Lock Manager (etcd / ZooKeeper / Chubby Internals).

Sixty-second mental model

Problem: A missed timer and a duplicated occurrence are different failure cases.

Use: Persist due occurrences and fence completion by attempt ownership.

Design boundary: Distinguish schedule occurrence from execution attempt. Calendar policy, catch-up and job effects must survive leader changes without silently multiplying a business occurrence.

Layer 1 · Intuition

Hypothetical scenario: Northwind is designing task scheduling. Maya represents product requirements, Dev implementation and Priya reliability. The team must agree what one job occurrence means and which component owns the schedule occurrence.

Think of a calendar that records each occurrence and its assigned worker. Separate the requester from schedule occurrence, then identify the retained evidence needed after failure.

Authority
The entitled state owner.
Invariant
A rule preserved across concurrency and failures.

Architecture and worked reasoning

Design boundary: Distinguish schedule occurrence from execution attempt. Calendar policy, catch-up and job effects must survive leader changes without silently multiplying a business occurrence.

Responsibilities on the request path

Task scheduling: responsibilities and request directionDistinguish schedule occurrence from execution attempt. Calendar policy, catch-up and job effects must survive leader changes without silently multiplying a business occurrence.Schedule registryDue occurrenceExecution queueJob journal
Distinguish schedule occurrence from execution attempt. Calendar policy, catch-up and job effects must survive leader changes without silently multiplying a business occurrence.

Workload and limiting resource

Hypothetical 10,000 schedules due each minute create 10,000 / 60 ≈ 166.67 occurrences/s on average, but synchronized minute boundaries create a 10,000-item burst. At 500 starts/s, dispatch alone requires at least 20 seconds without other work.

Keep the units attached to each intermediate result. The assumptions above describe a hypothetical exercise, not observed vendor capacity. A real capacity decision also needs a measured service curve, skew, recovery traffic and an explicit admission policy for overload.

Mutation or publication path

Task scheduling: mutation boundaryDerive occurrence identity from schedule and intended time. Then: Claim it conditionally and queue recoverable work. Then: Record attempts/effect progress under that occurrence.Step 1
Derive occurrence identity from schedule and intended time.
Step 2
Claim it conditionally and queue recoverable work.
Step 3
Record attempts/effect progress under that occurrence.
Derive occurrence identity from schedule and intended time. Then: Claim it conditionally and queue recoverable work. Then: Record attempts/effect progress under that occurrence.
  1. Derive occurrence identity from schedule and intended time.
  2. Claim it conditionally and queue recoverable work.
  3. Record attempts/effect progress under that occurrence.

Observation and recovery path

Task scheduling: observation boundaryRead occurrence state rather than counting worker starts. Then: Apply explicit missed-run/catch-up policy. Then: Reconcile long-running or orphaned attempts.Step 1
Read occurrence state rather than counting worker starts.
Step 2
Apply explicit missed-run/catch-up policy.
Step 3
Reconcile long-running or orphaned attempts.
Read occurrence state rather than counting worker starts. Then: Apply explicit missed-run/catch-up policy. Then: Reconcile long-running or orphaned attempts.
  1. Read occurrence state rather than counting worker starts.
  2. Apply explicit missed-run/catch-up policy.
  3. Reconcile long-running or orphaned attempts.

Failure that changes the decision

Hypothetical scenario: Two scheduler leaders enqueue the same due time after failover. A unique occurrence record must bind all attempts to one logical job.

Attempt this decision before reading the explanation

Should a missed hourly job always run once per missed hour after a day outage?

That is a domain policy, not a scheduler default. Define whether to catch up, coalesce, expire or require review, and budget the resulting burst.

Supporting mechanism analysis

Hypothetical scenario: Northwind. Maya represents product, Dev implementation and Priya reliability. The following workflow develops the underlying mechanism.

Separate a due time, a logical occurrence and authority to carry out its effects. Choose overlap and missed-run behavior deliberately. Keep object readiness and pending publication from page 17 in the cleanup contract rather than treating every old object as removable.

The process can resume. The design needs a rule enforced where protected effects occur, not merely a new scheduler’s belief that the old claim expired.

A schedule defines when an occurrence should become eligible to run. A durable occurrence record can distinguish due, claimed, running, completed and unresolved work. A process noticing the clock is not sufficient evidence that the intended occurrence was created once or completed successfully.

State what a sweep does. Here it inspects expired upload intents and decides which require recovery or are eligible for cleanup. It does not blindly delete every object absent from one momentary query result. Pending publication, allowed rollback and in-flight readers still constrain the decision.

A claim can include owner identity, an expiry and a monotonically advancing ownership generation. Heartbeats can renew a valid claim. Expiry permits recovery after a lost worker, but it does not reach into a paused process and prevent its later instructions from executing.

Calendar scheduling answers when an occurrence is due. A monotonic duration clock helps measure local elapsed waiting. Neither makes a remote lease holder disappear. Choose whether missed calendar occurrences are skipped, coalesced or replayed, and retain their stable occurrence identities. Recovery capacity must cover the selected missed-run policy without launching every historical sweep at once.

A replacement request is not proof that every old external operation was cancelled. A process can be delayed after it sent a request, and a remote effect can finish later. The protected state transition must still recognize which authority or object version was permitted to act.

The old worker is 40 − 30 = 10 seconds beyond its original expiry. That arithmetic does not prevent its code from running. A protected effect needs to reject generation 7 after generation 8 became authoritative. This exclusion is often called fencing; it must be enforced at a boundary the old worker cannot bypass.

For a separate selected sweep estimate, choose one hundred candidate intents and a worker inspecting twenty per second. The scan portion takes 100 ÷ 20 = 5 seconds before recovery actions, object operations and retries. A ninety-second observed run therefore cannot be explained by that scan count alone.

If the scheduler is unavailable across several intended instants, decide whether to replay every occurrence, coalesce into one current sweep or declare old work expired. A current-state cleanup scan may not need one run for every missed minute. A required periodic financial calculation could have a very different obligation.

Northwind still owns its occurrence identity, cleanup eligibility and external-effect protection. A deployment controller can manage process lifecycle while a separate application protocol determines whether deleting a particular object remains authorized.

Use recurring scheduling when time-based eligibility is a real requirement. Prefer an event-triggered task where a known state change directly identifies required work, while retaining a sweep for recovery if justified. Running the same full scan ever more frequently can hide a missing state transition and add load.

Layer 3 · Internals

A recurring schedule and an execution attempt are different records. Derive an occurrence identity from the schedule and its intended firing time, then create attempts beneath that occurrence. A worker claims a due occurrence under a lease; another worker can claim a later attempt after the lease expires. Only the current attempt token may finish the occurrence.

A timing wheel groups deadlines into buckets and can reduce timer-management overhead under its resolution and range assumptions. It is not the durable source of pending obligations. Rebuild the in-memory lookahead from persisted occurrences after a restart. A database polling design can claim rows using bounded transactions and skip locked candidates, but a claim does not make a subsequent external effect atomic with that transaction. Define whether missed occurrences are skipped, coalesced or replayed. A billing schedule usually cannot inherit the same missed-run policy as a disposable cache refresh.

Trade-offs and limits

ApproachProvidesRequires
Persisted due-row scanSimple recovery and an inspectable claim transaction.Polling and index maintenance grow with scheduling traffic.
Durable source plus timing wheelEfficiently manages many near-term timers.Resolution, rebuild and missed-occurrence rules remain explicit.

Recovery decision

Hypothetical scenario: Two scheduler leaders enqueue the same due time after failover. A unique occurrence record must bind all attempts to one logical job.

That is a domain policy, not a scheduler default. Define whether to catch up, coalesce, expire or require review, and budget the resulting burst.

Write your design before revealing the review

Should a missed hourly job always run once per missed hour after a day outage?

Evidence you can explain in your own design

Drafts and self-review are stored only in this browser. They are separate from reading completion.

Compare your decision

That is a domain policy, not a scheduler default. Define whether to catch up, coalesce, expire or require review, and budget the resulting burst.

Two scheduler leaders enqueue the same due time after failover. A unique occurrence record must bind all attempts to one logical job.

Check your understanding

Should a missed hourly job always run once per missed hour after a day outage?

That is a domain policy, not a scheduler default. Define whether to catch up, coalesce, expire or require review, and budget the resulting burst.

How would you recover from this failure: Two scheduler leaders enqueue the same due time after failover. A unique occurrence record must bind all attempts to one logical job.

Start with the exact boundary that failed. Derive occurrence identity from schedule and intended time. Claim it conditionally and queue recoverable work. Record attempts/effect progress under that occurrence. Then recover evidence through the observation path: Read occurrence state rather than counting worker starts. Apply explicit missed-run/catch-up policy. Reconcile long-running or orphaned attempts. Preserve the distinction between a confirmed state change and an unavailable response.

Which assumption in the worked calculation would a burst or concentrated tenant invalidate first?

Hypothetical 10,000 schedules due each minute create 10,000 / 60 ≈ 166.67 occurrences/s on average, but synchronized minute boundaries create a 10,000-item burst. At 500 starts/s, dispatch alone requires at least 20 seconds without other work. Recompute the affected resource rather than multiplying unrelated storage and network budgets by the same factor. Distinguish schedule occurrence from execution attempt. Calendar policy, catch-up and job effects must survive leader changes without silently multiplying a business occurrence.

Which component in this topology could be removed from a smaller first deployment?

Schedule registry, Due occurrence, Execution queue, Job journal name responsibilities, not a requirement for separate processes. Co-locate responsibilities when their transaction, trust and capacity boundaries permit it. Derive occurrence identity from schedule and intended time.

What evidence must a caller have before relying on the observation path?

Read occurrence state rather than counting worker starts. Apply explicit missed-run/catch-up policy. Reconcile long-running or orphaned attempts. That is a domain policy, not a scheduler default. Define whether to catch up, coalesce, expire or require review, and budget the resulting burst.

45-minute interview rubric

  1. 00–05: scope job occurrence and schedule occurrence.
  2. 05–12: identify the limiting resource and derive the domain workload above, retaining units and assumptions.
  3. 12–28: draw schedule occurrence, numbered writes and reads.
  4. 28–40: challenge recovery: Persist due occurrences and fence completion by attempt ownership.
  5. 40–45: defend schedule_id placement, observations and remaining assumptions.

Go deeper

  • CronJob | Kubernetes · Primary document · kubernetes.io. Persist due occurrences and fence completion by attempt ownership. Verified 2026-10-26.

Decision log

Persist due occurrences and fence completion by attempt ownership.

Preserve job occurrence identity and schedule occurrence ownership.

Revisit changed workload, observations or recovery objectives.