Billing and analytics both need every event from the orders topic. How do you set up the consumers?
Sketch your own answer first, then compare it with the one below.
A strong answer
Give each service its own consumer group. A group gets a full copy of the stream, and the members inside it split the partitions. So the billing group and the analytics group each see every event, and each keeps its own committed offsets.
Putting both services in one group would be a mistake: the group would split the messages, so billing would see some orders and analytics the rest.
Because the groups are independent, they can run at different speeds. Analytics may batch and fall minutes behind while billing stays current. The one coupling is retention: if analytics falls further behind than the log keeps data, it loses events, so alarm on its lag.
Each group should be sized to the partition count. If the topic has 12 partitions, 12 is the useful maximum per group.
Sources
- Jay Kreps, Neha Narkhede, Jun Rao (2011). Kafka: a distributed messaging system for log processing.
- Martin Kleppmann (2017). Designing Data-Intensive Applications.