Apache Kafka is a distributed streaming platform used for building real-time data pipelines and streaming applications.

The Internal Architecture of Kafka

  • Producer: Sends records to Kafka topics.
  • Consumer: Reads records from Kafka topics.
  • Broker: Individual Kafka server, holding data and serving clients.
  • ZooKeeper: Manages brokers and maintains metadata.

Understanding Kafka Brokers and Clusters

  • Broker: Stores data and serves clients.
  • Cluster: A set of Kafka brokers.

Brokers store topic partitions and serve producers and consumers. Multiple brokers form a cluster, managed by ZooKeeper.

How Topics and Partitions Work

  • Topic: Logical channel to which records are sent by producers.
  • Partition: Physical subdivision of a topic.

A topic is divided into partitions for parallelism and distributed storage.

Replica Management in Kafka

  • Leader Replica: Handles reads and writes for a partition.
  • Follower Replica: Mirrors the data and can take over if the leader fails.

Replicas ensure data availability and resilience.

Data Flow and Message Routing in Kafka

  • Producer API: Sends records to the broker.
  • Consumer API: Fetches records from the broker.

Records are produced to topics, stored in partitions, and consumed from partitions.

Load Balancing and Data Distribution in Kafka

  • Partitioning: Distributes data across multiple brokers.

Producers use algorithms like round-robin or hash-based partitioning to distribute records.

Understanding Leader and Follower Roles

  • Leader: Serves client requests.
  • Follower: Mirrors the leader and can become leader if needed.

Leaders are elected by ZooKeeper.

Zookeeper’s Role in Kafka Architecture

  • Manages broker metadata.
  • Handles broker failure and recovery.
  • Manages leader elections.

Extended Practice Questions for CCKAD

  1. What is a Kafka broker?
  2. How is a topic different from a partition?
  3. What role does ZooKeeper play in Kafka?
  4. Explain the difference between leader and follower replicas.
  5. How does Kafka handle load balancing?
  6. Describe the data flow in Kafka.
  7. What algorithms can be used for partitioning in Kafka?
  8. How are consumer offsets managed?
  9. What happens when a broker fails?
  10. What are the core APIs in Kafka?
  11. How does Kafka ensure data durability?
  12. What are consumer groups and how do they work?
  13. How do producers decide which partition to send a message to?
  14. What is the role of a Kafka “Producer Record”?
  15. Describe the process of a leader election in a Kafka cluster.
  16. How is data ordered in Kafka partitions?
  17. What is “Log Compaction” in Kafka?
  18. How are read and write operations optimized in Kafka?
  19. What is a “Topic Log” in Kafka?
  20. Explain how Kafka enables fault-tolerance.
  21. What is the significance of the acks configuration in Kafka producers?
  22. How can you secure Kafka brokers?
  23. What is “Exactly Once Semantics” in Kafka?
  24. How does Kafka handle schema evolution?
  25. How can you monitor the health and performance of a Kafka cluster?


  1. A Kafka broker is an individual Kafka server that stores data and serves clients.
  2. A topic is a logical channel for storing records, whereas a partition is a physical subdivision of a topic.
  3. ZooKeeper manages the Kafka brokers and maintains the metadata.
  4. The leader replica handles client requests, while the follower replica mirrors the leader.
  5. Kafka uses partitioning to distribute data across multiple brokers.
  6. Producers send records to topics, which are stored in partitions. Consumers read from these partitions.
  7. Round-robin and hash-based partitioning.
  8. Consumer offsets are pointers that track the last read position in a partition.
  9. ZooKeeper detects the failure and initiates a leader re-election for partitions that the failed broker led.
  10. Producer API, Consumer API, Streams API, and Admin API.
  11. Through replication.
  12. Consumer groups allow multiple consumers to share the load of reading messages from topics.
  13. Producers use partitioning algorithms like round-robin or hash-based partitioning.
  14. A Producer Record contains the topic and partition information along with the key-value payload.
  15. ZooKeeper initiates leader election when a broker fails or a new broker is added.
  16. Data is ordered by the offset, a sequential ID, within each partition.
  17. Log compaction retains the latest update for each record key within a partition.
  18. Kafka optimizes read and write operations through sequential disk I/O.
  19. A Topic Log is the physical storage layer in a broker where messages for a particular topic partition are stored.
  20. Through data replication and leader elections.
  21. The acks configuration specifies the number of acknowledgments the producer requires the broker to receive before considering a request complete.
  22. Through SSL/TLS, SASL, and ACLs.
  23. “Exactly Once Semantics” ensure that records are neither lost nor seen more than once.
  24. Kafka handles schema evolution through schema registry services like Confluent’s Schema Registry.
  25. You can use monitoring tools like JMX, Grafana, or built-in Kafka tools to monitor cluster health and performance.