Thank you Romain Gilles for your question.
Basically you can use the stored offsets from the Kafka transaction to make sure you only update your DB state once. In his post on Exactly-once Support in Apache Kafka, Confluent CEO Jay Kreps offers two ways to implement this:
1. Store the offsets in the same DB as the derived state and update both in a transaction. When restarting, read your current offset from the DB and start reading from there.
2. Write both state updates and offsets together in a way that is idempotent. For example if your derived state was a key and counter tracking the number of occurrences, store the offset along with the count and ignore any update with an offset <= the current stored value.