A Kafka broker compares the PID (producer ID) and a message sequence number (generated by the producer) to deduplicate messages for idempotent producers. Once a transactional producer retains the PID upon restarts, does the transactional producer guarantee deduplication upon restarts? From where does the transactional producer receive the last sequence number after restart?
Example: A producer with a PID of "1" and a transactional ID of "producer-1" sends messages with sequence numbers "1" and then "2". After the producer crashes and restarts, the broker sees that the new producer has the transactional ID of "producer-1" and assigns it a PID of "1." How does the producer know that the last sequence number is "2"?
Finally I've found a solution. A broker resets sequence number when producer's epoch bumps (when a new producer appears with the same PID).