Skip to content
Blog

Engineering

Demystifying Apache Kafka: Why It's Not Just Another Message Queue πŸš€

What makes Kafka a distributed log rather than a queue, and when to reach for RabbitMQ or Redis instead.

July 6, 2026 / 6 min read
Message BrokerReliabilityArchitecture
Phan Hoang Nguyen Β· Backend Engineer

Hey everyone! πŸ‘‹ If you've been hanging around backend engineering and system architecture circles, you've inevitably heard the word "Kafka" thrown around. It often sounds like the ultimate silver bullet for any distributed system problem. But what exactly is it?

Today, let's grab a cup of coffee β˜• and dive deep into Apache Kafka. We'll strip away the jargon, explore its core architecture, figure out how it works under the hood, compare it with popular alternatives, and discuss its key trade-offs.


1. What is Apache Kafka, Really? πŸ€”

At its core, Apache Kafka is a Distributed Streaming Platform.

Instead of thinking of Kafka as a traditional message queue where a message is processed and immediately deleted, think of Kafka as a highly scalable, distributed, append-only log.

Imagine a massive, indestructible ledger book:

  • Producers write new events to the end of the log.
  • Consumers read from the log at their own pace.
  • Events stay in the log until a defined retention policy (e.g., 7 days or forever) expires them.

2. The Big Picture: Architecture & Core Concepts πŸ—οΈ

To understand Kafka, you need to know its core building blocks:

The Core Components:

  • Producer: Applications that write data/events to Kafka.
  • Consumer: Applications that read data from Kafka. Consumers pull data in batches to process efficiently.
  • Broker: A single Kafka server. A group of working brokers forms a Kafka Cluster.
  • Topic: A logical stream or category where messages are published (similar to a table in a database).
  • Partition: Topics are divided into partitions distributed across brokers for parallelism and massive scale.
  • KRaft / Zookeeper: The consensus mechanism that manages cluster metadata and leader election.

Here is a logical view of how the data flows:

mermaid
flowchart LR
    subgraph Producers
        P1[Payment Service]
        P2[Clickstream Tracker]
    end
 
    subgraph Kafka_Cluster[Kafka Cluster]
        B1[Broker 1]
        B2[Broker 2]
        B3[Broker 3]
        ZK[(KRaft / Zookeeper)]
    end
 
    subgraph Consumers
        C1[Fraud Detection Service]
        C2[Analytics Engine]
    end
 
    P1 -->|Publishes Events| Kafka_Cluster
    P2 -->|Publishes Events| Kafka_Cluster
    
    Kafka_Cluster -->|Pulls Batches| C1
    Kafka_Cluster -->|Pulls Batches| C2
 

3. How Does It Work Under the Hood? βš™οΈ

Let's zoom in on a Topic and its Partitions:

  1. Append-Only Logs: When a Producer sends a record, Kafka appends it to the end of a specific partition. Once written, records are immutable (they cannot be changed).
  2. Offsets: Every record inside a partition is assigned an incremental numerical ID called an Offset. Consumers track their own reading position via this offset. If a consumer crashes, it simply resumes reading from its last committed offset.
  3. Consumer Groups: Multiple instances of a worker service can form a Consumer Group. Kafka automatically assigns each partition to a specific consumer instance within the group, enabling seamless horizontal scale-out.

Here's how one topic's partitions map to a consumer group β€” each partition is read by exactly one consumer in the group, which is what caps your parallelism at the partition count:

mermaid
flowchart LR
    subgraph Topic["Topic: orders"]
        P0["Partition 0<br/>offsets 0 β†’ 3 β†’"]
        P1["Partition 1<br/>offsets 0 β†’ 2 β†’"]
        P2["Partition 2<br/>offsets 0 β†’ 4 β†’"]
    end
    subgraph CG["Consumer Group: order-workers"]
        C1[Consumer A]
        C2[Consumer B]
    end
    P0 --> C1
    P1 --> C1
    P2 --> C2

Add a third consumer and Kafka rebalances a partition onto it; add a fourth and it sits idle, because there's no unassigned partition left for it to own.


4. Kafka vs. RabbitMQ vs. Redis Pub/Sub: Picking the Right Tool βš”οΈ

Developers often ask: "Why shouldn't I just use RabbitMQ or Redis?"

Let's look at a conceptual difference using RabbitMQ's routing architecture as an example:

While RabbitMQ uses intelligent brokers with complex routing (Exchanges) to push messages, Kafka uses a "dumb broker / smart consumer" model where consumers pull from a distributed log.

FeatureApache KafkaRabbitMQRedis Pub/Sub
Primary ModelDistributed Commit LogTraditional Message Queue (AMQP)In-Memory Pub/Sub / Cache
Data FlowPull-based (Consumer polls data)Push-based (Broker pushes to consumer)Push-based (Fire & Forget)
PersistencePermanent on disk (Retention-based)Transient (Deleted upon acknowledgement)Ephemeral (Lost if consumer is offline)
ThroughputUltra-High (Millions of msgs/sec)High (Tens of thousands/sec)Extremely High (Limited by RAM)
Message Replayβœ… Yes (Rewind consumer offset)❌ No (Once consumed, it's gone)❌ No
Best ForEvent streaming, log aggregation, real-time analyticsComplex job queuing, transaction routing, RPCLightweight real-time notifications, chat signaling

Summary Rule of Thumb:

  • Choose RabbitMQ if you need complex routing logic, task queues, or strict per-message acknowledgements.
  • Choose Redis Pub/Sub if you need ultra-fast, lightweight signaling where losing messages during network hiccups won't break the business.
  • Choose Kafka if you need high-throughput event streaming, message replay capabilities, or a central immutable log for microservices.

5. Real-World Use Cases: Where Kafka Shines ✨

  • Event-Driven Architecture (EDA): Decoupling microservices so they react to state changes asynchronously rather than making synchronous HTTP calls.
  • Log Aggregation & Monitoring: Aggregating billions of daily telemetry events and logs across hundreds of servers into a centralized storage system.
  • Real-time Stream Processing: Calculating rolling metrics, auditing fraud detection on live transaction streams, or syncing database updates via Change Data Capture (CDC).

6. The Trade-offs (No Silver Bullets) πŸ›‘

As solution architects, we must weigh the trade-offs:

Pros βœ…Cons ❌
Massive Scalability: Horizontal scaling across hundreds of brokers.Operational Complexity: Managing and monitoring cluster partitions, rebalancing, and ISRs requires effort.
Durability & Replayability: Re-read historical events to backfill databases or recover from bugs.High Latency for Small Workloads: Polling batches introduces minor overhead compared to direct socket pushes.
High Throughput: Optimized sequential disk I/O and zero-copy transfers.Overkill for Simple Apps: Unnecessary if a lightweight Redis stream or PostgreSQL queue suffices.

Final Thoughts πŸ’‘

Apache Kafka isn't just a simple queueβ€”it is an event streaming backbone designed for massive, durable, and asynchronous data flows. Understanding its architecture and knowing when to pick Kafka over alternatives like RabbitMQ or Redis will help you design far more resilient, scalable backend systems.

Keep reading