Kafka & Messaging
Apache Kafka, RabbitMQ β event streaming, consumer lag, production operations
Category: Messaging & Event Systems
Learning Path: What β Why β Learning Modules β Production Example β Interview Prep
Before you start: basic Kubernetes and Linux/CLI comfort are assumed, since Kafka is run and operated on Kubernetes throughout this course. No prior messaging-system experience is needed.
What is Kafka & Messaging?
Kafka is a distributed event streaming platform β instead of one service calling another directly, services publish events to Kafka and other services read them independently. A topic (a named stream of events, e.g. orders) is divided into partitions β the unit of parallelism, since each partition can be read independently. Each partition is an ordered, immutable log. Consumers track their position with an offset (their place in that log). A consumer group lets multiple consumers split the work of reading a topic in parallel β each partition is assigned to exactly one consumer within the group at a time, which is why the rule is consumer instances β€ partition count (extra consumers beyond the partition count sit idle, with nothing assigned to them). Replication factor is the number of copies of each partition kept across brokers (3 is standard for production, so the cluster survives a broker failure).
Why Kafka & Messaging?
Consumer lag is the number of messages waiting to be processed β the gap between the log-end-offset (the newest message written) and the consumer's current offset, per partition. Growing lag means consumers can't keep up with the producer rate. Lag growing on all partitions means the consumer group is simply too slow overall (the fix is to scale up, up to the partition count). Lag stuck on one partition specifically usually means a stuck consumer or a poison pill message β a malformed message the consumer keeps failing to process and retrying forever, blocking everything behind it on that partition.
Learning Modules
Module 01 β Kafka Architecture
Brokers, topics, partitions, consumer groups
Covered above: topics, partitions, offsets, and consumer groups. This module shows the actual CLI commands for creating topics and inspecting them.
Topics covered:
Module 02 β Consumer Lag β Most Common Issue
Diagnose and fix processing lag
Covered above: what consumer lag means and the all-partitions-vs-one-partition diagnosis split. This module shows the actual commands for checking and fixing it.
Topics covered:
Module 03 β Kafka in Kubernetes (Strimzi)
Operator-based Kafka on K8s
Strimzi is the CNCF Kafka Operator for Kubernetes β manages the entire Kafka cluster lifecycle (deploy, upgrade, scale, config changes). Instead of manually managing Kafka brokers, you define a Kafka custom resource and Strimzi handles everything. Used in production at a large telecom organisation for telecom SOM/COM event streaming.
Topics covered:
Module 04 β Kafka vs RabbitMQ
When to choose which
Kafka: high throughput, message retention (replay), consumer-controlled offsets, ordered per partition, for event streaming, audit logs, ML pipelines. RabbitMQ: moderate throughput, messages deleted after consume (no replay), push-based, complex routing (exchanges/queues), for task queues, RPC, microservice messaging. Kafka is NOT the right tool for simple job queues β RabbitMQ or SQS is simpler and more appropriate.
Topics covered:
Production Example
Interview Prep
PSR Formula: Answer every question: Problem β Solution β Result. 45-90 seconds max.
Common Interview Questions
Q1. What is Kafka & Messaging and why would you use it in production?
A: Kafka is a distributed event-streaming platform: instead of services calling each other directly, they publish events to Kafka topics and other services consume them independently, at their own pace. You'd reach for it when you need high throughput, the ability to replay past events (debugging, reprocessing, backfilling a new consumer), or multiple independent consumers reading the same event stream. It's not the right tool for a simple one-off task queue β RabbitMQ or SQS is simpler and more appropriate there.
Q2. How does Kafka & Messaging work internally? Explain the architecture.
A: A topic is split into partitions, each an ordered, append-only log. Producers write to a partition (often by a key, so related events land on the same partition and stay ordered relative to each other). Each partition is replicated across brokers (typically 3x) for durability. Consumers in a consumer group split the partitions among themselves β each partition assigned to exactly one consumer in the group at a time β and each consumer tracks its own offset (position in the log) so it can resume correctly after a restart.
Q3. What are the main components of Kafka & Messaging?
A: Brokers (the servers storing partition data), topics and partitions (the data model), producers (write events), consumers and consumer groups (read events, in parallel across partitions), and β for Kubernetes deployments β the Strimzi Operator, which manages the entire cluster lifecycle (deploy, upgrade, scale) via a Kafka custom resource instead of managing brokers by hand.
Q4. How do you handle failures in Kafka & Messaging?
A: For broker failures, replication (factor 3 in production) means other replicas keep serving the partition. For consumer failures, the diagnosis splits in two: lag growing on every partition means the consumer group as a whole is too slow, so scale up (add consumer instances, up to the partition count). Lag stuck on one specific partition usually means a poison pill message β a malformed message the consumer keeps failing on β which requires finding that message and either fixing the consumer's handling of it or manually advancing past the stuck offset.
Q5. What is your production experience with Kafka & Messaging?
A: (Needs verification β this platform can't fabricate a first-person production story. Answer from your own experience: what topics/partition counts you ran, what a real consumer-lag incident looked like, and how Strimzi or your own operational setup handled it.)
Q6. How do you monitor and observe Kafka & Messaging in production?
A: The most important signal is consumer lag per consumer group and partition (kafka-consumer-groups.sh --describe, or the kafka_consumergroup_lag_sum metric in Prometheus, alerted on when it crosses a threshold sustained for several minutes). Also watch for under-replicated partitions (kafka-topics.sh --under-replicated-partitions β a sign a broker is down or falling behind, meaning data is at reduced durability) and broker health via kafka-broker-api-versions.sh.
Q7. What are the security considerations for Kafka & Messaging?
A: Enable TLS for both broker-to-broker and client-to-broker traffic (the example Strimzi config shows both a plaintext internal listener and a TLS listener β production should favor TLS). Use SASL or mTLS for client authentication rather than trusting network-level access alone. And apply topic-level ACLs so a compromised producer credential can't read or write topics it has no business touching.
Q8. How does Kafka & Messaging compare to alternatives?
A: Kafka vs. RabbitMQ is the main comparison: Kafka retains messages for replay, is pull-based (consumers control their own offset and pace), and handles very high throughput β suited to event streaming, audit logs, and ML pipelines. RabbitMQ deletes messages once consumed (no replay), is push-based, and supports complex routing (exchanges, queues) β suited to task queues, RPC, and simpler microservice messaging. Choosing Kafka for a simple job queue is over-engineering; choosing RabbitMQ when you need replay or extreme throughput under-delivers.
Q9. Explain Kafka Architecture in Kafka & Messaging.
A: Topics are divided into partitions, the unit of parallelism β each partition is an ordered, immutable log that consumers read sequentially by tracking an offset. A consumer group splits partitions among its members so each partition is read by exactly one consumer at a time, which is why having more consumers than partitions leaves the extras idle. Replication factor (commonly 3 in production) determines how many copies of each partition exist across brokers, so the cluster tolerates broker failure without data loss.
Q10. Explain Consumer Lag β Most Common Issue in Kafka & Messaging.
A: Consumer lag is the gap between the log-end-offset (the newest message written to a partition) and a consumer's current offset β effectively, how many messages are waiting to be processed. Lag growing across all partitions means the consumer group is simply too slow for the producer rate, fixed by scaling up consumers (up to the partition count). Lag stuck on one specific partition, while others are healthy, points to a stuck consumer or a poison pill message on that partition specifically β a different problem requiring you to find and handle that specific bad message, not just add more consumers.

