How to Scale Kafka (for your System Design Interview)
๐จ ๐ง๐ต๐ฒ big ๐ฑ๐ฎ๐ is coming! Your e-commerce system processes 1,000 orders/second on a normal day and suddenly it's 50,000 orders/second. How do you scale Kafka?
๐งฉ ๐๐ฑ๐ฑ ๐ฝ๐ฎ๐ฟ๐๐ถ๐๐ถ๐ผ๐ป๐ ๐ณ๐ผ๐ฟ ๐ฝ๐ฎ๐ฟ๐ฎ๐น๐น๐ฒ๐น ๐ฝ๐ฟ๐ผ๐ฐ๐ฒ๐๐๐ถ๐ป๐ด
Partitions are independent, ordered logs. Each partition guarantees order within itself. Customer A's orders in partition 7 stay in sequence, while Customer B's orders in partition 23 process in parallel. More partitions = more throughput.
๐ฅ ๐ฆ๐ฐ๐ฎ๐น๐ฒ ๐ฐ๐ผ๐ป๐๐๐บ๐ฒ๐ฟ ๐ด๐ฟ๐ผ๐๐ฝ๐
You can have up to one consumer per partition. With 50 partitions, you can run up to 50 parallel consumers. Each sees events in order within their partition. Need more parallelism? Add partitions.
๐ฅ๏ธ ๐ฆ๐ฐ๐ฎ๐น๐ฒ ๐ฏ๐ฟ๐ผ๐ธ๐ฒ๐ฟ๐ ๐ต๐ผ๐ฟ๐ถ๐๐ผ๐ป๐๐ฎ๐น๐น๐
Brokers are Kafka servers that host partitions. Running 50 partitions on 3 brokers? Add more brokers to spread the load. Kafka automatically rebalances partitions across all brokers.
๐ง๐ต๐ฒ ๐ธ๐ฒ๐ ๐๐ฟ๐ฎ๐ฑ๐ฒ๐ผ๐ณ๐ณ: More partitions = more throughput BUT ordering only within each partition, not globally. Don't forget this!