Why AI Systems Lie and How to Stop Them

AI pipelines are rediscovering a failure mode databases solved thirty years ago.

Databases · AI Infrastructure · Distributed Systems
Log First, Act Second
A quiet database pattern invented to keep distributed systems honest has become the hidden foundation of reliable AI infrastructure.
2026

There is a failure mode baked into almost every distributed application built in the last two decades, and most engineers discover it only after something has already broken. It lives in the gap between two operations that look like one: saving a record to a database and then announcing the change to the rest of the system. Both feel instant and safe. They are not the same operation, and the window between them is where systems fracture into two different versions of the truth.

I. The crack no one sees until it costs them

The problem has a name in distributed systems: the dual-write problem. A service writes to a database, then publishes a message to a broker, a kind of dispatch service that routes notifications between components. Two separate commitments to two separate systems, with no shared understanding of what the other is doing. If the database write succeeds and the process crashes before the message goes out, the event vanishes without a trace. Reverse the order and the trap springs back the other way: publish first, have the transaction roll back, and downstream services react to a state change that never happened. Neither ordering is safe.

Engineers at the European neobroker Trade Republic ran into this while building their cash-balance service. A customer deposit would land in the database, and then the service would crash before publishing the event to Kafka, the streaming system their infrastructure relied on. From the database's perspective, the deposit was complete. From every other service, nothing had happened. The event was not delayed or corrupted. It was simply gone, with no error to mark its passage. They had not found a rare edge case in a poorly designed system. They had found the crack that has always been there.

01 The dual-write trap
Both orderings of a dual-write fail. Path A: the database commits, the process crashes, and the message broker never receives the event. Path B: the broker publishes, the database rolls back, and downstream services act on a state that never existed. The dashed arrow marks where each path breaks.
PATH A PATH B Service Database committed ✓ Process crash server failure Message broker never reached Event lost Service Message broker published ✓ Database rollback ✗ Downstream phantom state Ghost event
Step succeeded
Failure or phantom state
Disrupted path
II. The solution hidden in the database itself

The outbox pattern solves the dual-write problem by refusing to cross a system boundary at the moment of truth. Instead of writing to the database and then reaching out to a broker, the service writes both the business record and a description of the event into the same database, inside a single transaction. Because both targets live in the same system, the atomicity guarantee that databases have provided for decades covers both writes at once. Either both land or neither does. The coordination problem becomes a local problem the database already knows how to solve.

Once the event record is safely committed, a separate relay process reads the new rows and forwards them to the message broker, then marks them as delivered. The relay runs independently of the business transaction, so a crash on either side leaves the committed record intact. The sequence now has a durable checkpoint between writing and announcing, and anything after that checkpoint can be retried without losing what came before.

At Shopify, the open-source Debezium tool tails the transaction logs of more than a hundred MySQL shards behind the company's commerce system, streaming committed writes into Kafka rather than polling an outbox table on a schedule. During a recent Black Friday weekend, that pipeline processed roughly 65,000 database records per second at peak, with latency from a write to its availability in Kafka staying under ten seconds at the ninety-ninth percentile. The outbox table and the log reader are the mechanism. At Shopify's scale, that mechanism moves the state of a global retail platform.

02 The outbox pattern
The service commits the business record and an outbox event row together in a single atomic database transaction. An outbox relay reads the committed row from the transaction log and publishes it to the message broker. The consumer deduplicates by event ID, achieving exactly-once effective processing without exactly-once transport.
Service SINGLE DB TRANSACTION Business record domain write + Outbox event row event pending Database committed ✓ reads transaction log Outbox relay CDC log reader Message broker at-least-once Consumer deduplicates by ID
Atomic commit boundary
Async relay (CDC)
Dashed: async reads log
III. Why "exactly once" is a polite fiction

The delivery guarantee everyone reaches for first is exactly-once: every event arrives at its destination precisely one time, no more and no less. It is the simplest mental model and the hardest thing to actually deliver. A classic result in distributed computing, sometimes called the Two Generals Problem, shows that if an acknowledgment can be lost in transit, a sender can never distinguish between "message processed, acknowledgment lost" and "message never arrived." Networks are unreliable in exactly this way. The only options are accepting a possible duplicate or accepting a possible gap.

Distributed systems have converged on at-least-once delivery paired with idempotent consumers. Every event carries a unique identifier. Before acting on a message, a consumer checks whether it has already processed that identifier. If it has, it skips the operation. If it has not, it processes normally and records the identifier. The deduplication work sits on the consumer side, not in the transport layer, which is the right place for it because the consumer is the only component that knows whether a given side effect has already occurred.

Kafka, the streaming platform used by thousands of companies for event relay, has invested heavily in building exactly-once semantics directly into the broker. The mechanism assigns sequence numbers to producer messages so the broker can identify and discard retried duplicates. The platform's own documentation is clear about where the guarantee ends: it covers transport between Kafka components, not the broader application. A retried consumer operation that sends a payment confirmation to an external processor can still trigger a duplicate charge if the consumer does not check whether it already completed the action. Exactly-once delivery is a property of the pipe. Idempotency is a property of the endpoint, and no amount of broker sophistication changes that.

Distributed systems event log architecture

A CDC relay tailing a database transaction log and streaming committed events into a durable message broker. The outbox pattern turns a two-system coordination problem into a local commit followed by an asynchronous relay, giving the broker a single, replayable source of truth it can fan out to any number of consumers.

IV. The same trap, rebuilt in AI

A modern AI application is a distributed system wearing new clothes, and it has more places to lose a write than a traditional microservice ever did. A typical production AI stack spans a primary database, a vector index, a message broker, an observability sink, and one or more model endpoints, each component often maintained by a different team or vendor. Every boundary between those components is a potential dual-write problem waiting to surface. The engineers who built these stacks moved fast through a period of rapid capability growth, and many inherited the same latent failure mode without recognizing it as a known problem with known solutions.

The most visible place it appears is Retrieval-Augmented Generation, the architecture where a language model pulls relevant documents from a vector store before generating a response. The vector store has to stay consistent with the primary data it mirrors. When a document changes in the primary system, its embedding must be regenerated and updated in the index. If that second step fails or lags, the index drifts from reality. The model retrieves stale embeddings and generates answers based on outdated information, doing so with the same confidence it would bring to accurate data. The divergence is invisible at the inference layer and shows up only in output quality, which makes it one of the harder failure modes to diagnose and one of the easier ones to overlook until users start noticing.

The problem appears at every layer of an AI pipeline, from agentic workflows that lose state mid-run to observability systems that drop inference records before they reach the audit log. One data platform company surveying teams deploying RAG at scale found the failure mode appearing consistently: embedding generation API calls would time out or fail, leaving vector indexes half-populated, and stale vector data, in their account, could "turn great generative AI systems into useless systems in short order." The dual-write problem does not become less dangerous when it runs inside a language model pipeline. It becomes harder to see.

V. The log is the system

Before a database makes any change to its actual data files, it records the intended change in a write-ahead log. If the process crashes mid-operation, the log survives on disk. On restart, the database replays the log to reconstruct what was in progress, and the data files end up in the correct state regardless of when the crash occurred. The log is not a backup or an audit trail appended after the fact. It is the primary record of intent, and the data files themselves are a materialized view derived from it. Log first, act second is not a microservices pattern or an AI principle. It is the basic architecture of any system that needs to survive failure.

What changed over the past fifteen years is that this idea escaped the internals of individual databases. Engineers at LinkedIn, building the infrastructure that eventually became Kafka, made the argument explicitly: every query-optimized data store, whether a search index, a cache, or a read-optimized replica, can be understood as a derived view of a shared log. The log holds the source of truth. Every other representation is something the log can regenerate. The outbox pattern is this same philosophy applied to the seam between a single service and its downstream consumers.

The pattern shows up wherever the problem shows up, under different names and in different tooling. Event sourcing treats the sequence of changes to a business entity as the authoritative record and derives current state by replaying them. The write-ahead log in PostgreSQL or MySQL gives database engineers a changelog they can tap with a tool like Debezium. Modern workflow engines persist the execution history of a long-running process so it can be replayed from any checkpoint. RAG pipelines that route source changes through an event stream before triggering embedding updates are applying the same logic to vector consistency. The vocabulary shifts depending on the context, but the architecture is stable: make the record durable before taking the action, and design every recipient of that record to handle receiving it more than once. Reliable systems are not systems that never fail. They are systems whose failures leave a trail that can be followed back to safety.

03 The AI stack: log first, act second
Every AI component treated as a derived view of a shared, durable event log. The primary database commits to the log via the outbox mechanism. Three downstream AI consumers, a vector index for RAG, agent memory for durable execution, and an LLMOps pipeline for audit and analytics, each stay current from a single source of truth.
Primary DB source of truth Outbox Event log ordered, replayable Vector index RAG sync Agent memory durable execution LLMOps audit, analytics
Event log (source of truth)
AI consumers (derived views)

Key references: Richardson, C., "Transactional Outbox Pattern," microservices.io, 2018. Kleppmann, M., Designing Data-Intensive Applications, O'Reilly Media, 2017. DeCandia, G. et al., "Dynamo: Amazon's Highly Available Key-value Store," ACM SOSP, 2007. Kreps, J., "The Log: What every software engineer should know about real-time data's unifying abstraction," LinkedIn Engineering Blog, 2013. Shopify Engineering, "Capturing Every Change from Shopify's Sharded Monolith," shopify.engineering, 2022. Trade Republic Engineering Blog, traderepublic.com/blog. Debezium CDC project documentation, debezium.io. Apache Kafka documentation on exactly-once semantics, kafka.apache.org.