I am not familiar with Apache-Beam but I believe the issue might be related to Kafka not committing the offsets in time. After writing data to the database, the offsets may not be committed immediately. Kafka waits until all messages in the batch (by default 500 messages due to the max.poll.records setting) are processed. This could lead to reprocessing if the system fails or restarts before the offsets are committed.
To reduce the number of duplicates processed in case of failure, you can:
For more information, you can refer to this article which explains it nicely Offset Management