You're designing the topic layout for a high-volume Kafka stream and the team wants both strict ordering and high throughput. Walk me through how you'd choose the number of partitions and the partition key, and the trade-off you're making.

technical-conceptual · Senior level · data-ml

What the interviewer is really asking

Assesses whether the candidate understands that Kafka ordering is per-partition (so the key choice and partition count directly trade ordering scope against parallelism), plus consumer-group and rebalance implications, rather than treating partition count as a pure throughput dial.

What to say

What to avoid

Example answers

Strong: The first thing I'd anchor on is that Kafka only guarantees order within a partition, and the key hashes to a partition — so the key is the unit of ordering. If we need per-user order, I key by user_id and every user's events stay ordered, but there's no global order across users, which is usually fine. Partition count then trades throughput against that: more partitions means more parallelism, since a consumer group can run at most one consumer per partition, but it widens the cross-partition no-order surface and adds overhead, so I'd size for peak throughput plus headroom rather than picking a huge number. I'd check key distribution for hot keys that would bottleneck one partition, and make sure we're on the cooperative-sticky rebalance protocol — default since 3.0 — so scaling consumers doesn't stop-the-world.

Weak: I'd set a high partition count, like 100, so we get lots of throughput and parallelism, and use a random or round-robin key so the load spreads evenly across all the partitions. That way every consumer stays busy and the stream is fast.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.