Nâng CaoKafka iconKafka

Exactly-once semantics (EOS) trong Kafka hoạt động như thế nào? Giải thích idempotent producers và transactions.

Kafka hỗ trợ 3 delivery semantics: at-most-once (có thể mất message), at-least-once (có thể duplicate), và exactly-once. Idempotent producer (enable.idempotence=true) đảm bảo mỗi message chỉ được ghi đúng một lần vào một partition kể cả khi retry — producer được gán PID và mỗi message có sequence number, broker reject duplicate. Kafka Transactions cho phép atomic write across multiple partitions/topics: producer dùng initTransactions(), beginTransaction(), write messages, commitTransaction() hoặc abortTransaction(). Consumer dùng isolation.level=read_committed để chỉ đọc message từ committed transaction. EOS trong Kafka Streams được bật bằng processing.guarantee=exactly_once_v2.

Lưu ý: EOS có overhead về latency và throughput (~20-30%), chỉ dùng khi thực sự cần thiết (tài chính, billing).

Xem toàn bộ Kafka cùng filter theo level & chủ đề con.

Mở danh sách Kafka