Try
↑ ↓ move↵ openesc close

Interview prep / Partitioned logs

Senior · Partitioned logs · System design interview question

A topic with 12 partitions is at its limit. Consumers keep per-customer state in memory. How do you move to 24 partitions safely?

Sketch your own answer first, then compare it with the one below.

A strong answer

Adding partitions in place changes the hash modulo, so about half of the keys move. For a while, a customer's older messages sit in one partition and newer ones in another, potentially handled by two consumers. In-memory state keyed by customer would be split or wrong, and per-key order breaks across the change.

The safer route is a new topic with 24 partitions. Producers write to both for a transition period, or a copier job moves history across. Consumers drain the old topic, build state in the new one, and switch when lag is zero on the old topic. Order per key holds, because each topic is consistent within itself.

If an in-place change is the only option, stop producers briefly, let consumers reach the end of the log, then add partitions, so no key has data in two places. This costs a short outage.

Either way, key consumer state by the message key and not the partition number, and confirm new partitions will not be empty and idle: 24 consumers is needed to use them.

Sources

Learn it by running it

The partitioned logs lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms