<p>Small question regarding SpringBoot Kafka apps deployed in Kubernetes and how to Load Balance then please.</p>
<p>Background:
I used to have a very simple SpringBoot web app, exposed over http, just doing a rather complex and lengthy computation.</p>
<pre><code>@RestController
public class HelloHttp {

    @Autowired BusinessService businessService;

    @GetMapping(&quot;/business&quot;)
    public String veryComplicatedAndTimeConsumingBusinessLogic(@RequestBody String request) {
        return businessService.veryComplicatedAndTimeConsumingBusinessLogic(request);
    }
</code></pre>
<p>As this web app is getting popular, many more clients were using it, we decided to containerize it, and deploy it in Kubernetes (AWS). We created 5 replicas of it with a Kubernetes deployment / replica set. We then created a Kubernetes Service type Load Balancer, and like magic, we could see requests being load balanced between the 5 replicas. Meaning, one pod will process one request, then, another pod will process the next one, etc...</p>
<p>Some organization change happened, and instead of the clients sending the request http style, they all now put the payload inside Kafka. (The question is not about the legitimacy of this choice).</p>
<p>We then migrated this web app using Spring Kafka, to something like this:</p>
<pre><code>public class HelloKafka {

    @Autowired BusinessService businessService;

    @KafkaListener(topics = &quot;businessTopic&quot;)
    public void veryComplicatedAndTimeConsumingBusinessLogic(String message) {
        businessService.veryComplicatedAndTimeConsumingBusinessLogic(message);
    }
</code></pre>
<p>We just know the Kafka host, the topic (no information about consumer group?)</p>
<p>Still, like magic, on a single instance, we could see the application consuming the messages from Kafka and processing them.</p>
<p>As the load is still the same, we decided to deploy the same, again in Kubernetes, using deployment + replica set + service type Load Balancer.</p>
<p>However, very strange, we are not observing the load balancing mechanism at all.</p>
<p>May I ask what did I miss please?</p>
<p>Thank you</p>

PatPanda
<blockquote>
<p>no information about consumer group?</p>
</blockquote>
<p>You define that on your own. <code>groupId</code> is a param to <code>@KafkaListener</code>.</p>
<blockquote>
<p>we are not observing the load balancing mechanism at all</p>
</blockquote>
<p>It's not a Kubernetes problem. Kafka consumers do not &quot;distribute load&quot;. Instead, all consumers in the same <strong>consumer group</strong> (again, something you set) get assigned to individual partitions in the topic.</p>
<p>So, either</p>
<ul>
<li>if you didn't set a <code>groupId</code>, it may be auto-generated by Spring, and each instance is reading all partitions</li>
<li>your topic has one partition (which is the default, if they were auto-created); therefore only one consumer at most in the group can read the topic</li>
<li>the upstream producers are only sending data to one partition, so only one consumer is reading it, and that is out of your control</li>
</ul>
<blockquote>
<p>legitimacy of this choice</p>
</blockquote>
<p>Kafka is generally considered more highly available than an HTTP server with or without replicas. And it acts as a buffer to prevent DOS attacks against those endpoints. Plus, you probably don't need the overhead of HTTP vs plain TCP.</p>
