This is more of a system design question.
Let's assume I have a microservice architecture and I have X instances of Service B (to load-balance HTTP requests to the service). But, Service B is also a consumer on some Kafka topic. How can I avoid processing the same message X times (X is the number of instances of Service B)? at least once could be fine if processing is idempotent. It doesn't need to be exactly once, but cannot be X times .
Service A could be an Order Service. It produces messages about user making an order to Orders topic.
Service B could be a Payment Service. It consumes messages from Orders topic to charge the user.
Paying for an order could be an idempotent operation. But still, if I have 10 instances of Payment Service, I don't want to waste CPU and IO for doing something 10 times.
Even if partitioning is the answer, what if we have more instances of a particular microservice than partitions?