Comments on: Concurrency with Kafka and Spring Boot https://piotrminkowski.com/2023/04/30/concurrency-with-kafka-and-spring-boot/ Java, Spring, Kotlin, microservices, Kubernetes, containers Fri, 01 Mar 2024 22:03:31 +0000 hourly 1 https://wordpress.org/?v=6.9.1 By: piotr.minkowski https://piotrminkowski.com/2023/04/30/concurrency-with-kafka-and-spring-boot/#comment-2342 Fri, 01 Mar 2024 22:03:31 +0000 https://piotrminkowski.com/?p=14121#comment-2342 In reply to Nikita.

1. Yes, if you need ordering, for sure don’t use 4 solution
2. Yes, it happens, but the same things happen in all other points. However, there are mechanisms in spring kafka for handling it. By dafault, it retries the operation several times, you can also apply it: https://docs.spring.io/spring-kafka/reference/kafka/annotation-error-handling.html

]]>
By: Nikita https://piotrminkowski.com/2023/04/30/concurrency-with-kafka-and-spring-boot/#comment-2314 Mon, 26 Feb 2024 09:41:50 +0000 https://piotrminkowski.com/?p=14121#comment-2314 There are 2 problems with solution 4.

1. out of order processing possible
2. offset commits happen before processing of the messages happen, so in case of failure offset is already commited but messages will be never processed

]]>
By: piotr.minkowski https://piotrminkowski.com/2023/04/30/concurrency-with-kafka-and-spring-boot/#comment-2270 Tue, 30 Jan 2024 13:01:57 +0000 https://piotrminkowski.com/?p=14121#comment-2270 In reply to Ankit Sood.

Yes, there was also a similar question from another person in the article comments. By default, Spring Kafka handles offset commits. When we are processing the already received messages in the threap pool it does not have any impact on the offset commits, because it has already been done by the Spring Kafka.

]]>
By: Ankit Sood https://piotrminkowski.com/2023/04/30/concurrency-with-kafka-and-spring-boot/#comment-2268 Thu, 25 Jan 2024 10:40:57 +0000 https://piotrminkowski.com/?p=14121#comment-2268 In reply to piotr.minkowski.

Hi,
I just saw this and had the same question as ROD. Based on the code:
public void listen(Order order) {
LOG.info(“Received: {}”, order);
executorService.submit(() -> service.process(order));
}

We are consuming the message and then submitting it to the thread pool. In this case, we are having the pool size as 30. If all the events are processed in independent threads, then JVM can choose any thread to be process. This can result in a situation where message which was at offset x+10 get processed before the message at offset x.

I am not sure how acknowledgement works in spring kafka but if we are setting the ACK at record level. This behaviour seems likely and if our application goes down at that moment, the kafka should start from latest offset.

Please give more clarity on this.

]]>
By: piotr.minkowski https://piotrminkowski.com/2023/04/30/concurrency-with-kafka-and-spring-boot/#comment-2264 Fri, 19 Jan 2024 12:10:32 +0000 https://piotrminkowski.com/?p=14121#comment-2264 In reply to Rod.

Definitely no. If you take a look at the scenario 4 once again, you will see that the concurrency at the consumer level is `3`. The thread pool you are asking about (`Executors.newFixedThreadPool(30)`) is processing the already “consumed” messages. Since Spring Kafka is responsible for commiting offsets, it has nothing to do with the offset commitment.

]]>
By: Rod https://piotrminkowski.com/2023/04/30/concurrency-with-kafka-and-spring-boot/#comment-2246 Wed, 10 Jan 2024 14:41:44 +0000 https://piotrminkowski.com/?p=14121#comment-2246 Hello, just came across this article. One interesting thing about starting your own threads like you do there in the end of your article, is how to control offset commits. Am I wrong to assume that offsets would be committed in a total chaotic order, hence, if offset 8 could be committed before offset 1, it basically means you’d lose all messages with offsets 1 to 7?

In other words, it would be hard to guarantee delivery of any messages?

]]>
By: piotr.minkowski https://piotrminkowski.com/2023/04/30/concurrency-with-kafka-and-spring-boot/#comment-2154 Fri, 06 Oct 2023 21:52:34 +0000 https://piotrminkowski.com/?p=14121#comment-2154 In reply to Eduardo Silva.

Thanks!

]]>
By: Eduardo Silva https://piotrminkowski.com/2023/04/30/concurrency-with-kafka-and-spring-boot/#comment-2151 Tue, 03 Oct 2023 21:08:26 +0000 https://piotrminkowski.com/?p=14121#comment-2151 Very good material, thank you for your contribution.

]]>
By: piotr.minkowski https://piotrminkowski.com/2023/04/30/concurrency-with-kafka-and-spring-boot/#comment-2114 Tue, 05 Sep 2023 08:28:39 +0000 https://piotrminkowski.com/?p=14121#comment-2114 In reply to Pushkar Kumar.

Hi!
Thanks! Well, I don’t think that ExecutorService will hinder anything. Why? It just processes messages using thread pool – normal approach. Just a question to your app – if don’t have to process messages sequentially

]]>
By: Pushkar Kumar https://piotrminkowski.com/2023/04/30/concurrency-with-kafka-and-spring-boot/#comment-2108 Wed, 30 Aug 2023 18:17:13 +0000 https://piotrminkowski.com/?p=14121#comment-2108 Hi Piotr, It really made Concurrency & Spring Kafka very clear to me, Thanx for the article. In My use case I will also be handling approximately around 3-4k msg/sec, so Executor service with concurreny field seems to be a valid option to me.

Just wanted to clarify one thing:-

1. Does using Executor Servcie will hinder the offset mainatinence part, because I don’t want to lose any message maybe due to some downtime or exceptions while processing.

Thanks Again!

]]>