title: How to write Kafka consumers - single threaded vs multi threaded
body: <p>I have written a single Kafka consumer (using Spring Kafka), that reads from a single topic and is a part of a consumer group. Once a message is consumed, it will perform all downstream operations and move on to the next message offset. I have packaged this as a WAR file and my deployment pipeline pushes this out to a single instance. Using my deployment pipeline, I could potentially deploy this artifact to multiple instances in my deployment pool.</p>
  
  <p>However, I am not able to understand the following, when I want multiple consumers as part of my infrastructure - </p>
  
  <ul>
  <li><p>I can actually define multiple instances in my deployment pool and
  have this WAR running on all those instances. This would mean, all of
  them are listening to the same topic, are a part of the same consumer
  group and will actually divide the partitions among themselves. The
  downstream logic will work as is. This works perfectly fine for my
  use case, however, I am not sure, if this is the optimal approach to
  follow ?</p></li>
  <li><p>Reading online, I came across resources <a href="https://howtoprogram.xyz/2016/05/29/create-multi-threaded-apache-kafka-consumer/" rel="noreferrer">here</a> and <a href="https://www.confluent.io/blog/tutorial-getting-started-with-the-new-apache-kafka-0-9-consumer-client/" rel="noreferrer">here</a>,
  where people are defining a single consumer thread, but internally,
  creating multiple worker threads. There are also examples where we
  could define multiple consumer threads that do the downstream logic.
  Thinking about these approaches and mapping them to deployment
  environments, we could achieve the same result (as my theoretical
  solution above could), but with less number of machines.</p></li>
  </ul>
  
  <p>Personally, I think my solution is simple, scalable but might not be optimal, while the second approach might be optimal, but wanted to know your experiences, suggestions or any other metrics / constraints I should consider ? Also, I am thinking with my theoretical solution, I could actually employ bare bones simple machines as Kafka consumers.</p>
  
  <p>While I know, I haven’t posted any code, please let me know if I need to move this question to another forum. If you need specific code examples, I can provide them too, but I didn’t think they are important, in the context of my question.</p>