Chaturmind
LearnDSASystem DesignInterview PrepDevOpsEngineering GrowthBlog
Start learning
Chaturmind

Structured learning paths for engineers who want to go deep. Written by practitioners.

Learn

  • Java
  • DSA
  • System Design
  • Spring Boot
  • AI / ML
  • DevOps
  • Engineering Growth
  • Java Interview Prep

Company

  • Blog
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

© 2026 Chaturmind. All rights reserved.

Built for engineers who want to go deep.


← Java Interview Prep: 2–5 Years

Revise the Fresher Tier

  • Revise: Core Java Fundamentals (Fresher Tier)
  • Revise: Collections, Threads, Java 8 & Coding (Fresher Tier)
  • Revise: Spring Core, Spring Boot & Spring MVC (Fresher Tier)
  • Revise: Hibernate, SQL, Microservices, Maven & Git (Fresher Tier)

Intermediate Core Java

  • Intermediate OOP & Language Features — Interview Questions
  • Enums, Generics, Pass-by-Value & Imports — Interview Questions
  • Collections Internals & Scenarios — Interview Questions
  • JVM, Memory & Class Loading — Interview Questions
  • Exception Design & Serialization Edge Cases — Interview Questions

Java 8 Deep Dive & Stream Coding

  • Lambdas, Functional Interfaces & Method References — Interview Questions
  • Default Methods, Backward Compatibility & Optional — Interview Questions
  • Stream API Internals (Part 1) — Interview Questions
  • Stream API Internals (Part 2) — Interview Questions
  • Stream Coding Problems (Level 2, Part 1) — Interview Questions
  • Stream Coding Problems (Level 2, Part 2) — Interview Questions

Concurrency & Multithreading

  • Synchronization, Locks & Deadlocks — Interview Questions
  • Executors, ThreadLocal & Concurrent Collections — Interview Questions

Spring Framework In Depth

  • Bean Lifecycle, Contexts & Circular Dependencies — Interview Questions
  • Spring Bean Conflicts, AOP, Batch & Injection Styles — Interview Questions

Spring Boot In Depth & Scenarios

  • Spring Boot Internals & Auto-Configuration — Interview Questions
  • Spring Boot Configuration, Profiles & Secrets — Interview Questions
  • Spring Boot Data, Transactions & Caching — Interview Questions
  • Spring Boot Testing, Error Pages & Deployment — Interview Questions
  • Spring Boot Performance, Scaling & Resilience — Interview Questions
  • Spring Boot Async, Events & Messaging — Interview Questions
  • Spring Boot Security Scenarios — Interview Questions
  • Actuator, AOP, Spring Cloud & Distributed Tracing — Interview Questions
  • External APIs, Files, GraphQL & WebFlux — Interview Questions

Spring Security

  • Spring Security — OAuth2, CORS, CSRF & Access Rules — Interview Questions
  • Spring Security — Passwords, Filter Chain, Sessions & Debugging — Interview Questions

Apache Kafka

  • Kafka Architecture, Topics & ZooKeeper vs KRaft — Interview Questions
  • Kafka Producers, Consumers, Reliability & Streams — Interview Questions
  • Kafka Security, Connect & Core Scenarios — Interview Questions
  • Kafka Production Scenarios — Interview Questions

Git, Maven & Gradle (Level II)

  • Git Workflows, Rebase & Conflict Handling — Interview Questions
  • Git Recovery, Hooks, Tags & Collaboration — Interview Questions
  • Maven Builds, Multi-Module Projects & Dependency Resolution — Interview Questions
  • Maven Profiles, settings.xml, Plugins & Quality Gates — Interview Questions
  • Gradle Fundamentals, Migration & Dependencies — Interview Questions
  • Gradle Performance, Plugins, Testing & Publishing — Interview Questions

Deployment & CI/CD

  • Sessions, CI/CD Pipelines, Rollbacks & Secrets — Interview Questions
  • Migrations, Zero-Downtime Releases, Containers & Monitoring — Interview Questions

JUnit 5 & Mockito

  • JUnit 5 — Interview Questions
  • Mockito Basics — Interview Questions
  • Mockito Advanced & Tricky Questions — Interview Questions
Chaturmind
← Java Interview Prep: 2–5 Years

Revise the Fresher Tier

  • Revise: Core Java Fundamentals (Fresher Tier)
  • Revise: Collections, Threads, Java 8 & Coding (Fresher Tier)
  • Revise: Spring Core, Spring Boot & Spring MVC (Fresher Tier)
  • Revise: Hibernate, SQL, Microservices, Maven & Git (Fresher Tier)

Intermediate Core Java

  • Intermediate OOP & Language Features — Interview Questions
  • Enums, Generics, Pass-by-Value & Imports — Interview Questions
  • Collections Internals & Scenarios — Interview Questions
  • JVM, Memory & Class Loading — Interview Questions
  • Exception Design & Serialization Edge Cases — Interview Questions

Java 8 Deep Dive & Stream Coding

  • Lambdas, Functional Interfaces & Method References — Interview Questions
  • Default Methods, Backward Compatibility & Optional — Interview Questions
  • Stream API Internals (Part 1) — Interview Questions
  • Stream API Internals (Part 2) — Interview Questions
  • Stream Coding Problems (Level 2, Part 1) — Interview Questions
  • Stream Coding Problems (Level 2, Part 2) — Interview Questions

Concurrency & Multithreading

  • Synchronization, Locks & Deadlocks — Interview Questions
  • Executors, ThreadLocal & Concurrent Collections — Interview Questions

Spring Framework In Depth

  • Bean Lifecycle, Contexts & Circular Dependencies — Interview Questions
  • Spring Bean Conflicts, AOP, Batch & Injection Styles — Interview Questions

Spring Boot In Depth & Scenarios

  • Spring Boot Internals & Auto-Configuration — Interview Questions
  • Spring Boot Configuration, Profiles & Secrets — Interview Questions
  • Spring Boot Data, Transactions & Caching — Interview Questions
  • Spring Boot Testing, Error Pages & Deployment — Interview Questions
  • Spring Boot Performance, Scaling & Resilience — Interview Questions
  • Spring Boot Async, Events & Messaging — Interview Questions
  • Spring Boot Security Scenarios — Interview Questions
  • Actuator, AOP, Spring Cloud & Distributed Tracing — Interview Questions
  • External APIs, Files, GraphQL & WebFlux — Interview Questions

Spring Security

  • Spring Security — OAuth2, CORS, CSRF & Access Rules — Interview Questions
  • Spring Security — Passwords, Filter Chain, Sessions & Debugging — Interview Questions

Apache Kafka

  • Kafka Architecture, Topics & ZooKeeper vs KRaft — Interview Questions
  • Kafka Producers, Consumers, Reliability & Streams — Interview Questions
  • Kafka Security, Connect & Core Scenarios — Interview Questions
  • Kafka Production Scenarios — Interview Questions

Git, Maven & Gradle (Level II)

  • Git Workflows, Rebase & Conflict Handling — Interview Questions
  • Git Recovery, Hooks, Tags & Collaboration — Interview Questions
  • Maven Builds, Multi-Module Projects & Dependency Resolution — Interview Questions
  • Maven Profiles, settings.xml, Plugins & Quality Gates — Interview Questions
  • Gradle Fundamentals, Migration & Dependencies — Interview Questions
  • Gradle Performance, Plugins, Testing & Publishing — Interview Questions

Deployment & CI/CD

  • Sessions, CI/CD Pipelines, Rollbacks & Secrets — Interview Questions
  • Migrations, Zero-Downtime Releases, Containers & Monitoring — Interview Questions

JUnit 5 & Mockito

  • JUnit 5 — Interview Questions
  • Mockito Basics — Interview Questions
  • Mockito Advanced & Tricky Questions — Interview Questions
HomeLearnJava Interview PrepJava Interview Prep: 2–5 YearsApache Kafka
✓ FreeIntermediate· 8 min read

Kafka Architecture, Topics & ZooKeeper vs KRaft — Interview Questions

What Kafka is and when to use it, how it differs from traditional brokers, its architecture, topics and partitions, creating topics, replication and ISR, ZooKeeper's historical role, what happens when it fails — and KRaft, which replaced ZooKeeper entirely in Kafka 4.0.

Published September 25, 2026


How to use this lesson

Kafka questions often come from material written before Kafka 4.0 (2025) removed ZooKeeper. Answer the ZooKeeper questions correctly for older clusters, then add that KRaft is how Kafka works now. That single update marks you as current.

Q1. What is Apache Kafka?

Short answer: Kafka is a distributed, partitioned, replicated commit log, used as an event-streaming platform. Producers append records to topics. Kafka stores them durably, for a configurable retention period, whether or not anyone has consumed them. Consumers read at their own pace by tracking offsets. It delivers very high throughput through sequential disk I/O, batching, zero-copy transfer and partitioning.

Learn it in depth → Messaging Technology Choices

Q2. What are Kafka's common use cases?

Short answer:

  • Event-driven microservices: order placed → inventory, billing, notifications.
  • Change data capture: database changes streamed through Debezium.
  • Log and metrics aggregation, and activity tracking (clicks, views).
  • Real-time stream processing: fraud detection, alerting, live dashboards, with Kafka Streams or Flink.
  • Data integration into lakes and warehouses through Kafka Connect.
  • Event sourcing and audit trails, thanks to replay.
  • Buffering between fast producers and slow consumers.

Q3. How does Kafka differ from traditional messaging systems?

Short answer:

Traditional broker (RabbitMQ, ActiveMQ)Kafka
ModelQueue: messages are deleted once acknowledgedLog: records are retained (by time or size), and consumers track offsets
ReplayGenerally notYes: rewind the offsets and reprocess
Many independent consumersNeeds fan-out exchanges or copiesFree: each consumer group reads the same log
OrderingPer queuePer partition
ThroughputHighVery high (millions of messages per second across a cluster)
RoutingRich (exchanges, patterns, priorities)Simple: topic plus key → partition
Push/pullMostly pushConsumers pull

Key points to cover:

  • RabbitMQ still wins for complex routing, per-message priorities and request/reply task queues. Kafka wins for high-volume event streams, replay and stream processing.

Q4. What components make up the Kafka architecture?

Short answer:

  • Brokers: servers that store partitions and serve clients. A cluster is a set of brokers.
  • Topics, split into partitions, which are replicated across brokers. Each partition has one leader and some followers.
  • Producers write, and consumers (grouped into consumer groups) read.
  • The controller: manages cluster metadata, partition leadership and broker membership. Historically this was coordinated through ZooKeeper. Now it's the KRaft controller quorum.
  • Ecosystem: Kafka Connect (integration), Kafka Streams (processing), Schema Registry (Confluent or Apicurio).

Q5. What is a Kafka topic?

Short answer: A topic is a named, append-only stream of records for one kind of event (orders.placed). It's split into partitions for parallelism, and each partition is an ordered log in which each record has an offset. Records are retained according to a policy: time or size (retention.ms, retention.bytes), or compaction (keep the latest value per key).

Q6. How do you create a topic?

Short answer: Use the CLI, the Admin API, or declarative infrastructure-as-code:

kafka-topics.sh --bootstrap-server broker:9092 --create --topic orders.placed \
  --partitions 12 --replication-factor 3 --config min.insync.replicas=2 --config retention.ms=604800000
@Bean
NewTopic ordersPlaced() {                         // Spring Kafka's KafkaAdmin creates it at startup if missing
    return TopicBuilder.name("orders.placed").partitions(12).replicas(3)
            .config(TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG, "2").build();
}

Key points to cover:

  • In production, disable auto-creation (auto.create.topics.enable=false), and manage topics through GitOps or Terraform.
  • The replication factor on a real cluster is usually 3. The replication factor of 1 in many examples means no fault tolerance.

Q7. How are topics partitioned, and why does it matter?

Short answer: A topic's partitions are spread across brokers. A producer chooses a partition by:

  • hashing the record key, so the same key always goes to the same partition;
  • sticky batching, when there's no key;
  • a custom partitioner.

Partitions matter because they are:

  • The unit of parallelism: a consumer group can have at most one active consumer per partition.
  • The unit of ordering: order is guaranteed only within a partition, so key by the entity whose events must stay ordered (for example orderId).
  • The unit of scaling and placement: load is spread across brokers.

Key points to cover:

  • Choose the partition count with headroom. Adding partitions later changes key→partition mapping, which breaks per-key ordering for existing keys.
  • Beware of hot partitions from skewed keys.

Q8. What happens when a topic is replicated?

Short answer: Each partition has replication-factor copies on different brokers:

  • The leader handles all writes, and by default all reads.
  • Followers fetch from the leader to stay in sync.
  • Replicas that are caught up form the ISR (in-sync replica set).
  • If the leader fails, a new leader is elected from the ISR, so no acknowledged data is lost when acks=all and min.insync.replicas are configured properly.

Key points to cover:

  • Replication is for fault tolerance, not read scaling. Consumers read from leaders, unless follower fetching (rack-aware, KIP-392) is enabled to reduce cross-AZ traffic.
  • Rack or AZ awareness (broker.rack) spreads replicas across failure domains.

Q9. What was ZooKeeper's role in Kafka?

Short answer: In older Kafka (before KRaft), ZooKeeper stored the cluster metadata:

  • broker registration and liveness;
  • topic and partition configuration;
  • ACLs and quotas.

It also helped elect the controller broker, which in turn managed partition leadership, and told brokers about metadata changes.

Key points to cover:

  • KRaft (Kafka Raft) moves metadata into Kafka itself: a replicated metadata log, managed by a quorum of controller nodes. It was production-ready from 3.3, and it's the only mode in Kafka 4.0. ZooKeeper has been removed.

Q10. Why was ZooKeeper critical for Kafka (and why did Kafka remove it)?

Short answer: In ZooKeeper-based clusters, it was the source of truth for metadata, and the anchor for controller election. Without it, the cluster couldn't change leadership or configuration safely. That centrality was also its weakness: a second distributed system to deploy, secure and tune, slow controller failover on large clusters (metadata had to be reloaded), and a practical limit on partition count. KRaft removed those problems. Controller failover is fast, the cluster scales to millions of partitions, and there's one system to operate.

Q11. What would happen if ZooKeeper failed?

Short answer (ZooKeeper-based clusters):

  • Existing leaders keep serving produce and consume requests for their partitions, so the data path mostly continues.
  • The control plane freezes:
    • no controller election;
    • no leader changes when a broker fails (partitions whose leader dies stay unavailable);
    • no topic creation or configuration changes;
    • no new brokers joining;
    • no ACL updates.
  • Long outages leave the cluster increasingly fragile.

Key points to cover:

  • That's why ZooKeeper ran as a 3- or 5-node ensemble, tolerating the loss of a minority of nodes.

Q12. How does Kafka handle ZooKeeper outages, and what's the modern answer?

Short answer: In older clusters: brokers keep their cached metadata and continue serving, while metadata operations are blocked until a ZooKeeper quorum returns. When it does, the controller reconciles the state. Operators minimise the risk with an odd-sized ensemble across AZs, dedicated disks and monitoring.

The modern answer is KRaft. There's no ZooKeeper to lose. Metadata is replicated among 3 or 5 KRaft controllers using Raft, and losing a minority of controllers doesn't stop the control plane.

Follow-up questions this topic invites — and their answers

Q: How do you migrate from ZooKeeper to KRaft? A: Kafka 3.x provides a migration mode. You stand up KRaft controllers, migrate the metadata while brokers run in dual-write mode, roll the brokers into KRaft mode, then finalise and decommission ZooKeeper. You have to be on a bridge 3.x release before upgrading to 4.0.

Q: What's the ISR, and what is min.insync.replicas? A: The ISR is the set of replicas fully caught up with the leader. min.insync.replicas (commonly 2, with a replication factor of 3) is the minimum ISR size required for an acks=all write to succeed. That guarantees every acknowledged write exists on at least two brokers.

Q: How many partitions should a topic have? A: Enough for the peak consumer parallelism you need (target throughput ÷ per-consumer throughput), plus headroom, and not thousands without reason. More partitions mean more open files, more metadata, and longer rebalances.

Q: What is log compaction? A: A retention mode that keeps at least the latest record per key, and removes older ones. It suits changelog or state topics, such as current customer profiles, and it's what Kafka Streams uses for its state stores.

Previous

Spring Security — Passwords, Filter Chain, Sessions & Debugging — Interview Questions

Next

Kafka Producers, Consumers, Reliability & Streams — Interview Questions

AI Tutor

Lesson: Kafka Architecture, Topics & ZooKeeper vs KRaft — Interview Questions

Quick actions

AI responses can be inaccurate. Verify critical information.