SDE & MLE Prep

Distributed Message Queue (Kafka)

Requirements: durable, ordered (per key), high-throughput pub/sub; consumers replay from offsets; horizontal scaling.

producer --(key -> partition = hash(key) % P)--> broker leaders
topic "orders":  P0 [0 1 2 3 4 ...]  leader B1, followers B2 B3
                 P1 [0 1 2 ...]      leader B2, followers B3 B1
consumer group G: C1 <- P0, C2 <- P1        (committed offsets per partition)
controller (KRaft/ZooKeeper): metadata, leader election

Deep dives: append-only segment files + OS page cache + zero-copy sendfile → very high throughput; replication with ISR (in-sync replicas), acks=all for durability; ordering only within a partition (choose the key carefully); retention by time/size or log compaction (keep latest per key); consumer rebalancing; exactly-once via idempotent producers + transactions.