This logic and the strong ordering of transactions ensures that the count in the database will be accurate even if tuples are replayed. Credit for this trick of storing a transaction id in the database along with the value goes to the Kafka devs, particularly this design document.
У меня бімба от подобных параграфов. Чуваки предложили ввести переменную "current_id" и сравнивать её со значением id и что-то делать в зависимости. Описывается это как "design document", "credit for this trick" etc.