KatInterview

Kafka Ordering, Durability, and Exactly-Once Processing

System DesignModel answer
HardModel answerSystem Designkafkamessagingdelivery-semantics

Last updated

Describe how Kafka's partitioned, replicated log and consumer groups shape ordering, scale, and resilience, and how to get effectively-once results from a pipeline.

You are reviewing the messaging layer of a platform in which a stream of order events flows through Apache Kafka into a downstream service that updates account balances.

Answer the following in a structured way:

  1. Describe how topics, partitions, replicas, and consumer groups work in Kafka.
  2. Explain how these mechanisms influence message ordering, horizontal scalability, and fault tolerance.
  3. Contrast at-most-once, at-least-once, and exactly-once delivery. State what failure each one tolerates and what it costs.
  4. Lay out how you would build a pipeline that produces exactly-once effects end to end, including the part that writes to an external system outside Kafka.

State your assumptions (replication factor, partition count, key choice) and point out where the guarantees stop.

Hints

Hint 1

Start from the smallest unit: a partition is an ordered log with offsets. Ask what that implies for ordering, and for how many consumers in one group can be busy at once.

Hint 2

For fault tolerance, think about leader and followers, the in-sync replica set, and how the producer ack level combined with a minimum in-sync replica count decides whether an acknowledged write can be lost.

Hint 3

Delivery semantics depend on the order of 'do the work' and 'record progress'. Kafka transactions cover work that stays inside Kafka; for an external database you need the write to be safe to repeat, or to commit the offset in the same atomic step as the data.