In case of manual commit offset in Kafka, what happens when there is a failure? Example -> Lets assume offset 0 is committed, offset 1 is not committed and then offset 2 is committed. Is the message at offset 1 retried?
It depends on how you commit:
On commitSync
assuming you commit each offset separately like in your example, if offset 1 is not committed it will retry to commit that offset until it succeeds or until it encounters nonRetryable failure.
One drawback of that mechanism is that the application is blocked until the broker responds and therefor limit the application throughput.
On commitAsync
on the other hand, there is no retry in case it failed to commit offset 1. The reason for that is that by the time the broker responds get back to your Kafka client there may be later commit that was already successful.
Imagine on your example that commit of message with offset 1 was failed due to temporary network issue. Meanwhile the application already processed successfully message with offset 2. If we now retry previous failed commit it might succeed to commit offset 1 after 2 was already committed. In a case of rebalance, this will cause more duplicated.