1/28
Part 1 of 6 · A queue and its holdersLearn

A work queue that survives failures

OpenAI software engineer candidates report a fault-tolerant work queue as their coding question (3 reports). Two of them name the parts they had to build: enqueue, reserve, fail and a dead-letter queue, with unit tests that all had to pass (2 reports). It starts like this:

Build WorkQueue. enqueue(task_id) adds a task. reserve(worker) hands that worker the oldest waiting task and hides it from every other worker, or returns None when nothing is waiting. ack(worker, task_id) marks the task done and returns True, but only for the worker that holds it.

CallReturns
enqueue("a"), then enqueue("b")
reserve("w1")"a"
reserve("w2")"b"
ack("w2", "a")False, because w1 holds a
ack("w1", "a")True, and a is done
reserve("w1")None, because w2 still holds b

Then the interviewer adds failure. fail gives a task back, and after too many failures the task goes to a dead-letter queue. Next comes time: a reservation that ends by itself when a worker goes quiet, and a cooldown before a failed task runs again. In two reports, the second part added dependencies between tasks (2 reports).

You don't write it yet. The lesson first teaches the pieces one at a time: a line in order, a reservation only its holder can finish, retries and a dead-letter queue, leases on a clock you control, and tasks that wait on other tasks. At the end you solve the whole problem, level by level, in an interview simulation with a 60-minute timer.

This lesson builds on three earlier ones: heaps for the next task and the next deadline, the caches lesson's clock that you pass in, and Kahn's algorithm from the topological sort lesson, which comes back when tasks wait on other tasks.