Event-Driven Graphs with Kafka and CDC

Combining change data capture with event streaming makes the graph reactive while keeping Neo4j as the single source of truth.

Event-driven graphs pair naturally with streaming systems. Change Data Capture (CDC) lets your graph emit events whenever nodes or relationships change. Kafka distributes these events, enabling reactive workflows without polling. The key principle is that Kafka signals changes, but the graph remains the authoritative state.

CDC as the Event Source

CDC captures changes in the graph’s transaction log and emits events when nodes or relationships are created, updated, or deleted. This means you do not need to embed event logic in every query. The database itself becomes the event source.

You can configure CDC to emit full changes or diffs. Full changes provide complete context; diffs reduce bandwidth. Either way, the graph remains the canonical record.

Kafka as the Nervous System

Kafka distributes change events to consumers. Each consumer subscribes to topics that match its interests. A function does not need to poll the graph repeatedly; it receives a signal that something relevant changed, then queries the graph for the current state.

This is important: Kafka does not replace the graph. It provides notification, not authority. The graph remains the source of truth, which prevents data duplication and inconsistencies.

Topic Design

You can map topics to node labels, relationship types, or higher-level graph patterns. For example:

This allows you to create precise subscriptions. You can also change topic definitions as the graph evolves. Because the graph is schema-aware, you can generate topics dynamically from query patterns.

Catch-Up and Replay

Kafka’s log-based nature allows consumers to replay events. This is ideal for new agents or functions. They can replay historical changes to catch up, then switch to real-time consumption. This complements the graph’s own historical data, giving you both event sequences and current state.

Decoupling and Scalability

Kafka decouples producers and consumers. A graph update can trigger multiple consumers without them knowing about each other. This enables parallel processing and modular growth. You can add new agents without modifying existing ones, as long as they subscribe to the relevant topics.

Event-Driven Visualization

You can use Kafka events to drive real-time visualizations. Each event updates a graph dashboard, highlighting active nodes, errors, or stalled processes. This creates a living interface where you see the system evolve as events occur.

Why Not Polling?

Polling is simple but inefficient. It wastes resources by repeatedly querying for changes that may not exist. Kafka provides immediate, event-driven notifications. The system becomes more responsive and more efficient.

Practical Example

Suppose a new `AudioSegment` node is created. CDC emits an event to `node.AudioSegment.created`. A transcription function subscribes to that topic, receives the signal, and queries the graph for unprocessed segments. It processes the data and writes `Transcript` nodes. CDC emits events for those nodes, triggering downstream summarization functions.

The system becomes a chain of reactive steps, each driven by graph changes rather than manual scheduling.

Why This Matters

Event-driven graphs with Kafka enable real-time reactivity without sacrificing consistency. You keep the graph as the single source of truth while making the system responsive and scalable. This is the foundation of a living, self-updating computational graph.

Part of Graph-First Execution Systems