Skip to content
Veltoryx Technologies
ProLesson 10.2Intermediate6 min readUpdated 31 October 2026

Failure Modes, Idempotence, and Consistency: Interview Mastery

Master staff-level interview questions on delivery semantics, idempotent producer internals, transactional read-process-write loops, and the transactional outbox.

In distributed systems interviews, few topics generate as much scrutiny as data consistency, delivery guarantees, and failure recovery. Interviewers frequently challenge candidates who make imprecise claims such as "Kafka guarantees exactly-once processing across our entire platform."

A senior engineer must be able to dissect the mechanics of producer idempotence, explain what Kafka transactions can and cannot coordinate, and explain how to design resilient architectures across non-transactional boundaries.

Consistency Trade-offs
Fig. 1 · Consistency Trade-offs

01Deep-dive interview questions

What does "Exactly-Once Semantics" (EOS) in Kafka actually cover, and what does it NOT cover?

The interviewer is testing:

Whether the candidate understands system boundaries and the limitations of two-phase commit over heterogeneous distributed systems.

High-scoring response:

Exactly-Once Semantics (EOS) in Kafka is specifically scoped to Kafka-to-Kafka processing pipelines (the read-process-write loop), such as Kafka Streams applications reading from topic A, performing transformations, and writing results to topic B while committing consumer offsets atomically.

  1. What EOS covers:
    • Idempotent producer: Eliminates duplicate messages produced due to network retries between a single producer and a partition leader.
    • Atomic multi-partition writes: Guarantees that messages written across multiple output topics and consumer offsets written to __consumer_offsets either all commit together or all abort together.
    • Zombie fencing: Uses epoch numbers on transactional IDs to prevent "zombie" instances (split-brain consumers delayed by GC pauses) from committing phantom transactions.
  2. What EOS does NOT cover:
    • External side effects: If your consumer calls a third-party REST API (e.g., Stripe) or writes to a non-Kafka relational database, Kafka's transaction manager cannot roll back the HTTP request or external database mutation if the Kafka transaction aborts.
    • Producer-side crashes before commit: If the source application crashes before initiating commitTransaction(), the transaction aborts, requiring upstream replay.

To achieve true end-to-end exactly-once processing across external systems, you must combine Kafka with idempotent consumers (using unique deduplication keys) or the Transactional Outbox pattern.


How does the Kafka idempotent producer work internally, and why is max.in.flight.requests.per.connection <= 5 required?

The interviewer is testing:

Mechanical knowledge of PID assignment, monotonic sequence tracking on brokers, and in-flight request window validation.

High-scoring response:

The idempotent producer (enable.idempotence=true, default since Kafka 3.0) prevents duplicate records from being written to a partition when a network timeout occurs during an ACK:

  1. Producer ID (PID): During startup, the producer sends an InitProducerId request to the broker, which assigns a unique 64-bit Producer ID (PID).
  2. Sequence numbers: For every topic partition, the producer maintains a strictly monotonic sequence number starting at 0 for each message sent.
  3. Broker-side state cache: The leader broker maintains an in-memory cache of the last 5 sequence numbers accepted for every active PID on that partition.
  4. Duplicate detection:
    • If the incoming message has Sequence == ExpectedSequence: The broker appends the message to the log, advances the expected sequence number, and sends an ACK.
    • If Sequence < ExpectedSequence: The broker recognizes the message as a network retry of an already-committed record. It drops the duplicate payload and returns a successful ACK to the producer.
    • If Sequence > ExpectedSequence: The broker throws an OutOfOrderSequenceException because a gap occurred, indicating an earlier message was dropped.
  5. Why max.in.flight.requests.per.connection <= 5: Kafka maintains sequence history for only the last 5 in-flight batches per connection. If more than 5 batches are permitted in-flight, a failure in batch 1 followed by retries after batch 6 would exceed the broker's sequence tracking window, leading to unrecoverable sequence errors.

How does Kafka coordinate transactions in a read-process-write loop?

The interviewer is testing:

Knowledge of the Transaction Coordinator, the __transaction_state log, and two-phase commit marker records.

High-scoring response:

Kafka implements a specialized two-phase commit protocol managed by a Transaction Coordinator (a designated broker managing a partition of the internal __transaction_state topic):

text
Producer                     Transaction Coordinator                   Broker Partitions
   │                                    │                                      │
   ├─ 1. AddPartitionsToTxn ───────────>│                                      │
   │                                    ├─ 2. Write "Ongoing" to log           │
   ├─ 3. Produce records ─────────────────────────────────────────────────────>│ (Messages written to disk)
   ├─ 4. sendOffsetsToTxn ─────────────>│                                      │
   ├─ 5. commitTransaction() ──────────>│                                      │
   │                                    ├─ 6. Write "PrepareCommit" to log     │
   │                                    ├─ 7. Write COMMIT markers ───────────>│ (Appends COMMIT marker)
   │                                    ├─ 8. Write "Committed" to log         │
   │<─ 9. Transaction committed ────────┤                                      │
  1. Transaction state initialization: The producer registers its transactional.id with the coordinator, which writes an Ongoing state record to __transaction_state.
  2. Speculative writes: The producer sends records to output topic partitions. Brokers write these records to disk immediately, but they are flagged as uncommitted.
  3. Binding consumer offsets: The producer sends the incoming message's offset to the coordinator via sendOffsetsToTransaction(), binding the input offset commit to the active producer transaction.
  4. Commit phase: The coordinator appends a PrepareCommit record to __transaction_state and writes explicit control markers (COMMIT or ABORT) to every participating topic partition.
  5. Consumer isolation: Consumers running with isolation.level=read_committed buffer messages internally and only release records to the application when they read a COMMIT control marker. If an ABORT marker is read, the buffered records are discarded.

Why is the Transactional Outbox pattern preferred over distributed 2-Phase Commit (XA) across databases and Kafka?

The interviewer is testing:

Understanding of distributed consensus trade-offs, locking overhead, and microservice independence.

High-scoring response:

In microservices that must update a relational database AND publish an event to Kafka (e.g., creating an order and publishing an OrderCreated event), doing both operations independently creates a dual-write hazard: one operation can succeed while the other fails.

  1. The flaw of distributed XA transactions:
    • 2-Phase Commit (XA) requires all participating systems (PostgreSQL, Kafka) to support an external transaction coordinator.
    • XA holds long-running row and table locks across network boundaries while waiting for all nodes to vote.
    • If a network partition occurs between phases, database locks remain held indefinitely, causing cascading connection pool exhaustion and system-wide unavailability.
  2. The elegance of the Transactional Outbox pattern:
    • Instead of coordinating two independent systems, the application writes the business entity (e.g., the orders table) and the event payload into an outbox table within the same local database ACID transaction.
    • A dedicated CDC process (like Debezium) tails the database transaction log and streams outbox events to Kafka asynchronously.
    • Trade-off: Dual writes and distributed locks are eliminated entirely. The architecture provides guaranteed at-least-once delivery with zero cross-system locking, leaving deduplication to downstream idempotent consumers.

Loading the rest of the lesson…