Streaming Updated: 2026-01-21

What is Apache Kafka?

A distributed event streaming platform used for building real-time data pipelines and streaming applications, handling trillions of events per day.

From the field

Apache Kafka is the distributed log that ate the streaming world. Originally built at LinkedIn around 2011 to solve their cross-system data-integration nightmare, Kafka's core abstraction — an append-only, partitioned, replicated log that producers write to and multiple consumer groups read from independently — turned out to be the right primitive for an enormous range of problems: event-driven microservices, change data capture, real-time analytics, log aggregation, metrics pipelines, and more. If you're building any system where multiple services need to react to the same stream of facts, Kafka is almost certainly in the picture.

What Kafka actually is underneath the buzzwords

Kafka isn't a message queue in the RabbitMQ sense. It's a durable, replay-able log. Messages stay around (days, weeks, or forever with log compaction) after consumption. Consumers track their own offset — their position in the log — so two independent consumer groups can read the same topic at different speeds without affecting each other. Topics are split into partitions; each partition is ordered but the topic as a whole isn't. Keys determine which partition a message lands in, so "all events for user-42" stay ordered on one partition even while the topic as a whole is parallelized across dozens. Replication (usually 3x) across brokers gives durability even when a broker crashes.

Field story

A fintech client had a classic "database-of-doom" architecture: the mobile app wrote to Postgres, and 14 downstream systems (fraud scoring, notifications, risk engine, data warehouse, reporting) each polled Postgres every 30 seconds for new rows. Postgres CPU ran at 85% all day just serving reads, and a single slow consumer could back up replication. We inserted Kafka as a CDC buffer using Debezium → Kafka → 14 consumer groups. Each consumer moved at its own pace, Postgres CPU dropped to ~25%, and adding a 15th consumer (an ML feature pipeline) took 20 minutes instead of a two-week migration. The caveat: we spent six months operationally maturing — partition strategy, monitoring consumer lag, handling offset-commit-failures, wiring schema registry so producers couldn't ship breaking changes. Kafka itself is simple; operating Kafka well is not.

Apache Kafka is a distributed event streaming platform capable of handling trillions of events per day. Originally developed at LinkedIn, Kafka is now used by thousands of companies for real-time data pipelines, streaming analytics, and event-driven architectures.

Core Concepts

Topics

Data streams are organized into topics—named feeds of messages:
  • Producers write to topics
  • Consumers read from topics
  • Topics can have multiple partitions for parallelism

Partitions

Topics are split into partitions for scalability:
  • Each partition is an ordered, immutable sequence of records
  • Consumers can read partitions in parallel
  • Partition count determines parallelism

Consumer Groups

Consumers form groups to divide work:
  • Each partition is consumed by exactly one consumer in the group
  • Allows horizontal scaling of consumers
  • Multiple groups can read the same topic independently

Kafka Architecture

Producers → [Topic: orders] → Consumers
                  │
            ┌─────┴─────┐
            │ Partition │
            │     0     │
            ├───────────┤
            │ Partition │
            │     1     │
            ├───────────┤
            │ Partition │
            │     2     │
            └───────────┘

Key Features

  • High Throughput: Millions of messages per second
  • Low Latency: Sub-millisecond message delivery
  • Durability: Data replicated across brokers
  • Scalability: Add brokers without downtime
  • Fault Tolerance: Automatic leader election

Kafka Ecosystem

  • Kafka Connect: Pre-built connectors to data sources/sinks
  • Kafka Streams: Stream processing library
  • ksqlDB: SQL interface for stream processing
  • Schema Registry: Manage message schemas

Kafka Use Cases

  1. Event Sourcing: Store all state changes as events
  2. Change Data Capture (CDC): Capture database changes
  3. Microservices Communication: Async event-driven messaging
  4. Real-time Analytics: Process events as they arrive
  5. Log Aggregation: Collect logs from distributed systems

Key Points

Gotchas

Kafka operational pitfalls that bite every team eventually:

  • Under-partitioning your topics. Partition count caps consumer parallelism — if you have 6 partitions, only 6 consumers in a group can actively process. Changing partition count later is painful and breaks ordering guarantees. Over-provision: plan for 2-3x peak consumer count at topic creation.
  • Over-partitioning your topics. Thousands of partitions per broker multiplies metadata overhead, slows rebalances, and stresses ZooKeeper/KRaft. 4000 partitions per broker is often the practical upper bound. Don't blindly set partitions=200 on every topic.
  • Ignoring consumer lag monitoring. The one metric that matters most: how far behind is your consumer relative to producer head? Alert on lag > SLA threshold. Teams that don't monitor lag discover 4-hour-stale data when a dashboard consumer finally reads it.
  • Default auto.offset.reset=latest in production. A consumer that restarts with no committed offset will skip all backlog. Use earliest for most batch-like consumers; reserve latest for real-time-only use cases where missed events are acceptable.
  • No schema registry, hoping JSON schemas stay stable. Producers change fields; consumers break. Use Confluent Schema Registry or Apicurio with Avro/Protobuf/JSON Schema. Reject incompatible schemas at produce time.
  • Log retention misunderstood. Default retention is 7 days; data older than that disappears. For event-sourcing use cases, set retention.ms=-1 (forever) and enable log compaction (only latest value per key kept). Don't learn this from a data-loss incident.
  • Exactly-once semantics are harder than they sound. EOS requires idempotent producers (enable.idempotence=true), transactions for multi-partition writes, and transactional consumer reads (isolation.level=read_committed). Misconfigure any piece and you're back to at-least-once.
  • Tiny messages hurt throughput. Kafka is optimized for batches. Sending 10-byte messages one at a time gives 10KB/s; batching to 16KB gives GB/s. Tune batch.size and linger.ms to aggregate small writes.
  • Partition key skew. If 80% of messages share the same key, all land on one partition — that partition's consumer becomes the bottleneck while others idle. Audit key distribution; consider compound keys or hash-salting for skew.
  • Running Kafka yourself at small scale. Operating Kafka responsibly (upgrades, rebalances, broker failures, monitoring) is a full-time job. At small scale, use Confluent Cloud, AWS MSK Serverless, Redpanda Cloud, or Warpstream. Only self-host when scale justifies the ops investment.

Frequently Asked Questions

What is Apache Kafka used for?

Kafka is used as a durable, distributed event log that decouples producers from consumers. Primary use cases: (1) event-driven microservices architectures where many services react to the same events; (2) change data capture (CDC) — Debezium reads database changes into Kafka, many downstream consumers react; (3) real-time analytics pipelines — Kafka → Flink/Spark Streaming → warehouse; (4) log aggregation — collecting logs from thousands of servers; (5) metrics pipelines; (6) event sourcing — Kafka as the source-of-truth log for application state. Essentially: any time multiple systems need to react to the same stream of facts, Kafka is the default choice for the backbone.

Is Kafka a message queue?

Kafka can fill the role of a message queue but is more accurately a distributed log. Key differences from traditional queues (RabbitMQ, SQS): messages persist after consumption for configurable retention; multiple independent consumer groups can read the same topic at different speeds; consumers manage their own offset so they can replay history; and ordering is guaranteed per-partition, not across the topic. For pure work-queue semantics (one consumer takes a job, job disappears), traditional queues are simpler. For fan-out, replay, high-throughput, and multi-consumer scenarios, Kafka's log model is the right abstraction.

What is a Kafka topic and partition?

A topic is a named stream of messages (e.g., `orders`, `user-clicks`, `payment-events`). A partition is a subdivision of a topic — each topic has one or more partitions. Each partition is an ordered, immutable sequence of messages stored on a specific broker and replicated for durability. Partitioning enables parallelism: a topic with 12 partitions can have up to 12 consumers in a consumer group reading in parallel. Messages with the same key always go to the same partition (via `hash(key) % partitions`), preserving per-key ordering. Partition count is the primary tuning knob for throughput and consumer scalability.

What is a consumer group in Kafka?

A consumer group is a set of consumer processes that cooperate to read a topic. Kafka distributes the topic's partitions across the group's consumers — each partition is read by exactly one consumer in the group. If you have 12 partitions and 4 consumers, each consumer handles 3 partitions. Add a fifth consumer and Kafka rebalances so each reads 2-3 partitions. Remove a consumer and its partitions are redistributed. Multiple groups can subscribe to the same topic independently — group A (analytics pipeline) and group B (notification service) each see every message. Consumer groups are how you scale stream processing horizontally.

Is Kafka difficult to learn and operate?

Learning basic producer/consumer usage takes an afternoon. Mastering Kafka's full surface area (consumer groups, rebalancing, offsets, exactly-once semantics, schema evolution, compaction, KRaft/ZooKeeper, MirrorMaker) takes months. Operating a production Kafka cluster responsibly is a specialty role — upgrades, rolling restarts, rebalances, capacity planning, monitoring dozens of metrics (consumer lag, under-replicated partitions, request latencies, disk usage). Small teams should use managed Kafka (Confluent Cloud, AWS MSK, Redpanda Cloud, Aiven) to avoid the operational burden. Only self-host when scale justifies a dedicated platform team.

What is the difference between Kafka and RabbitMQ?

Kafka is a distributed log optimized for high-throughput, replayable, multi-consumer workloads — it keeps messages around and lets consumers seek to any offset. RabbitMQ is a traditional message broker optimized for flexible routing (exchanges, bindings, routing keys), per-message delivery semantics, and queue-based work distribution. Kafka wins on throughput (millions of msgs/sec per broker), retention, and replay. RabbitMQ wins on flexible routing, priority queues, and operational simplicity at small scale. Use Kafka for event streaming and CDC; RabbitMQ for task queues, RPC, and complex routing. Many companies use both — they solve different problems.

What are Kafka Connect, Kafka Streams, and ksqlDB?

Kafka Connect is a framework for moving data between Kafka and other systems via pre-built connectors (Debezium for CDC, JDBC for databases, S3 sink for data lake, Elasticsearch, etc.) — you configure YAML instead of writing code. Kafka Streams is a Java library embedded in your application for processing Kafka topics (filter, map, aggregate, join) with exactly-once semantics and state management; no separate cluster required. ksqlDB is a streaming SQL engine built on Kafka Streams — write SQL queries against topics as if they were tables. Together they cover most streaming use cases without Flink or Spark, though Flink is often preferred for complex event-time processing and larger state.

Related Terms

Stream ProcessingData PipelineApache SparkChange Data Capture (CDC)

Related Tools

ConfluentAWS MSKRedpandaApache PulsarRabbitMQ

Learn More

Related Articles

Browse All Terms Read Articles