In distributed systems, keeping your primary database and external systems (like a search index or analytics pipeline) in sync is a notoriously hard problem.
What happens if you save to the database successfully, but the network request to update the search index fails? You end up with inconsistent state.
The Transactional Outbox Pattern solves this by using the database transaction itself. Instead of calling the external service directly, you save the domain entity AND an "Outbox Event" in the same transaction.
For the Outbox Pattern to work, your database must support ACID transactions. MongoDB supports multi-document transactions starting from version 4.0.
KnowledgeObjectOutboxEventA separate background worker constantly polls the outbox_events collection and processes the messages, providing "At-Least-Once" delivery guarantees.
Here is a simplified example of an outbox worker in Node.js: