-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MID-164] Process kafka messages sequentially and commit manually #135
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This ensures that message processing is more reliable. By pushing the message handling off to a goroutine, we immediately "acknowledged" the kafka message and if a redeployment or an app crash happened during processing a message, it would have lost the messages. Additionally, when there are thousands of messages in the kafka topic, they all would have been read into memory and executed (more or less) simultaneously, leading to a very high memory consumption.
ulich
force-pushed
the
remove-concurrent-reads
branch
from
July 11, 2022 13:49
6762426
to
997473a
Compare
…el and wait for all to finish
jcyamacho
previously approved these changes
Jul 12, 2022
jcyamacho
previously approved these changes
Jul 12, 2022
jcyamacho
approved these changes
Jul 12, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This ensures that message processing is reliable. Before this change, the handling of a message was pushed off to a goroutine and the next message was read immediately. As soon as the next message is read, the previously read message is marked as processed successfully implicitly (by commiting the offset, which happened automatically relying on the default value of
enable.auto.commit=true
every 5 seconds, by default). After this change, you should make sure that you dont setenable.auto.commit
at all (it will be set tofalse
by this library) or setenable.auto.commit=false
explicitlyIf there was a crash or redeployment in between reading the message and the handler function finishing (especially a problem when the retry middleware is used, which can lead to very long execution times of the handler function), the messages would have been lost and wouldnt be reprocessed when the k8s pod comes back up.
Additionally, if there were thousands messages pushed to a topic, the consumer was reading all of them quickly after eachother, pushing each message processing onto a goroutine, essentially processing all messages in parallel. This causes problems on memory consumption and/or CPU etc.
This change will make the processing sequential. One consumer will read one message at a time. There will also be an explicit commit after the message handler is finished processing.
Now that each message is processed sequentially, there is no need for the
config.WithDeliveryOrder
method anymore as it will always be ordered. This got removed.This change will reduce the throughput of message processing if you dont modify your application source code, as one consumer will only process one message at a time. If you expect a high volume of message processing, you can change your service and start multiple consumers instead of by scaling to more k8s pods.
Extra stuff:
errFn