All technologies

Data & Architecture

Event streaming with Apache Kafka

In event-driven systems, each service reports what happened and others react to it. Kafka stores these events in order and durably, so new services can reread them later. We build this with the outbox pattern and change data capture so that no change is lost. For simpler cases, RabbitMQ or NATS are enough.

Apache Kafka is a distributed platform that stores events in order and durably, so many services can read them independently.

Data flow

How Event streaming with Kafka fits into your processes

  1. Application
  2. Outbox
  3. Debezium
  4. Kafka
  5. Consumers
The application writes events to an outbox table in the same transaction, and Debezium transfers them to Kafka.

Use cases

What we build with Event streaming with Kafka

  • Decouple systems

    Store, ERP and business applications exchange events without calling each other directly.

  • Change Data Capture

    Pass on changes from the database as events with Debezium.

  • Replays

    Replay events to populate new services or fix errors.

  • Data pipelines

    Forward events to analytics, search and the data warehouse.

Typical projects

Why companies bring us in

  1. 01

    Decouple store and ERP

    Starting point
    Store, ERP and shipping call each other directly; if one system fails, the whole chain stalls.
    Solution
    We introduce business events such as order received and let each system process them independently.
    Result
    An outage only holds up the affected system; the others catch up as soon as it is running again.
  2. 02

    Capture changes without rebuilding

    Starting point
    An existing application needs to notify other systems of changes, but its code can hardly be modified.
    Solution
    We read changes via change data capture with Debezium directly from the database log.
    Result
    Other systems receive every change without having to rebuild the legacy application.
  3. 03

    Backfill a new service

    Starting point
    A new analytics service also needs past transactions.
    Solution
    We retain events long enough and replay them for the new service from the beginning.
    Result
    The service starts with the complete dataset, without special exports from the source systems.

Approach

How we introduce Event streaming with Kafka

  1. 1

    Model events

    Which business events exist, who produces them, who reads them?

  2. 2

    Schemas and topics

    Define formats in the schema registry, partitions and retention.

  3. 3

    Producers and consumers

    Implement outbox, CDC and idempotent processing.

  4. 4

    Operations

    Set up the cluster, lag monitoring and recovery.

Result

What you get from us

  • Event model with names, keys and owners
  • Schemas in the schema registry with compatibility rules
  • Outbox table and CDC pipeline with Debezium
  • Idempotent consumers with error topics
  • Topics with partitions and retention
  • Monitoring of lag and throughput
begin;

update auftraege set status = 'bestaetigt' where id = $1;

-- Ereignis in derselben Transaktion wie die fachliche Änderung
insert into outbox (id, aggregatetype, aggregateid, type, payload)
values (gen_random_uuid(), 'auftrag', $1::text, 'AuftragBestaetigt',
        jsonb_build_object('auftragId', $1::text, 'zeit', now()));

commit;

-- Debezium liest die Outbox aus dem WAL und leitet das Ereignis
-- über den Outbox Event Router in das Topic outbox.event.auftrag.
The business change and the event are stored together, either both or neither.

Quality

What we watch for with Event streaming with Kafka

  1. 1

    No double entry

    Writing to the database and Kafka separately loses events when errors occur, so we use the outbox pattern.

  2. 2

    Exactly once, realistically

    Kafka guarantees exactly-once only within Kafka; we build consumers with external side effects to be idempotent.

  3. 3

    Order per key

    Kafka only preserves order within a partition, so we choose the key based on the business entity.

  4. 4

    Evolve schemas

    New fields must not break old consumers, and the schema registry checks this before writing.

  5. 5

    Don't let errors block

    A single faulty message must not block the partition permanently, so it is moved to a separate error topic instead.

Comparison

Apache Kafka or RabbitMQ?

Apache Kafka

Model
Persistent log of events
After reading
Events are retained
Replays
Built in via offsets
Routing
Via topics and partitions
Operations
More complex, built for high load

RabbitMQ

Model
Message broker with queues
After reading
Message is removed after acknowledgment
Replays
Only with streams or separate storage
Routing
Flexible via exchanges
Operations
Lean entry point

RabbitMQ fits task queues and flexible routing. Kafka fits when many services read the same events and replays are needed.

Event streaming with Kafka

Common questions

Tap a question.