Event Sourcing: Contextual AI Requires a Contextual Data Model

Stephen Tung avatar
Stephen Tung

Event Sourcing: Contextual AI Requires a Contextual Data Model

One of the biggest problems with AI these days is hallucination. How well it performs really depends on the amount of context it has about the topic you’re asking about.

AI is very unreliable if you ask it anything about your personal life. Unless you’re famous, it probably has no training data about you. It’s also spotty with contextualizing the latest and breaking news and emerging technologies because its base model’s knowledge cutoff is usually a while ago. You need to actively verify its responses and ideally cross reference different foundation models. On the other hand, AI excels at general knowledge because it’s trained on tons of text from the internet, books and articles.

So where does business data fall? Data stored in your CRMs, ERPs and custom applications is obviously not something AI knows about since it’s private. But there’s a deeper reason why business data usually doesn’t have enough context to be useful. Let me explain.

The Black Box Your Business Doesn’t Have

I don’t know if it’s just me, but it feels like I keep hearing about airplane incidents these days. When these devastating incidents happen and investigators need to figure out what went wrong, they always look for the “black box.”

The (actually bright orange) “Black Box”

The black box records everything that happened before an incident such as aircraft performance like speed and altitude, control positions, and button settings. Some parameters are captured thousands of times per second. This gives investigators a complete view of what was going on around the clock before the incident. It becomes the definitive source of truth for distributed teams investigating from different angles: pilot behavior, aircraft maintenance, manufacturing. The black box is full of context, and you can imagine how valuable this data would be for AI to understand and analyze an accident.

Now imagine a world where the black box hasn’t been invented. The only information investigators could collect would be the current state of the wreckage, i.e.,the values on cockpit instruments right now. They’d have to rely on intuition and just guess what happened. The current state doesn’t capture the context because previous states were never recorded.

This might come as a surprise to you, but most business applications don’t have a black box of their own.


This might come as a surprise to you, but most business applications don’t have a black box of their own.

CRMs, ERPs, ordering systems, inventory management, payment processing - many are designed to only capture the current state because their primary goal is handling day-to-day operations. The system only needs to know whether there’s enough stock right now. It doesn’t need to know what stock levels were like before.

But accidents eventually happen. Maybe you’re a food manufacturer whose product caused mass food poisoning. Maybe you’re a trading platform facing fraud allegations. When bad things happen, the current state in your business application won’t tell you why. Without a black box, you can’t go back in time. The past is gone.

It’s not just accidents. There are plenty of scenarios, like customer journeys, were understanding the past is the key to acting more effectively and profitably in the now and in the future.

Two Ways to Model Data: State vs. Event-based data model

Most business data comes from tables in databases like Postgres or MySQL that hold the latest, most correct data. But these tables are designed to reflect only the current state and not the past. This is a state-based data model, and it’s like looking at aircraft wreckage when there’s no black box.

A State-Based Shopping Cart

In this shopping cart example, records only track what’s in the cart right now. When a user removes the TV, a DELETE statement erases the record. When they reduce the HDMI cable quantity, an UPDATE statement replaces the old value. Each operation destroys the previous state forever. There’s no way to know which items were discarded or why, meaning lost opportunities to understand customer behavior, troubleshoot disputes, or comply with audits.

An event-based data model takes a different approach: instead of storing only the current state, it stores the history of everything that happened.

An Event-Based Shopping Cart

Each action, adding a TV, adding cables, removing the TV, swapping for a smaller TV, removing a cable - is captured as an event. To find the current state, you replay events from start to finish.

This might seem more complicated, but look what you get:

  • You can immediately form a story about this user as they downgraded from a big TV to a smaller one (probably because of a tight wallet).
  • You can travel back in time by replaying events up to any point to reconstruct the state at that moment.

And here’s the key insight: You can always construct the current state from events, but you can never reconstruct events from the current state. That tells you everything about how much more context the event-based model actually captures.


You can always construct the current state from events, but you can never reconstruct events from the current state

That tells you everything about how much more context the event-based model actually captures.”

Event sourcing is the architectural pattern that applies this event-based data model to your applications. Storing every change as an immutable event in an append-only log.


Learn more about event sourcing →

Powering AI with Your Business Black Box

Your Business Operation in Black Box

When you apply event sourcing across your entire business operation (for example, ordering, payment, fulfillment, packing, shipping), you construct a black box for your whole business. Each department captures their own valuable events, and together they form a complete timeline of operations, pointing out exactly what happened and when.

This opens up powerful AI solutions:

Customer Journey Prediction: When every view, add-to-cart, order, and cancellation is captured, AI models can understand the full customer journey and predict what products a user might want next. Your model can recommend an HDMI cable when someone adds a TV to their cart.

Dynamic Pricing Optimization: When every price change, inventory movement, and order is captured, AI can optimize pricing in real time, learning seasonal patterns and predicting stockouts. Retailers like Amazon use similar techniques to adjust prices thousands of times per day.

Customer Lifetime Value and Churn: When every login, search, and wishlist addition is stored, models can predict customer value, churn probability, and the optimal moment to intervene.

Demand Forecasting: When ordering, returns, cancellations, and supplier fulfillment events feed AI models, they can predict demand across warehouses, helping maintain optimal stock levels.

Case Study: Predicting Manufacturing Costs with 91% Accuracy

One of our customers, a German machine tool manufacturer, specializes in custom cutting tools with 12 different customizable parameters. They wanted to automate cost estimation for online orders, but with so many variables, manual expert input was required for every inquiry.

Their breakthrough came from a simple insight: why not review the costs of past orders with similar specs? And because their systems used event sourcing, they already had a black box. All manufacturing events were retained without anyone anticipating this need. With 15,000 historical data points, they trained a regression model achieving 91% accuracy.

In their own words: “If we hadn’t modeled our work logging solution as an event-sourced system, the data required would not have been available to us.”


“If we hadn’t modeled our work logging solution as an event-sourced system, the data required would not have been available to us.”

Read the full case study →

Build Your Business Black Box

Event sourcing helps you and your business application to build a black box for your business. The context it preserves transforms your operational data from a snapshot into a story, which makes AI much more useful.

Kurrent was purpose-built for event sourcing from the ground up, eliminating the complexity of adapting general-purpose databases. It delivers enterprise-grade capabilities backed by decades of production deployments, with native support for immutable events, global ordering, real-time subscriptions and projections.


Download the Benefits of Kurrent for Event Sourcing white paper to learn more →*