Inside a Pub-Sub System 00:00:01 Design a newswire with two delivery doors A weather station publishes observations once. Some clients pull a batch. Others receive a push callback. Start by identifying the durable event and each subscription's outstanding work before designing the network API. The publisher sends a topic, a key and a payload to the gateway. The broker appends the message to the replicated log and then confirms. The pull reader asks for messages and receives those it has not acknowledged. The reader acknowledges by a call. The endpoint's success status is its acknowledgement. A publisher confirmation records acceptance according to the broker's durability contract. A subscriber acknowledgment records progress for one subscription. Put them on different arrows in the architecture diagram. 00:00:47 Decide when the publisher hears yes The replicated log design in this example has three copies. Confirming before the promised replication point makes a fast answer that the system may be unable to honor after failover. Three copies hold 100 records each. Both followers copy it. All in-sync copies have it. Now the publisher hears yes. With a configured minimum of two in-sync copies, a lone surviving leader rejects new writes under this acknowledgment policy. Publishing latency now includes the required replicas. Document the behavior during replica loss so producers can tell an unavailable write from one that was accepted but lost its reply. 00:01:27 A bookmark cannot jump over a missing page A subscriber runs three callbacks in parallel. Two later offsets finish before the oldest. Advancing one scalar bookmark to the largest observed success would silently discard the unfinished work. The subscription holds offsets 0 to 4. The cursor is at 0. They finish first. Offset 0 is still running, so the cursor cannot move. The gap closes. The cursor jumps over 0, 1 and 2. The server restarts with cursor 3. Offsets 3 and 4 are delivered again, nothing before. Track completed gaps until the contiguous prefix advances. Persist enough state to recover the advertised redelivery behavior, and require the receiving service to tolerate a repeated callback. 00:02:15 A broken receiver must not stall the newswire A push endpoint returns a server error. Retry temporary failures on a bounded schedule, with jitter so thousands of recovering messages do not hit the same host together. The endpoint answers 500. Wait 1 second. Wait 2 seconds, then 4. Wait 8 seconds. Random jitter keeps many messages from returning together. The last attempt fails. The message moves to the dead-letter topic with its error. Keep the last failure, message identifier and delivery history when sending work to a dead-letter destination. Provide a replay procedure that respects the receiver's idempotency rule. 00:02:54 Route one station to the same partition Late deliveries and parallel workers make ordering expensive. If consecutive readings must preserve order within a station, use that station as the routing key and document the ordering scope precisely. The topic orders has P0, P1 and P2, all empty. Suppose key k1 hashes to P0, k2 to P1 and k7 to P2. k1 sends two more. They follow the first in P0. If k1 is most of the traffic, P0 is busy and the others idle. A fourth partition would not help. Measure lag by subscription and partition. A single high-volume station can overload one partition even when average capacity looks fine. That observation tells you which design choice to revisit first.