Senior
How to deliver messages to all 4 instances with a 2-partition limit? Standalone consumer pattern
sobes.tech AI
Answer from AI
With 2 partitions and 4 standalone consumer instances, to deliver messages to all 4 instances, the following approach can be used:
- Each instance subscribes to both partitions, but since partitions are limited, in Kafka's standard model, each partition can only be processed by one consumer in a group.
- To deliver messages to all instances with partition limitations, patterns like broadcast or fan-out outside Kafka are used, for example, through an additional layer:
- Use a separate message broker (e.g., Redis Pub/Sub, RabbitMQ) that duplicates messages for all instances.
- Or, each instance reads independently from Kafka with different consumer groups (standalone consumer), so each will receive all messages, but this increases Kafka load.
Thus, with the standalone consumer pattern and partition limitations, to deliver messages to all 4 instances:
- Create 4 different consumer groups (one per instance) so each receives all messages.
- Or implement an additional message relay layer for broadcast.
It is important to understand that Kafka does not guarantee delivery of a single message to multiple consumers within the same group, so for multi-delivery, different groups or external mechanisms are needed.