Essay series · 2 essays

Fair Scheduling Across Queues with Deficit-Weighted Round Robin (DWRR)

When several producers share one consumer, something has to decide whose work goes next. Taking turns sounds fair until the turns are different sizes.

Deficit weighted round robin measures turns in work rather than in count, and it does so with almost no bookkeeping. It fits in a paragraph. An implementation that other people can rely on needs more than a paragraph: answers to every question the paragraph leaves open, and a way to show that the code gives those answers.

The first essay, Taking Turns, starts from the need, works through the questions the paragraph leaves open, and checks an implementation against a deliberately simple reference. The second, Reviewing a Fair Scheduler, follows the fixed-quantum Go implementation’s promises through its tests, arithmetic, and storage.

Engineering work

I developed the Go, Elixir, and Python libraries around explicit scheduling rules, reference-model testing, and a shared fixed-quantum contract.

A shared draft specification, executable model, conformance corpus, replay tools, and protocol checker give the implementations a common fixed-quantum target. Pinned snapshots make checks reproducible. A live generating, fuzzing, shrinking harness remains planned.

Implementations

  1. Part 1

    Taking Turns

    Why taking turns isn't enough to share a consumer fairly, how deficit round robin measures turns in work, and how a deliberately simple reference shows that an implementation follows the rules.

    9 min read

  2. Part 2

    Reviewing a Fair Scheduler

    A code review of dwrr, following its documented promises through test assertions to the state, arithmetic, and storage rules that make them hold.

    10 min read

See also

All writing