AlgoViz

Requirements of a task scheduler

medium 26 min

A task scheduler runs work later, in the right order, on many machines, and does not forget it.

When it comes up

The moments this idea belongs in a design interview, and the moments it does not.

Signals

When it comes up

You hearAskBecause
Send it laterHow late may it be?It decides polling and windows
Every night at twoWhat if one run is missed or long?It decides catch-up and overlap
Never lose a jobWhat may happen twice?It leads to keys and idempotency
Important jobs firstHow long may the others wait?It decides aging
Millions of jobsHow long is one, and when are they due?It decides slots and spikes

Scoping in two minutes

  1. Interviewer

    We need something that runs background jobs.

  2. You

    How many a day, how long is one, and may a job run twice?

  3. Interviewer

    Ten million a day, two seconds each. Twice is bad for payments, fine for the rest.

  4. You

    Then I promise at-least-once with a key for each payment. Acknowledged means stored. Start latency p99 under five seconds. That is 100 tasks a second, 300 at peak, so 600 busy slots and about 86 workers of ten slots. I leave workflow graphs out. Does that match?

Options

Compare your moves

The brief says: every job must run exactly once. What do you write down?

Breaks"Exactly-once execution"
How
Repeat the wish and lock the task while it runs.
Limit
A crash after the effect and before the report leaves no correct choice.
Choose when
Never.
WorksAt-most-once
How
Mark the task done before running it.
Limit
A crash loses the work.
Choose when
The work is worthless when late, such as a metric sample.
StrongAt-least-once, effect once
How
Retry until success. A key is stored with the change, so a repeat changes nothing.
Limit
Every handler must support the key, and the other service must too.
Choose when
Almost always.