Inside a Distributed Queue 00:00:01 Follow a ticket into the warehouse A warehouse sends a packing instruction. The broker acknowledges a durable position and, later, a worker reports how far it has processed. Those acknowledgments answer different people and promise different things. The producer sends a message to the frontend, through a load balancer. The message goes to broker 1, the leader. All in-sync replicas have it, so the producer gets offset 100. The work is done. The consumer commits 101, the next one to read. Here we are designing a partitioned log as a queue. A visibility-timeout work queue uses a different acknowledgment model. Decide which model your worker will be expected to recover from. 00:00:45 Keep one order's steps on the same belt Created, packed and shipped are easy to reason about if each order's events stay on the same belt. Choose a stable order identifier as the partition key so unrelated orders can progress independently. Created and paid of order A land on different partitions. Order A goes to P0 and order B to P2, each in sequence. Order A sends most of the messages. P0 is long while P1 is empty. A few huge orders can overload one belt. Review the traffic distribution per key, not just the number of partitions. Splitting a hot order changes which operations you can order naturally. 00:01:27 Draw the line between copied and committed The warehouse keeps several broker copies. A newly appended record can be present on the leader before lagging followers have it. Observe the boundary that determines which records are committed and readable. All three have 100 messages. The high watermark is 100. Broker 2 has fetched it. Broker 3 has not. Broker 3 has fetched it, too. The write is confirmed and readable. In this example the minimum in-sync count is two. With only the leader eligible, a write requiring all in-sync replicas is rejected. Configure the required in-sync replica count together with the producer acknowledgment policy. Under-replication can deliberately reject new writes to preserve the durability promise. 00:02:15 The belt supervisor disappears A replica that already has the committed prefix can become the new leader. During election and rediscovery, a brief gap in successful writes is expected. Durability and uninterrupted availability are separate questions. Brokers 1 and 2 are in sync. Broker 3 lags. The controller no longer hears broker 1. Writes fail for a moment. The producer fetches new metadata and writes to broker 2. Broker 1 returns as a follower, drops what was never confirmed, and copies. An uncertain reply can still produce a retry of a successful write. Use an appropriate idempotent producer and keep the consumer's own side effects safe to repeat. 00:03:00 A packed parcel with no progress receipt The worker handles three more positions and then loses power before committing its next offset. The replacement consults durable progress, so already-handled work may appear again. 0 to 4 are finished. The commit says 5. 5, 6 and 7 are handled, but not committed yet. The new owner starts at 5. It handles 5, 6 and 7 again. Mark a stable instruction identifier together with the business update, or make that update naturally idempotent. The queue can then deliver again without persuading the warehouse to ship the same box twice.