Chapter Fourteen · Problem Eight

Distributed Message Queue

The broker Chapter 6 left as a box, opened: a log on disk, a rule for when the yes goes back, and order that holds per key.

4 lessons · 45 minutes
The Question

"Design a message queue that producers write to and many consumer groups read from, without losing a message."

You have already drawn this as one box. Chapter 6's Queues, Logs and Pub-Sub used the broker that way, and said that how it stores and copies the log was this chapter's job. So here you open the box, as far as a whiteboard goes. Real brokers as products, with their settings and their tuning, stay outside this course.

Most of the parts are already yours. From Chapter 3 you bring the arithmetic of When One Machine Is Not Enough, and Hot Partitions for the key that will not split. Chapter 4 gives you Leaders, Followers and Everyone for when a write counts, and Quorums for the sums of a majority. Chapter 5 left two promises to keep here: Why Agreement Is Hard promised a partition exactly one leader, and Clocks and Ordering promised offsets. Leader Election and Consensus, and Leases, Locks and Fencing, are how the first gets kept. Chapter 6 adds Delivery Semantics at Scale for the duplicates, and Backpressure and Load Shedding for the group that falls behind.

Expect this one at senior and staff. A mid-level candidate who reaches a replicated log with offsets has done well. The difficulty comes in three layers. The first is the log as a storage model: append-only files and offsets the consumer owns, in place of an acknowledgement for every message. The second is replication and the rule behind the yes: what "committed" means, and a failover that loses nothing acknowledged. The third is order against parallelism: partitions, keys, and what a group goes through when it has to reshuffle who reads what.

Before Scope, start a 45-minute countdown and answer the question on paper, down to the moment your yes goes back. Minute 10 ends Scope, minute 20 ends First Design, minute 30 ends Scaling It, and Deep Dives and Curveballs takes you to the end. When the time is up, kill the broker that has just said yes, and count what is gone.

The 45 minutes of this problem, lesson by lesson
Scopeminutes 0-10
→
First Designminutes 10-20
→
Scaling Itminutes 20-30
→
Deep Divesminutes 30-45

Lessons in This Chapter