Search code examples
kubernetesapache-kafkamicroserviceskafka-consumer-api

How to expand microservices? If Kafka is used


I have built a micro service platform based on kubernetes, but Kafka is used as MQ in the service. Now a very confusing question has arisen. Kubernetes is designed to facilitate the expansion of micro services. However, when the expansion exceeds the number of Kafka partitions, some micro services cannot be consumed. What should I do?


Solution

  • This is a Kafka limitation and has nothing to do with your service scheduler.

    Kafka consumer groups simply cannot scale beyond the partition count. So, if you have a single partitioned topic because you care about strict event ordering, then only one replica of your service can be active and consuming from the topic, and you'd need to handle failover in specific ways that is outside the scope of Kafka itself.

    If your concern is the k8s autoscaler, then you can look into the KEDA autoscaler for Kafka services