Ordering
Last updated
Last updated
If the msg producing order is the same with msg consuming order, then msgs are in order.
The msg producing order is the order when msg arrives at broker.
For Kafka, it could not guarantee the order across different partitions.
Cross-partition ordering would typically need a role for coordinator.
Suppose msg1 is produced before msg2 but msg2 arrives at consumer before msg1
Then the coordinator needs to hold msg2 until msg1 is consumed.
Steps
Calculate a hashing value according to the business key.
Calculate a slot index according to hashing_value % slot_num.
Decide the mapping between slot and partition based on load.
The mapping between slot and partition could be stored inside service registry.
Redis uses 16385 slots, and the number of slots could be decided based on business cases.
Adjust the partition allocation on ring for data distribution.
For example, message id = 3 and id = 7 will land on the same partition after resizing.
However, when there are many backlogs on partition 0 for id = 3 and there is no backlog on partition 3 for id = 7 due to resizing, then id = 7 will be consumed before id = 3.
For all new partitions, wait for certain period which is long enough for old backlog messages to be consumed.