{"canonical_url":"https://engineer.company/glossary/transactional-outbox/","content_markdown":"# Transactional outbox\n\n## What it is\n\nA transactional outbox is a durable record that tells another process what to\npublish after a database change. The application writes the change and the\noutbox entry within one database transaction. The entries commit together. If\nthe database rolls back, a relay has no committed entry to publish. The relay\nmay poll a table or watch changes through the database's change stream. The\ndestination can be a broker, an integration service or another component with a\ndocumented delivery contract.\n\nConsider a service that records that a parcel has been received at a depot. The\nsame transaction updates the parcel record and inserts an event with a stable\nidentifier, a parcel reference, an event type and a version. The HTTP request\ncan finish once the transaction commits. A separate publisher sends the event\nand records progress. The service can acknowledge the committed update\nimmediately while transport and downstream processing follow on their own\nschedule.\n\nThe producer decides which facts belong in the event and preserves them under\nthe same commit boundary as the change. The publisher is responsible for\nretrying transmission. The receiver needs a way to recognise an event already\napplied. If the publisher sends successfully and stops before recording that\nsuccess, the same event can be sent again after it returns. The event identifier\nmust survive this repeat.\n\n## Why it matters\n\nWithout a shared commit boundary, a producer must choose an order for two\nindependently fallible operations. A database write can succeed while\npublication fails. Sending first can let another service act on a change the\ndatabase later rejects. Closing either window with retries alone requires\nknowing which step happened. An outbox gives the publisher a durable answer\nabout committed intent, including when the producer restarts or the broker is\nunavailable for a while.\n\nA customer can observe the effects of the delay. The depot screen might\nimmediately show the parcel at the facility, while an email notification arrives\nlater. Define which result the request acknowledges and which ones arrive\nasynchronously. If a subsequent business step must wait for the broker consumer\nto finish, model that pending state explicitly and decide what response the user\ncan see while it is pending.\n\nThe database now holds a buffer that must be operated. Count unpublished records\nand track the age of the oldest one. A growing count can be normal for a short\nburst, while a stable count with one ageing entry can indicate an event that\nnever makes progress. Observe relay attempts and consumer failures separately.\nWhen somebody investigates a delayed shipment, they should be able to\ndistinguish a committed parcel update from a published event and a completed\nnotification.\n\n## What it looks like in practice\n\nStart with an integration that can accept duplicate deliveries safely. In an\nisolated test, update a parcel and write its event. Stop the publisher before it\nreads the committed entry and confirm that the entry is present after restart.\nNext stop it after a send and before saving progress. The receiver should handle\nthe repeat using the existing event ID. Check the actual side effect, such as a\nnotification record, and count the acknowledgements at the broker separately.\n\nTest a database rollback separately. Ask the producer to perform an operation\nthat fails a constraint and verify that neither the proposed row change nor the\nevent is visible afterward. Then commit two changes for one parcel while a\ndifferent parcel's events are also arriving. If consumers depend on per-parcel\norder, give them a sequence or version with a meaningful scope and test delivery\nout of order. A timestamp alone may order items differently from the application\nchanges they describe.\n\nOur\n[case study about moving slow work onto a River job queue](/portfolio/moved-slow-work-onto-a-river-job-queue/)\ndescribes keeping jobs and the rows they touch in PostgreSQL so they can commit\ntogether. That shared commit boundary is relevant here. The parcel example adds\na separate relay and a receiver to demonstrate publication to another system.\nThe case outcome is about in-database background work and an inspectable\nhistory. The additional delivery test applies when the durable record is a\nrequest for external publication.\n\n## Where it goes wrong\n\nAn event tied only to a reference can describe the wrong version if the relay\nlooks up the current state long after the original update. Store the data or\nimmutable version that the consumer needs to act on. Decide which fields are\nuseful, who can read them and how long the event should be retained. Copying an\nentire application record can put sensitive fields into an additional store and\nmake later schema changes harder to manage.\n\nRepeated delivery is a normal recovery path. The consumer needs to decide how\nlong to retain its processing record and keep that decision consistent with the\nmaximum redelivery or replay window. For effects controlled by the receiving\ndatabase, recording the event identity and the side effect in the same receiver\ntransaction avoids another gap. External effects need their own idempotency\nmechanism or a reconciliation process based on a stable reference.\n\nAn outbox that grows without a limit can eventually threaten the database that\nserves everyday application traffic. Define when published entries can be\narchived or removed and which processing state the cleanup uses. Monitor free\nspace, publishing delay and the rate at which new events are generated. Keep a\nprocedure for finding and dealing with an event the relay cannot send. In a\ndrill, prove that later work can still proceed under the required ordering\npolicy and that a repaired event can be replayed safely.\n\n## Further reading\n\n- [AWS transactional outbox guidance](https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/transactional-outbox.html)\n  explains the failure window between separate database and messaging writes.\n- [Microsoft's Cosmos DB outbox architecture](https://learn.microsoft.com/en-us/azure/architecture/databases/guide/transactional-outbox-cosmos)\n  shows how a change feed can drive the relay.\n- [PostgreSQL transactions](https://www.postgresql.org/docs/18/tutorial-transactions.html)\n  describes the commit boundary that an outbox can share with application data.\n\n\u003chttps://engineer.company/glossary/transactional-outbox/\u003e\n","date_modified":"2026-11-24T21:48:58Z","description":"How an outbox keeps a data change and its event together, and what to test when a publisher retries.","formats":{"gemtext":"https://engineer.company/glossary/transactional-outbox/index.gmi","gopher":"https://engineer.company/glossary/transactional-outbox/gophermap","html":"https://engineer.company/glossary/transactional-outbox/","json":"https://engineer.company/glossary/transactional-outbox/index.json","markdown":"https://engineer.company/glossary/transactional-outbox/index.md","pdf":"https://engineer.company/glossary/transactional-outbox/index.pdf"},"kind":"page","language":"en","title":"What is a transactional outbox?","url":"https://engineer.company/glossary/transactional-outbox/","version":1}