Interview's MateData Engineer
Interview's Mate

Data Engineer

SQL · Spark · Lakehouse · Streaming

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Engineer topics
Lesson 123/ 160
07. Streaming & Real-Time Data Engineering

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.

IntermediateTopics · Partitions · KRaft3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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

Loading interactive 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.

Apache Kafka Architecture in one concrete design

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.

Key takeaway: Kafka stores records in ordered append-only partitions under topics

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.

Key takeaway: 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.

How it works, step by step

Step 1 of 4
Topics

1. 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.

choose partition for ordering and load
Key numbers at this step
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

Topics
Best for: Named streams composed of one or more ordered partitions of records.

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.

Partitions
Best for: The unit of ordering, replication, and parallel consumption; records with the same routing key should land together.

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.

KRaft
Best for: Kafka's Raft-based internal controller/metadata quorum replacing an external ZooKeeper dependency in modern clusters.

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: 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.

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?
Interview tip: Lead with the data path and failure boundary: 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. Then make the answer operational: 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.

Knowledge check

Loading quiz

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.

Open Data Engineer Q&A →Machine Learning Q&A
Previous topic
Event-Driven Architecture & Message Brokers Overview
Next topic
Kafka Producers (Acknowledgments acks, Batching, Compression, Partitioners)