Try
↑ ↓ move↵ openesc close

Interview prep / Partitioned logs

Mid · Partitioned logs · System design interview question

A new topic must carry 30,000 messages a second. One consumer finishes 1,500 a second, and one partition can take 10,000 a second from producers. How many partitions do you create?

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

A strong answer

Take the larger of the two requirements. Producers need 30,000 / 10,000 = 3 partitions. Consumers need 30,000 / 1,500 = 20. So 20 is the floor, set by the consumer side.

I would not stop at 20. If traffic is likely to double, 40 leaves room to add consumers without touching the topic, which matters because changing the count later remaps keys. Running 20 consumers on 40 partitions means two partitions each, which is fine.

Going far past that has costs. More partitions mean more open files, longer leader elections when a broker fails, bigger rebalances and smaller producer batches. Sizing for twice the projected need is a reasonable balance.

Check the assumption behind the number too. The formula assumes load spreads evenly over keys. If one key carries a large share, the partition holding it needs a consumer faster than 1,500 a second, and no partition count fixes that.

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