Why this matters: the ordering mechanism here is a client-supplied partition ID, which looks like leaking implementation detail into the API. It is actually the cheapest correct answer, and being able to defend that is a strong interview moment.
Key takeaway
Producers send messages to a topic, and the system distributes them to partitions using the round robin algorithm — specifically a variation called weighted round robin. Within a partition, strict ordering is maintained by appending new content to the end of the log.
Default placement: weighted round robin
Messages cycle across partitions in turn, spreading write load evenly.
Strict ordering via partition ID
"Strict ordering ensures that messages are stored in the order in which they are produced. How can we ensure strict message ordering?"
We'll assign each partition a unique ID, partition_ID. The user can provide the partition_ID while writing into the system. In this way, the messages will be sent to the specified partition, and the ordering will be strict.
The write call becomes:
write(topic_ID, partition_ID, message)
If the user does not provide the partition_ID, we'll use a weighted round robin algorithm to determine which message to send to which partition.
Producer supplies
Placement
Ordering guarantee
No partition_ID
Weighted round robin
None — consecutive messages land on different partitions
A partition_ID
That partition
Strict — appended in order to a single log
Why let the client choose at all?
It might seem strange to give the client of pub-sub the ability to choose a partition. However, such a facility can serve as a basis for clients to obtain data for a specific time period — for example, data from yesterday. For simplicity, we won't include time-based reading in our design.
Key takeaway
Weighted round robin by default, giving load balance and no ordering. An optional partition_ID gives strict ordering within one partition. Only the client knows which messages are related, which is why it — and not the system — chooses. The cost is that a badly chosen key produces a hot partition.
Interview signal by level
Level
What a strong answer sounds like
L4
"Messages are spread across partitions round robin."
L5
Knows ordering is opt-in: "round robin by default, which gives no ordering — if we need strict order the producer supplies a partition ID so related messages land on one log."
Staff+
Justifies the API shape and prices the risk: "only the client knows which messages are semantically related, so it has to choose — the system would only be able to order by arrival. I'd partition by the smallest key that needs ordering, channel ID for chat. The cost is that a keyed write bypasses load balancing entirely, so a low-cardinality or skewed key gives you a hot partition, and the fix is splitting the key and giving up order across the splits."
Next: why the messages sit on local disk.
Enjoying the preview?
Create a free account to unlock the rest of this course, the in-browser judge, and live AI mock interviews.