Apache Kafka — Event Streaming from Basics to a Platform Service›02 · Why event streaming

Lesson 02 of 17 · Foundations

Why event streaming

Why systems need an event log: the pain of services calling each other directly, what an event is, how an append-only log decouples producers from consumers, absorbs spikes, feeds many readers and allows replay. How a log differs from a traditional queue, where Kafka is used, and when it is the wrong tool.

Beginner
Key wordsevent streamingeventpoint-to-point integrationdecouplingbufferingfan-outreplaycommit loglog versus queueRabbitMQSQSwhen not to use Kafkaevent-driven architecture

The problem: everything talks to everything

Imagine a shop. When an order is placed, many systems care: billing, email, warehouse, analytics and fraud checks. The simple design is for the order service to call each one:

Orders ──► Billing
   ├─────► Email
   ├─────► Warehouse
   ├─────► Analytics
   └─────► Fraud check

This works at first, then hurts:

  • Coupling: if Billing is slow or down, Orders slows down or fails.
  • Every new reader means changing Orders. A new team that wants order data must ask the Orders team for another call.
  • Spikes: a sale with ten times the usual traffic hits every downstream system at once.
  • No history: once a call is made, it is gone. A system that was down, or a new system, cannot catch up.

With five producers and five consumers you have up to twenty-five connections to build, secure and monitor.

The idea: write events to a shared log

An event is a small, immutable fact: "order 123 was placed at 10:02 for 45 euros". Instead of calling everyone, the producer writes the event once to a log: an append-only list kept for a while. Anyone who cares reads from the log.

Orders ──► [ orders log:  e1  e2  e3  e4  e5 … ] ──► Billing     (at e5)
                                                 ──► Email       (at e5)
                                                 ──► Analytics   (at e3, catching up)
                                                 ──► New system  (starts at e1)
What you gain Why
Decoupling Orders doesn't know who reads; a reader being down doesn't affect it
Buffering Spikes go into the log; readers process at their own speed
Fan-out Any number of readers get the same events independently
Replay A new or repaired reader can start from an old position
Durability Events are written to disk and copied to several servers
Scale The log is split into parts spread over many servers

Think of a class notice board with a notebook. Instead of the teacher walking to every pupil to say "sports day is Friday", she writes it in the notebook on the board, one line after another, with a number. Each pupil reads it when they arrive and remembers the last line number they read. A pupil who was ill reads from where they stopped. A new pupil can read the whole notebook from page one. The teacher never waits for anyone.

Apache Kafka is the most widely used system for this: a distributed, replicated, append-only log built for very high throughput.

A log is not a queue

Kafka (log) Classic queue (RabbitMQ, SQS)
After a message is read Stays until retention removes it Deleted once acknowledged
Several independent readers Natural: each group has its own position One queue per reader, or a fan-out setup
Re-reading history Yes, from any retained position No
Ordering Guaranteed within a partition Limited
Typical use Event streams, pipelines, integration, audit Task distribution, work queues, RPC-style jobs

Both are useful. A queue answers "who will do this job?"; a log answers "what happened, in what order?"

The big picture: from collection to dashboard

1 · Collect: where events happen Web & mobile clicks, page views Microservices order placed, paid Databases rows inserted, updated Devices & logs sensors, server logs 2 · Ingest: turn it into a record REST proxy / SDK browsers can't speak Kafka Producer client acks=all, idempotent Debezium CDC Connect source, reads WAL Fluent Bit / MQTT agents and bridges 3 · Store & stream: the Kafka cluster web.clicks.v1 0 9 17 shop.orders.v1 0 9 17 cdc.products 0 9 17 new events are appended at the end → 3 brokers · KRaft · every partition copied 3× (min ISR 2) · Schema Registry checks the shape · mTLS, ACLs, quotas 4 · Process & react Stream processing Flink · Kafka Streams Event-driven services billing · email · fraud Kafka Connect sinks ClickHouse · S3 · OpenSearch results go back to Kafka as new topics 5 · Store & serve: built for queries Real-time analytics ClickHouse · Pinot · Druid Data lake S3 / GCS + Iceberg Search & databases OpenSearch · PostgreSQL 6 · Visualize & act Live dashboards Grafana · Superset Reports & BI SQL, notebooks, ML Alerts & apps thresholds, search UI 1 · Collect: where events happen 2 · Ingest: turn it into a record 3 · Store & stream: the Kafka cluster 4 · Process & react 5 · Store & serve: built for queries 6 · Visualize & act
Events are collected where they happen, written to Kafka once, and then feed processing, storage and dashboards independently.

Follow one event through the six stages:

Stage What happens Typical tools Lessons
1 · Collect Something happens: a click, an order, a changed database row, a sensor reading Web and mobile apps, microservices, databases, devices 2
2 · Ingest The event becomes a record (key, value, timestamp) and is written to a topic Producer clients, REST proxy, Debezium (CDC), Fluent Bit, MQTT bridges 6, 12
3 · Store & stream Kafka keeps an ordered, replicated log of every event for as long as you choose Brokers, KRaft, topics and partitions, Schema Registry 3, 8, 9, 11
4 · Process & react Services react to events; stream processors join, filter and aggregate them and write the results back as new topics Kafka Streams, Flink, event-driven services 7, 10, 12
5 · Store & serve Sink connectors copy topics into stores that are built for queries ClickHouse, Pinot, Druid, S3 + Iceberg, OpenSearch, PostgreSQL 12
6 · Visualize & act Dashboards query those stores, alerts fire, apps and reports use the results Grafana, Superset, BI tools, notebooks 12

Two things to notice:

  • Each stage only knows about Kafka, not about the others. The checkout service doesn't know a dashboard exists; you can add a new consumer next year and it can replay the history.
  • Dashboards don't read Kafka directly. Kafka is a log: it is excellent at "give me everything after offset 1,042" and bad at "revenue per region for the last hour". That question is answered by a store built for queries (stage 5), which Kafka keeps up to date within seconds. Lesson 12 follows one order event all the way to a bar on a chart.

Where Kafka is used

  • Event-driven services: order placed → billing, shipping and email react.
  • Data pipelines: application events into a data warehouse or lake.
  • Change data capture (CDC): every database change streamed to search indexes, caches and analytics.
  • Logs, metrics and telemetry from thousands of servers or devices.
  • Audit trails: a durable, ordered record of who did what, such as logins and permission changes.
  • Stream processing: fraud detection, real-time dashboards, alerts.

When not to use Kafka

  • You need an answer now (log in, check a balance): use an API.
  • Low volume and simple jobs: a managed queue is simpler and cheaper.
  • No one to operate it: a self-run Kafka cluster needs real operational skill. Prefer a managed service.
  • You need to query data by field: Kafka is not a database. Stream into one.
  • Big files: keep files in object storage and send a reference in the event.

Try it: map a system

  1. Pick a system you know (a shop, a school portal, a monitoring stack). List the services and draw every direct call between them.
  2. Count the connections. Mark which ones would break the caller if the receiver were down.
  3. Redraw it with one or two topics in the middle. Which producers write, which consumers read?
  4. Find one flow that should stay a direct API call, and say why.

Going deeper

  • Events describe facts in the past tense (OrderPlaced), not commands (SendEmail). That keeps producers independent of what consumers do.
  • A log makes the order of events the source of truth; databases can be rebuilt from it (event sourcing). Use this carefully: it adds complexity.

Recap

  • Direct calls between many services create coupling, spike problems and no history.
  • A shared append-only log gives decoupling, buffering, fan-out, durability and replay.
  • A log keeps events after reading; a queue deletes them.
  • Kafka is not for synchronous answers, tiny workloads or data you need to query.

This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.