All scenes
Build a Message Queue (RabbitMQ / SQS)
14 scenes · ~98 min · build the primitive
Build your own Message Queue (RabbitMQ / SQS)
A point-to-point work queue — the messaging primitive Kafka is NOT. Each message goes to one consumer, ack deletes, retries push to a dead-letter queue, and a poisoned message is everyone's problem. Internalize ack vs visibility timeout vs DLQ vs prefetch vs FIFO groups — and learn to tell when Kafka is the wrong tool and when a queue is.
- 01The work that can't block the requestSome side effects (email, PDF, transcode) are too slow for the HTTP request — drop them on a buffer and let a worker pool finish them asynchronously.~7 min
- 02Kafka isn't this — reads delete hereSame picture as Kafka from a distance, opposite rules up close: the queue's read removes the cell; no other consumer will ever see it.~7 min
- 03The queue — head, tail, enqueue, dequeueTail on the right where producers push, head on the left where consumers pull, and the FIFO order between them.~7 min
- 04Competing consumers — N workers, one headPoint N workers at the same head; the broker hands each cell to whichever worker is ready. Throughput scales linearly until producer rate caps it.~7 min
- 05Ack — the consumer's 'you may delete'Dequeue is two steps: lease (hide from peers) + ack (delete). Same word as Kafka's ack, but consumer→broker direction — and auto-ack loses messages.~7 min
- 06Nack and requeue — the failure verdictThree consumer verdicts (ack / nack-with-requeue / reject-without-requeue) — and requeue-forever is a footgun.~7 min
- 07The poison message — the loop that won't endA naive requeue loop turns one un-processable message into an infinite redelivery storm that pegs CPU and starves the queue behind it.~7 min
- 08Dead-letter queue — the escape valveAfter N redeliveries, the broker routes the cell to a sibling DLQ; the main pool keeps moving. maxReceiveCount is the knob with two failure modes.~7 min
- 09Visibility timeout — the silent-worker clockPer-message countdown; if no ack arrives, the broker redelivers. Too short → duplicates; too long → stuck pool; heartbeat extend is the fix.~7 min
- 09aPrefetch — how many in flight per workerPer-worker cap on un-acked in-flight messages. Too low → throughput collapse on RTT; too high → one greedy worker hoards.~7 min
- 10Ordering vs parallelism — partition the keyspaceGlobally ordered + competing consumers is impossible. FIFO preserves order WITHIN a message group; many groups = parallelism. Kafka's partition-by-key in queue costume.~7 min
- 11Routing — one queue per consumer groupFanout in queue-world is an exchange/SNS topic that copies each message into N physical queues — opposite of Kafka's N cursors on one log.~7 min
- 12Operations — depth, age, DLQThree numbers tell you a queue's health: visible depth, oldest-message age, DLQ depth. Each one points at a distinct underlying failure.~7 min
- 13Design canvas — pick the queue for the workloadCapstone: place a workload on the canvas, set every knob, flag whether Kafka would have been a better fit.~7 min