Builders, note 1 of 4

Late is not permission

Deadlines, clocks and timers in a system that acts for people, and why a due time authorises nothing by itself

One sentence, several kinds of when

“Ask Inés tomorrow morning. Get her confirmation by Friday. Don’t contact her after Friday.” That instruction contains at least three different time rules, and none of them belongs in a single date field.

Rule Meaning
Not before The action cannot begin earlier
Due at The action becomes eligible, or is expected, at that time
Deadline The required outcome should exist by that time
Expires at Permission or validity ends at that time

A missed deadline might call for escalation. An expired permission forbids further contact. Being late does not authorise the system to do more.

Time passing and the system noticing that time has passed are separate events. A deadline can pass while every process is down, and the responsibility has to survive that gap.

Choose the kind of time first

An instant, a duration and a calendar time answer different questions. Decide which one you mean before deciding how to store it.

An instant is a point on the timeline. A duration is an amount of elapsed time. A calendar time, such as Monday at 09:00 in Lisbon, needs a date and a time zone before it names an instant.

“24 hours later” and “the same time tomorrow” differ across a daylight-saving change, and “one month later” needs calendar rules. When clocks go back, a local time happens twice. When they jump forward, it never happens at all. A scheduler needs a stated policy for both.

Nine o’clock where the person is now and nine o’clock in the zone they chose become different instants once they fly from Lisbon to Osaka. Storing everything in UTC cannot recover a calendar intention that was never recorded.

Two clocks, two jobs

A wall clock estimates the date and time. A monotonic clock measures elapsed time. Each fails at the other’s job.

Wall clocks jump backwards or forwards when they are synchronised or corrected. Monotonic clocks never go backwards, but a stored monotonic reading means nothing on another machine or after a restart. Use the wall clock to record observations and store deadlines, and the monotonic clock to time a request inside one process.

Every clock is an estimate: reference time plus an error that drifts. With a defensible bound on that error, a timestamp becomes an interval, and overlapping intervals can leave order unresolved. Timestamp precision is not timestamp accuracy. Six decimal places can describe a wrong clock very precisely.

Order comes from cause

Whether one event came before another is decided by what could have influenced what. Timestamps from different machines cannot decide it alone.

When a request goes out, gets answered and the answer comes back, the exchange itself fixes the order, whatever the clocks say. Lamport’s happened-before relation formalises this. A logical clock built on it gives causally earlier events lower counts, and a lower count alone proves no cause.

One response carries several times. A supplier in Riyadh agrees at 16:58, the report arrives at 17:04, and the deadline was 17:00. Whether that was on time depends on what the deadline measures, which source says when the supplier answered, how far that source is trusted and what policy covers late arrivals. A late observation does not prove a late occurrence.

A waiting job is a stored responsibility

A process that sleeps for a day before sending a reminder takes the reminder with it when it dies. A durable timer is a written-down responsibility with a way to recover it.

A durable timer records what it is for, the work it belongs to, when it is due, its status and the version of the schedule that created it. A scheduler repeatedly looks for pending timers due at or before now. “At or before” matters: a check for equality misses the timer forever if no worker runs at that exact instant. A database row does not wake itself up.

The timer proposes, the present decides

When a timer fires, the world may have moved on. The timer can propose work, and only the current state can permit it.

Before a reminder falls due, the other person may reply, the owner may cancel, or the permission may lapse. At the moment of action, check again: is the responsibility still active, is the condition still unmet, does this timer belong to the current schedule, and is the action still authorised?

If a reminder moves from 09:00 to 15:00, the old timer may still arrive. Carry the schedule version and reject mismatches where the change is written. Deleting the old timer is housekeeping. Rejecting stale work is what keeps the system correct.

Timers can also run twice, when a scheduler does the work and dies before recording completion. A stable timer identity helps, and it still cannot guarantee a single effect in the world. Durable scheduling has to expect retries without assuming they are harmless.

Missed work needs a policy

After downtime, missed work needs a rule chosen in advance: catch up, coalesce, skip or escalate.

  • Catch up: perform every missed occurrence.
  • Coalesce: perform one action that stands for all of them.
  • Skip: drop occurrences outside the permitted window.
  • Escalate: report the missed time and ask for a decision.

Sending four overdue reminders at once can be faithful to the schedule and absurd to the person receiving them. Store the due time, the latest permitted time and the policy together. “Run eventually” and “run at the right time” are different guarantees.

Timeouts and leases

A timeout says an answer did not arrive in time. It says nothing about whether the remote action happened.

A retry must respect the time and the authority that remain. Work can stay unresolved past its deadline. The deadline changes policy. It does not manufacture knowledge of the outcome.

A lease gives a worker ownership until a set time. At 10:05 a second worker takes over, but the first may only have paused, and when it resumes, both act. An expired lease stops nobody. A fencing token, a number that rises with each new owner, lets a resource reject writes from an older owner. It protects only resources that check it. An outside service that ignores it remains an open boundary.

Questions for anything that waits

Anything that waits on time should answer these questions before it ships.

  1. Is this an instant, a duration or a calendar rule?
  2. Which time zone, and which policy for ambiguous or missing local times?
  3. What survives a restart, and how is overdue work found?
  4. What happens if the same wake-up arrives twice, or arrives stale?
  5. What happens if authority expires while waiting?
  6. How are missed occurrences handled?
  7. What timing guarantee does measurement actually support?

A timer row proves the intention to act on time. Only measurement shows whether the system does.

What wakes it, when does that wake-up become eligible, and what is still permitted when it arrives?

Further reading

The classic work on clocks, order and leases.

  • Lamport, L. (1978). Time, clocks, and the ordering of events in a distributed system. Communications of the ACM, 21(7).
  • Gray, C. and Cheriton, D. (1989). Leases: an efficient fault-tolerant mechanism for distributed file cache consistency. Proceedings of the 12th ACM Symposium on Operating Systems Principles.
  • Mills, D. L. (1991). Internet time synchronization: the Network Time Protocol. IEEE Transactions on Communications, 39(10).
  • Kleppmann, M. (2017). Designing Data-Intensive Applications. O’Reilly Media.