Apache Kafka · KFK-09
Event & topic design
- 4 h
- requires KFK-08
From your world. fact grain and multi-company marts, decided at the topic layer
Explain to a teammate who knows Kimball well: how you design topics and keys for a multi-company commerce platform. Ordering, isolation, and load must all hold.
Rubric — a good answer covers:
- Kafka guarantees order only within a partition. The key decides the
partition (
murmur2(key) % n). So the key is the ordering contract. - Use the high-cardinality entity id (for example,
order_id) as the key. This keeps the events of each entity in order on one partition. - Don't key by
company_idalone. Skewed tenants create a hot partition. - Carry
company_idfor routing and filtering (tenant isolation). Hash the entity id for placement. - Event topic (time-retained facts) vs entity topic (compacted changelog of latest state). Choose by the need: history or current state.
- The partition count limits parallelism. It is painful to change because it remaps keys. So size it up front. Topic-per-tenant does not scale to thousands of tenants.
- Analogy: choosing the key = choosing the fact grain. The compacted entity topic = a conformed dimension on the log.