Log-Based Message Queues (Kafka Concepts) 00:00:01 A notebook whose pages stay numbered A dispatch clerk writes every event on the next line of a notebook. Each partition has its own notebook and local offsets. Reading a line moves the reader's bookmark without erasing the line. The producer's message goes to the end of the log and gets offset 7. Now and then an entry is added to the offset and time indexes. The follower fetches offset 7 from the leader. The cleaner deletes or compacts sealed segments. The consumer is not involved. The offset is an address within that partition. It is not evidence about the order of events on other partitions and need not equal a business event identifier. 00:00:45 Three readers bring different bookmarks Shipping wants the next unprocessed order, analytics is behind, and a brand new search index needs history. Give each subscription its own bookmark. None of those jobs has to reset another team's position. Shipping is next at 5, analytics at 2. It reads 5 and 6 and is next at 7. The log is unchanged. A search indexer joins and starts at 0. Shipping had a bug. Its position is set back to 2. Replay can rebuild derived state, provided the data are still retained. For a side-effecting reader, distinguish replaying database calculations from repeating a customer-facing email or shipment. 00:01:35 Find line twenty-one fifty without reading from zero A huge notebook is bound into segments and contains a sparse index. Choose the segment whose base offset is nearest below the target. Jump to an indexed position and scan the short remaining distance. Bases are 0, 1000 and 2000. The last one that is not above 2150 is 2000. The index lists 2000, 2100 and 2200. The last one that is not above 2150 is 2100. Start at byte 8192 and pass 50 messages. The sparse index trades a small sequential scan for much less index storage. Offsets stay stable even when cleaning later leaves holes in the numeric sequence. 00:02:27 A late reader reaches a torn-out page The retention policy may remove an old sealed segment while a disconnected reader still needs it. Observe how an older record can survive a little longer when its segment also contains newer records. The sealed segment holds msg-1 and msg-2, 8 days old. The active one holds msg-3 and msg-4. The newest message of the sealed segment is 8 days old. The whole segment goes. The log starts at msg-3. Here one sealed segment holds messages of 8 and of 2 days. Nothing is deleted yet. When planning recovery, compare the worst outage and catch-up time with the actual retention window. A bookmark proves where the reader wanted to go, but it cannot reconstruct deleted bytes. 00:03:20 Keep the final address or keep every move For a directory, a customer's latest address is enough. For a ledger counting every shipment, earlier events still matter. Log compaction serves the first type of reconstruction by keeping recent values for each key. Each key has several values. C ends with a tombstone at 6. A is at 5, C at 6, B at 7. Offsets 0 to 4 are removed. The others keep their numbers. After the configured tombstone retention interval, the delete marker can also be removed. A lagging reader needs a recovery strategy. A tombstone represents deletion. Its retention must cover the rebuild contract for downstream readers. Choose compaction for current-state reconstruction and retain complete events for computations that need every transition.