Apache Kafka Architecture (Brokers, Topics, Partitions, Offsets, Zookeeper vs KRaft)
Understand Kafka’s log of partitioned topics, offsets, and the shift from ZooKeeper to KRaft.
In plain words
Choose partition for ordering and load. Next, leader writes and replicas acknowledge. Finally, offsets are metadata; records remain by policy.
Think of it like…
A topic is a building of parallel logbooks; each partition has one append order, broker replicas hold copies, and consumers use bookmarks rather than removing pages.
Where you’ve seen it
orders with 64 partitions and replication factor 3 uses tenant_id/order_id keys; one consumer group can process at most 64 active partitions, while acks=all waits for all current ISR replicas according to producer/broker policy.
Words you’ll hear
- Topics
- Named streams composed of one or more ordered partitions of records.
- Partitions
- The unit of ordering, replication, and parallel consumption; records with the same routing key should land together.
- KRaft
- Kafka's Raft-based internal controller/metadata quorum replacing an external ZooKeeper dependency in modern clusters.
- Operational boundary
- Ordering exists only within a partition, a low partition count caps consumer group parallelism, and insufficient replication or in-sync replicas lets a leader failure lose acknowledged writes or halt availability. Partition by a key with balanced business ordering needs, size partitions for throughput/parallelism, use replication factor and
min.insync.replicas, and operate KRaft metadata quorum observers/backups.
Visual diagram
Theory & deep dive
Topics: the working mechanism
Kafka stores records in ordered append-only partitions under topics; brokers replicate partitions, producers pick a leader-partition, consumers track offsets, and KRaft replaces external ZooKeeper with built-in Raft metadata quorums.
Choose partition for ordering and load. Leader writes and replicas acknowledge, then group assigns one partition to one member; this exposes the state governed by KRaft.
orders with 64 partitions and replication factor 3 uses tenant_id/order_id keys; one consumer group can process at most 64 active partitions, while acks=all waits for all current ISR replicas according to producer/broker policy.
Apache Kafka Architecture: failure mode and production response
Ordering exists only within a partition, a low partition count caps consumer group parallelism, and insufficient replication or in-sync replicas lets a leader failure lose acknowledged writes or halt availability.
Partition by a key with balanced business ordering needs, size partitions for throughput/parallelism, use replication factor and min.insync.replicas, and operate KRaft metadata quorum observers/backups. Track Ordering scope as "strictly per partition, not across topic partitions", and make Replication factor visible to the dataset owner.
min.insync.replicas, and operate KRaft metadata quorum observers/backups.How it works, step by step
Step 1 of 41. Produce key
Choose partition for ordering and load. Kafka stores records in ordered append-only partitions under topics; brokers replicate partitions, producers pick a leader-partition, consumers track offsets, and KRaft replaces external ZooKeeper with built-in Raft metadata quorums.
- Ordering scope
- strictly per partition, not across topic partitions
- Partitions
- The unit of ordering, replication, and parallel consumption; records with the same routing key should land together.
When to use it & trade-offs
What it is
Kafka stores records in ordered append-only partitions under topics; brokers replicate partitions, producers pick a leader-partition, consumers track offsets, and KRaft replaces external ZooKeeper with built-in Raft metadata quorums. orders with 64 partitions and replication factor 3 uses tenant_id/order_id keys; one consumer group can process at most 64 active partitions, while acks=all waits for all current ISR replicas according to producer/broker policy.
Why it matters: Ordering exists only within a partition, a low partition count caps consumer group parallelism, and insufficient replication or in-sync replicas lets a leader failure lose acknowledged writes or halt availability. Partition by a key with balanced business ordering needs, size partitions for throughput/parallelism, use replication factor and min.insync.replicas, and operate KRaft metadata quorum observers/backups.
When to reach for it
- Understand Kafka’s log of partitioned topics, offsets, and the shift from ZooKeeper to KRaft.
- Choose Topics because it provides this capability: Named streams composed of one or more ordered partitions of records.
- Keep evidence for Ordering scope at "strictly per partition, not across topic partitions" so the last production stage-Commit/retain - offsets are metadata; records remain by policy-remains testable.
When to avoid or be careful
- Ordering exists only within a partition, a low partition count caps consumer group parallelism, and insufficient replication or in-sync replicas lets a leader failure lose acknowledged writes or halt availability.
- Do not conflate Partitions with Topics. The second concept contributes different behavior: The unit of ordering, replication, and parallel consumption; records with the same routing key should land together.
- Release only after this guardrail is in place: Partition by a key with balanced business ordering needs, size partitions for throughput/parallelism, use replication factor and
min.insync.replicas, and operate KRaft metadata quorum observers/backups.
Topics / Partitions / KRaft - roles, limits, and operating cost
Strengths: Named streams composed of one or more ordered partitions of records. Kafka stores records in ordered append-only partitions under topics.
Watch out: Ordering exists only within a partition, a low partition count caps consumer group parallelism, and insufficient replication or in-sync replicas lets a leader failure lose acknowledged writes or halt availability.
Strengths: The unit of ordering, replication, and parallel consumption; records with the same routing key should land together. In this workflow it supports: Consume - group assigns one partition to one member.
Watch out: The operating cost is real: copies of each partition across failure domains.
Strengths: Kafka's Raft-based internal controller/metadata quorum replacing an external ZooKeeper dependency in modern clusters. Its output can be checked with ISR.
Watch out: Operating guardrail: Partition by a key with balanced business ordering needs, size partitions for throughput/parallelism, use replication factor and min.insync.replicas, and operate KRaft metadata quorum observers/backups.
Interview signals & numbers to know
When this topic comes up
- “Where is the failure boundary for Topics, and how would Ordering scope reveal it?”
- “Why is Partitions distinct from this behavior: Kafka's Raft-based internal controller/metadata quorum replacing an external ZooKeeper dependency in modern clusters?”
- Production clue: Ordering exists only within a partition, a low partition count caps consumer group parallelism, and insufficient replication or in-sync replicas lets a leader failure lose acknowledged writes or halt availability.
- Design probe: Partition by a key with balanced business ordering needs, size partitions for throughput/parallelism, use replication factor and min.insync.replicas, and operate KRaft metadata quorum observers/backups.
Benchmarks & rules of thumb
- Ordering scope
- strictly per partition, not across topic partitions
- Replication factor
- copies of each partition across failure domains
- ISR
- replicas currently eligible to acknowledge and serve leader safety
Common mistakes & follow-ups
Common interview mistakes
- Ordering exists only within a partition, a low partition count caps consumer group parallelism, and insufficient replication or in-sync replicas lets a leader failure lose acknowledged writes or halt availability.
- Reporting success from a job exit code without checking Ordering scope and Replication factor.
- Treating this example as complete without replay, rollback, or access boundaries:
orderswith 64 partitions and replication factor 3 usestenant_id/order_idkeys; one consumer group can process at most 64 active partitions, whileacks=allwaits for all current ISR replicas according to producer/broker policy.
Likely interviewer follow-ups
- How would you prove this contract instead of only checking that the command ran: Named streams composed of one or more ordered partitions of records.
- What does the recovery plan do when this occurs? Ordering exists only within a partition, a low partition count caps consumer group parallelism, and insufficient replication or in-sync replicas lets a leader failure lose acknowledged writes or halt availability.
- When is Topics insufficient for Replication factor, and what does adding Partitions cost in Ordering scope?
min.insync.replicas, and operate KRaft metadata quorum observers/backups.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Apache Kafka Architecture (Brokers, Topics, Partitions, Offsets, Zookeeper vs KRaft) with data engineer interview Q&A and hands-on practice.