10/41
Part 2 of 7 · The serviceLearn and do

A request moves through six states

Once accepted, every request moves through a fixed set of states.

FromEventTo
queueda worker takes a leaserunning
runningthe result is writtensucceeded
runningthe lease lapses: attempt + 1queued
runninginvalid, or failed for gooderrored
queuedthe batch is canceled before a worker took itcanceled
queuedthe window closed before a worker took itexpired

A request is in exactly one state at a time:

  • queued: stored, and its batch passed the envelope checks.
  • running: a worker holds a live lease on it.
  • succeeded, errored, canceled and expired are final. A request never leaves them.

A running request whose lease lapses goes back to queued, with its attempt count raised by one.

One queue per model, with a sub-queue per tenant

A worker can serve only the model whose weights it has loaded, and loading a large model takes minutes. So queues are per model.

OpenAI builds the same limit into its API: each input file may hold requests for one model only.

Inside each model's queue, keep a sub-queue per tenant. Part 4, on fairness, shows why.

MOVES in the editor is the table of states, written as (state, event) to the next state. Write replay(events): start queued at attempt 1, apply each event the table allows from the current state, skip the rest, and raise the attempt by one on every lapse.