An AI agent that decides something for a customer has to know what is true right now and what just happened. Which system gives it both: the transactional database, a data streaming platform such as Apache Kafka, or the lakehouse? The source of truth for AI agents is a combination of these systems in an event-driven architecture. The database is the system of record, where the transaction happens. Kafka carries every change as an event to all systems that need it, feeds real-time views of the current state, and carries the actions of the agent back to the system of record. The lakehouse keeps the history for analytics.
This article covers:
Three systems hold the data an agent needs, and each one answers a different question.
A transactional database holds the current state of the business and guarantees that every read sees a consistent point in time. It is the system of record. The account balance and the open orders live there, and every refund or booking is a transaction in this database. In many enterprises, the system of record is a business application with its own database, for example SAP for ERP data or ServiceNow for customer tickets. This article says database for all of them.
An event log holds what happened, in order, and lets any consumer replay it from any point. Apache Kafka is the de facto standard for this job. A payment attempt, an address change, a fraud alert: each one is an event with a position in the log. Applications, analytical platforms and agents consume these events independently of each other. This decoupling of producers and consumers is the core of an event-driven architecture.
A lakehouse holds the history of the business for analytics, reporting and model training. It answers questions across months and years, for example about the dispute history of a customer. The data arrives there from the operational systems, so the lakehouse is always a step behind the database. An agent reads history there. The transaction itself stays in the system of record.
The picture below shows the three systems, the question each one answers, and one example from a payment dispute.
In most cases, no. Kafka complements the database and does NOT replace it, so Kafka alone is rarely the source of truth for AI agents. I explained the reasons in Can Apache Kafka Replace a Database?, and they still hold. A log on its own has to replay history to answer a question about the current state. A table that is built from a Kafka topic can answer such a question, as a later section shows. In most architectures, this table lives in a separate database. The transaction behind a refund or a booking happens in a database in any case. The other direction fails as well: a database that keeps every historical version gets slow and expensive at the current-state queries it exists for. Hence, both systems stay in the architecture, and change data capture connects them.
Change data capture (CDC) reads every committed change from the transaction log of a database and publishes it as an event. Debezium is the best-known open source implementation. Many enterprises run a commercial product: Oracle GoldenGate, IBM InfoSphere Data Replication (IIDR) or a third-party tool such as Qlik Replicate. IIDR is often the choice for Db2, IMS and VSAM on the mainframe, as I described in Mainframe Integration with Data Streaming.
From Kafka, the change reaches the lakehouse, the search engine, the vector index and any other consumer, each at its own pace. The vector index enables vector search, the search over embeddings that an agent uses for retrieval. It can live in a dedicated vector database, in the lakehouse or in the operational database. In most architectures, the embeddings are computed after the change, so the index follows the system of record with a lag.
The direction is important. CDC goes one way, from the system of record into the event log. The database stays the place where the transaction happens. With the event log in between, a team can see and monitor how far each downstream system is behind the database.
Point-to-point replication from the database to each target looks simpler at first. Good reasons exist for the event log in the middle:
The picture below compares both approaches. With three source systems and four consumers, point-to-point replication needs up to twelve pipelines, and each one has its own schedule, format and failure mode. With the event log in the middle, each source publishes once and each consumer subscribes once.
Shopify is a great example of this pattern at scale. The commerce platform powers millions of online shops. On the Black Friday and Cyber Monday weekend of 2025, its merchants sold goods for 14.6 billion US dollars to more than 81 million customers.
The core of the platform is a MySQL monolith with more than 100 shards. The old extraction tool queried these databases in batches and could run at most once per hour per table, because the queries hurt the source databases. Shopify’s engineers built a log-based CDC platform to replace it. Debezium captures every change from the shards and writes it to Kafka. A change is available in Kafka less than ten seconds after the insert in MySQL (99th percentile). On the same weekend in 2020, this platform already processed about 65,000 change records per second on average with spikes up to 100,000. The sales volume of the weekend has almost tripled since then.
The lesson for agent architectures: once every change is an event in the log, a new consumer such as a vector index or an agent is one more subscriber, and the source database does not notice it.
With CDC in place, the agent has five paths to the data. The picture below shows them, and the following sections explain each path.
The database stays the system of record, and Kafka is the way in and out for the agent.
With CDC in place, every change of the account balance is also an event in Kafka. So why should an agent still ask the database for the balance? For a lookup by key, it does not have to. Examples are the balance of one account or the status of one order.
A serving table keeps the latest value per key from a Kafka topic and answers lookups and simple queries on it. Architects also call it a read model or a materialized view. The agent queries it through SQL, an HTTP API or MCP.
Good reasons exist to read from such a table and to leave the system of record alone:
The price is eventual consistency. A change exists in the database first and in the serving table a moment later. For preparing a decision, this is good enough in most cases. A serving table is also read-only. The final check and the write happen in the system of record, as the section about writes explains.
Various options exist to build such a table, and they differ a lot in maturity:
I covered serving layers on top of Kafka and their role for dashboards and agents in Dashboards and Queries for Apache Kafka.
Reading is half of the job. The other half is the action: a refund, a booking, a status change. In an event-driven architecture, the agent sends this action through Kafka as well.
The agent publishes a command, for example a refund request, to a topic. There, the service that owns the account consumes the command, checks the balance and books the refund in one database transaction. The result returns to Kafka as an event, through CDC or the outbox pattern. From the event log, it reaches the serving table, the lakehouse, the vector index and every other agent.
What is the difference between the two? Plain CDC publishes the row changes of the internal tables. With the outbox pattern, the service writes a business event such as “refund issued” into an outbox table in the same transaction as the booking, and CDC publishes this table. Consumers get an event that the service designed as a contract, and the internal tables stay private.
This path has clear benefits:
This path has a price. The agent has to wait for the result event before it tells the customer that the refund is done. Every command needs an idempotency key so that a retry does not refund twice. And the enterprise architecture gets more complex: topics, schemas, error handling and monitoring for the commands come on top. The effort pays off when several systems need the commands and their results.
Hence, writing through Kafka is not a must. If the caller needs an immediate answer, the agent calls the API of the owning application, and the change still reaches Kafka through CDC. For a single application with one database, this synchronous call is the simpler choice. I compared both styles in When to use Request-Response with Apache Kafka? and, for agents, in MCP vs. REST/HTTP API vs. Kafka. In both cases, the check and the write happen in one database transaction, executed by the service that owns the data.
One rule protects this design. The agent publishes requests such as “refund requested”. Only the system of record publishes facts such as “refund issued”, after its transaction.
A serving table answers lookups by key. Other questions remain:
Two options exist. If the same question comes up with every decision, a stream processing application with Kafka Streams or Flink computes the answer continuously and writes it into a serving table. Such a continuous query adds value when many requests need the same result.
For ad hoc questions and for a consistent picture across tables, the agent queries the database directly. It does so read-only, through a replica, an API or an MCP server of the application. Questions about history go to the lakehouse.
Most data pipelines are drawn from left to right: the source systems on the left, the lakehouse and the other consumers on the right. In many enterprises, the cleaning, enrichment and transformation of the data happens on the right side, in batch jobs inside the lakehouse. The shift left architecture moves this processing to the left, into the data streaming platform and close to the source. A data product is the result: built once in the stream and served to every consumer. The picture below shows the principle.
Operational and analytical systems receive the same data product. Hence, the data is consistent across all consumers. The cost goes down because the processing runs once. And no consumer waits for the next batch job.
The same curation is possible inside the lakehouse alone. The medallion architecture, which Databricks made popular, refines the data in bronze, silver and gold tables. This works well for analytics. Operational applications and agents get the curated data late or only through reverse ETL, which I consider an anti-pattern.
For an agent, shift left has three concrete consequences:
The boundary between the system of record and the downstream systems stays. Shift left makes sure that every downstream system sees the same data in the same order. In an architecture with several engines, I do not know a better way to get close to a single point in time.
An example makes the five paths concrete. An agent handles a disputed payment. It needs the account balance and the open orders (current state). The dispute history of the customer and the chargeback rate of the merchant come on top (analytical history), as well as the applicable policy and similar past cases (retrieval). Finally, the agent needs to know what happened in the past minutes: three failed login attempts, an address change, a second dispute with the same merchant (context).
The picture below shows the example from left to right: the four sources the agent reads, the decision, and the write.
If the architecture provides only one side, every single read still succeeds and nobody gets an error message. The decision looks justified in the audit trail, although the agent made it on incomplete or outdated data. This makes the problem hard to find in production.
The lakehouse vendors and the cloud providers have turned the path from the database to the lakehouse into a managed feature:
For a team whose world is one vendor, the managed path replaces a pipeline the team used to build and operate itself. This is a real improvement and a good choice in this situation.
However, the managed path ends at the vendor boundary. As soon as the context of the agent includes events from a second database, a SaaS application, a mainframe or a plant floor, the event log is the layer that spans all of them. Most enterprises I know are in this situation.
A second reason is just as important. The most critical data of an enterprise has many consumers: several applications, analytical platforms, partner interfaces and now agents. A managed path connects one database with one lakehouse. Every further consumer needs another pipeline, and the result is the point-to-point spaghetti architecture that many enterprises try to get rid of. An event-driven architecture avoids it across operational and analytical systems. This is one of the main reasons to use Kafka and the database together.
The market shows the same split. Replication inside one vendor has become a feature of the database and lakehouse platforms. Integration across vendors, clouds and legacy systems remains a market of its own. Hence, a data streaming platform belongs in the architecture next to the databases, whichever database a team chooses. The Data Integration Landscape explains how event streaming, APIs and batch integration work together.
Three anti-patterns appear when an agent relies on one system alone or mixes up the roles of the systems:
The source of truth for AI agents has two parts in an event-driven architecture. The database is the system of record, where every transaction happens. Kafka is the way in and out: it delivers the events, a real-time view of the current state through a serving table, and the commands of the agent to the service that owns the data. CDC is the bridge from the system of record into the event log. Shift left makes sure that operational and analytical consumers get the same data product. The lakehouse adds the history. Managed replication is a good choice inside one vendor and ends at its boundary.
This article is part of a series about databases for AI applications. The first article explains why the lakehouse vendors and the clouds bet on Postgres for AI applications.
To follow this work across data integration, workflow orchestration, process intelligence, and trusted agentic AI, subscribe to the newsletter and connect on LinkedIn.
Five vendors with five strategies chose the same database underneath. What the Neon and Crunchy…
Airlines run data pipelines, infrastructure automation, application workflows and business processes in separate orchestration silos,…
AI agents pile up debt when retries, approvals and audit land in the wrong layer.…
My Lufthansa HON Circle experience in 2026 as a frequent flyer with around 30 trips…
Humanoids get the headlines, but most physical AI value comes from what happens after a…
Within a month of Jev by TypeSafe AI, hyperscalers, AI labs, data platforms and open…