Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

The dependable fix for the dual-write problem is to save the business change and an event record in the same database transaction, then publish that record asynchronously through a relay. This transactional outbox pattern closes the gap where a database commit succeeds but publishing fails. It does not make delivery exactly once: relays can publish duplicates, so consumers must be idempotent, and ordering needs its own design.

How do I keep my database and event bus consistent?

Put an event in a transactional outbox as part of the same local transaction that updates the business data. A separate relay reads committed events and publishes them to the broker. If the transaction commits, both the business change and the outbox record exist; if it rolls back, neither does. This is the key guarantee of the transactional outbox pattern.

The outbox does not make the database and broker participants in one atomic transaction. Instead, it makes the database transaction the reliable handoff point: the service durably records what it needs to publish before attempting publication. A relay can retry after a temporary failure without losing the event.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What belongs in the outbox?

Store enough information to publish a stable, meaningful event without guessing from a later version of the business record. A typical outbox entry includes:

Popular on Amazon
Silkland 40Gbps USB C 90 Degree Right Angle Adapter 2 Pack, 240W USB4 | Male to Female Extender, 8K@60Hz, Thunderbolt 4/3, Steam Deck, ROG Ally, MacBook, Switch 2, iPhone 18/17/16/15, Quest 3 VR
  • 【90 Degree Full Function USB C Adapter】Supports the latest USB4 standard for up to 40Gbps of bandwidth, 8K video support, and up to 240W Fast charging; Support USB PD 3.1 Extended Power Range (EPR) including 140W, 180W and 240W. Your productivity is easily doubled. *Warm Tip: For the best fit, please make sure the USB-C port is fully exposed; thick or bulky cases may affect compatibility.
  • 【Reliable Quality】Made from high-quality, scratch-resistant aluminum alloy, delicate metal frame. get excellent wear resistance and heat dissipation. Non-Slip Design for easier insertion and removal.
  • 【Small and portable】Ultra thin size, ultra compact design, a petite physique that matches the minimalist design of your modern laptops. Coming with a slim figure that won't block the port next to the one it's plugged into.
  • 【Compatibility】Widely work with most usb c, thunderbolt 4/3 devices. Compatibilit for ROG Ally, Steam Deck, Switch, MacBook Pro, Quest 3 VR headset, Surface Book 2, iPhone 18/17/16/15, Samsung Galaxy S23/S22/S21, Note 20/10, Google Pixel, ChromeBook, etc.
  • 【Excellence Customer Support】If you experience any issues or cable failure, simply reach out to our dedicated customer service team. We provide a prompt response within 18 hours, providing you with the necessary technical support to resolve any concerns.
  • A unique, stable event ID for deduplication.
  • An aggregate or entity ID, such as an order ID or account ID.
  • An event type and, where appropriate, a schema version.
  • The event payload, or a reference to the data needed to construct it.
  • A creation timestamp and a sequence number or entity version when ordering matters.

In a relational database, the outbox is commonly a table. In a document database, event data may be stored as a property of the same item as the business state, subject to that database’s transaction boundaries.

What does the workflow look like?

  1. Begin a local transaction. Validate the command and apply the business change.
  2. Insert the event record. Use a stable event ID and include the entity identity, type, payload, and any required ordering information.
  3. Commit once. Commit the business record and outbox entry together.
  4. Run a relay. Discover committed entries by polling, transaction-log tailing, or a database change feed.
  5. Publish and record progress. Send each event to the broker. Only after broker acknowledgement should the relay mark it complete or delete it.
  6. Deduplicate at consumers. Before applying an event’s effect, check whether its ID has already been processed, or use another durable idempotency mechanism.

In simplified form:

BEGIN
  update business_entity
  insert outbox_event(event_id, aggregate_id, event_type, sequence, payload)
COMMIT

relay:
  read committed outbox events
  publish event
  after broker acknowledgement, record progress or delete the row

consumer:
  if event_id already processed: acknowledge or safely ignore
  otherwise apply the effect and record event_id

The sender, database, outbox, and relay are distinct roles in the pattern. They may run in different processes, but the atomic step is the write of business state plus event record inside the database transaction.

What happens if the app crashes after the database commit but before publishing?

With a naive database-then-broker sequence, the business change remains committed while downstream services never receive its event. With an outbox, the event record remains in the database, so a relay can discover and publish it after recovery.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The failure window is fundamental to two independent writes: the application can fail between them, or the broker can be unavailable when publication is attempted. Microsoft lists network errors, message-service outages, and host failures as examples of causes for this inconsistency. See the Azure transactional outbox guidance.

Reversing the order does not solve the problem. If the application publishes first and the database transaction then fails, consumers may act on a phantom event for a change that never committed. AWS describes both inconsistent outcomes in its transactional outbox guidance.

A short retry loop or a highly available broker can reduce the chance of a failed publish, but neither makes the two operations atomic. The durable fix changes the boundary: persist the intent to publish in the same transaction as the business change, then retry delivery from that durable record.

How do I fix the dual-write problem?

Start by deciding which service owns the business change and which database transaction is authoritative. Put the outbox in that service’s database, write the event alongside the state change, and assign a relay responsibility for delivery. Then design explicitly for retries, duplicate delivery, ordering, and cleanup.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Also popular on Amazon
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

1. Define the event contract

Choose event names and payloads that describe a business fact consumers can act on. Include a stable ID and the aggregate ID. Add schema versioning when consumers need to distinguish payload formats, and include a sequence or version if they must detect stale or out-of-order changes. Avoid relying on a mutable database row as the only source of event meaning: a relay that reads the row later may see a newer state than the one that caused the original event.

2. Make the transaction boundary real

Verify that the business write and outbox insert use the same database transaction and the same database resource. If one write is outside the transaction, the outbox cannot protect it. For a document database, verify its partition or item-level transaction scope; the phrase “same database” alone does not prove the writes are atomic together.

3. Choose the relay mechanism

For a modest event volume or a team seeking a straightforward implementation, a polling publisher is often the clearest starting point. For an environment already equipped to operate a transaction log or native change feed, CDC may fit better. The trade-offs are discussed below.

4. Specify acknowledgement and retry behavior

Define what counts as successful publication: typically, the broker’s acknowledgement. Retain or retry an event if publication fails or the relay cannot confirm success. Decide how retries are delayed and bounded, and how a message that repeatedly fails is quarantined or dead-lettered. Deleting or marking an entry complete before acknowledgement risks loss; leaving it unmarked after successful publish can lead to a duplicate, which is safer if consumers are idempotent.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

5. Make consumers safe to repeat

Store processed event IDs durably, often in a deduplication table with a uniqueness constraint, and apply the event’s business effect in a transaction that also records the ID. If a consumer crashes, this arrangement prevents it from applying the same event effect twice. Where possible, make operations naturally idempotent—for example, setting a status to a specified value rather than blindly incrementing a counter.

6. Operate the outbox as production data

Monitor the age of the oldest unpublished event, relay lag, retry counts, duplicate rates, and broker queue depth. Set retention, cleanup, archival, and replay procedures. Keep enough information to investigate and recover failures without retaining event data indefinitely by accident.

Exercise failure points deliberately in system-level tests: after the local commit, after broker publication but before progress is recorded, and during consumer retries. Those cases expose whether the system loses events, produces duplicates safely, or violates an ordering rule.

Also popular on Amazon
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Should I use a polling publisher or CDC?

Polling reads pending rows from an outbox table; change data capture (CDC) reads committed database changes from a transaction log or native change feed. Both can relay durable changes, but they differ in latency, database load, event modeling, and operational demands.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Approach How it finds events Strengths Trade-offs
Polling publisher Periodically queries committed, unprocessed outbox rows. Easy to understand; works with ordinary relational transactions; uncompleted rows remain durable and can be retried. Latency depends on polling interval and batch size; queries and cleanup use database capacity; ordering needs explicit handling.
Transaction-log tailing or CDC Reads changes from a database log or native change feed. Can avoid repeated table scans and may use database-native change delivery. Requires database-specific capabilities and operational knowledge; event meaning may need reconstruction; offsets, schemas, streams, replication slots, or equivalent components need management.

A polling relay usually provides a visible application-level event record. Teams can inspect what is waiting, retain or replay selected rows, and define the event contract directly. Its costs are polling load, cleanup work, and latency introduced by its polling schedule.

CDC can be useful when database changes themselves are the integration contract or when a native feed is already part of the platform. It is not automatically an application-event system: a row update may not say clearly whether a business event occurred, and reconstructing event meaning from database changes can couple consumers to schema details.

PostgreSQL logical replication, for example, uses a publisher-subscriber model: it sends an initial snapshot and then changes as they occur, applying changes in publisher order within a subscription. PostgreSQL also documents possible conflicts when multiple subscribers write to the same replicated tables. The linked documentation is for PostgreSQL 13, which is marked unsupported; check documentation for the PostgreSQL version actually deployed before relying on version-specific behavior.

Choose based on the event contract and operational capacity, not the assumption that CDC eliminates reliability work. Either route still needs a clear acknowledgement boundary, recovery behavior, and consumer handling for repeated delivery.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I prevent duplicate events?

Assume that a relay may publish an event more than once. If it crashes after the broker accepts a message but before the relay records success, it may retry the same event after restarting. The outbox makes the source change and event record atomic; it does not make the broker publish and the relay’s progress update one atomic operation.

The usual honest guarantee is at-least-once delivery: an event remains retryable until the relay knows it was accepted, but a retry can create a duplicate. The pattern’s description calls out this crash scenario and the need for idempotent consumers. AWS also notes that standard SQS delivery can deliver the same message more than once in its guidance.

Also popular on Amazon
BENFEI USB C Hub 5-in-1 with 4K HDMI(Certified), 100W Power Delivery, 3 USB-A, Silicone Cable, Aluminum Case Compatible with MacBook Pro/Air, iPad Pro, iMac, iPhone 15 Pro/Pro Max, XPS, Thinkpad
  • Portable and powerful USB-C HUB: BENFEI USB Type-C HUB, with super-soft and knot-free silicone woven design cable, meets most mobile office needs. Compact, lightweight, stylish, and powerful portable USB C Hub equipped with 1 x HDMI port, 1 x 100W charging, and 3 x USB ports. 18-month warranty, 24-hour response, to ensure you feel at ease when using our product.
  • Design centered on comfort and reliability: Thanks to BENFEI's end-to-end in-house cable production capability, in-house PCBA and assembly capability, using the industry's most advanced silicone woven design and process, 20cm cable in length, no knots, super-soft, the HUB is easy to use in all scenarios: laptop, tablet, stand etc. Super-soft, 25000+ life cycles, to meet your daily carrying and office needs.
  • 100W Charging: Support up to 90W USB C pass-through charging via Type-C port to keep your laptop powered. 10W is reserved for other interface operations. No data and video function on the Type-C port.
  • 4K HDMI Display: The HDMI port supports media display at resolutions up to 4K 30Hz, keeping every incredible moment detailed and ultra vivid. Please note that the C port of the Host device needs to support video output.
  • Transfer Files in Seconds: Transfer files and from your laptop at speeds up to 10 Gbps with USB A 3.2 port. Extra 2 USB A 2.0 ports are perfectly for your keyboards and mouse.
  • Assign each logical event a unique ID once, when creating the outbox record. Do not generate a new ID for every relay attempt.
  • Record processed IDs durably at the consumer and make the deduplication record atomic with the consumer’s business effect.
  • Use idempotent state-setting operations where appropriate, while recognizing that not every business action can be made idempotent by changing its shape.
  • Use aggregate IDs and sequence numbers to identify stale or repeated updates when the domain needs them.
  • Include retries, broker acknowledgements, and dead-letter or quarantine handling in the documented delivery contract.

“Exactly once” needs a narrowly stated scope. A broker may offer exactly-once behavior for a specific operation or boundary, but that does not by itself guarantee that a consumer’s database effect happens exactly once across independent systems and failures. The outbox should not be described as an end-to-end exactly-once guarantee.

How should I preserve event order?

Ordering is a separate design requirement from atomic persistence. If one order changes in transactions T1 and T2, consumers may need its events E1 and E2 in that same order, but a general-purpose outbox does not automatically guarantee delivery order across all entities or all workers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Define the scope first: per aggregate, per broker partition, per session, per subscription, or global. Global order is a much stronger requirement than most business workflows need. A common design preserves order for one entity while allowing unrelated entities to progress concurrently.

  • Store an aggregate version or monotonically increasing sequence with each event.
  • Partition messages by aggregate ID, or use the broker’s session mechanism where available.
  • Ensure relay workers do not advance the same aggregate out of order; use safe coordination or a single ordered worker for that scope.
  • Define consumer behavior for a missing sequence, a stale event, or an earlier event that is retried, dead-lettered, or rejected.

Azure Dataverse guidance says Service Bus sessions provide ordering within a session, not globally, and recommends application-level sequence numbers when missing or out-of-sequence events matter. See the Dataverse transactional outbox architecture. PostgreSQL’s publisher-order behavior is likewise scoped to a subscription, not a universal ordering promise.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When is an outbox not enough?

An outbox solves reliable outbound publication from one service-owned transaction. It does not make several independently owned databases one ACID transaction. If a business workflow requires multiple services to change their own data, coordinate those steps as a distributed workflow—commonly a saga—instead of stretching one local outbox beyond its boundary.

A saga makes progress through explicit steps and needs defined behavior for retries, timeouts, failures, and compensating actions. Each participating service can still use an outbox to publish its own commands or events reliably; the saga coordinates the larger workflow and tracks its state.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Two-phase commit may be available in a narrow environment, but it depends on support from the participating database and broker and couples them to one distributed transaction. The outbox pattern guidance treats this as a specialized alternative, not a default repair. AWS recommends sagas or transaction-level handling when work spans multiple services in its architecture guidance.

Also popular on Amazon
𝟒𝐏𝐚𝐜𝐤 𝐔𝐩𝐠𝐫𝐚𝐝𝐞𝐝 USB to USB C Adapter,Type-C Female to A Male Charger Converter for iPhone 18 Charger,iWatch Ultra SE 9 10,iPhone 17 Pro Max 16 15 14,Samsung S25,AirPods,iPad,Car,Xbox
  • 【Read before You Buy】 Note: This adapter is USB 2.0 version and cannot transmit HDM, VGA, or other video signals. Nevertheless, they are fully capable of charging devices,duplicating files, and can be seamlessly integrated with USB-C earphones, wireless network adapters, and SD card adapters.
  • 【Easy to Use and Safe】Thanks to modern manufacturing techniques, we've made these adapters sufficiently compact so that they can remain inserted in your device without noticeable protrusion or inconvenience. This means you don't have to constantly plug and unplug them, reducing the likelihood of wear and misalignment, and making them more convenient to carry around.
  • 【Reliable Quality】Engineered for enhanced durability, durable aluminum alloy shell material,get excellent wear resistance and heat dissipation,the male USB C and female USB connectors & the male USB and female USB C connectors are designed to be plugged and unplugged up to 20000 times. Provides data transfer, device charging, memory space expansion, and additional computer peripherals.
  • 【Think more for you】Do you need to connect a USB-C-enabled device to an odd device that only has USB-A ports? Then these USB-A male to USB-C female adapters are made for you.Simply insert the adapter into the USB-A port on the device, and you can instantly connect your USB-C device to the device that originally didn't have the correct connection port.
  • 【Trusted xiwxi Quality and Service】As a responsible brand seller, you will receive xiwxi's 12-month Quality assurance and lifetime friendly customer service, you're not just buying a product,you're investing in peace of mind with all-round quality and exceptional customer service.

What changes for Cosmos DB, PostgreSQL, and Dataverse?

The pattern is general, but the atomicity boundary and relay options depend on the database and platform. Check the supported transaction scope before choosing where the business object and event will live.

Azure Cosmos DB

Microsoft’s Cosmos DB example writes the business object and event in the same transactional batch, then uses Change Feed and Service Bus for background publication. A Cosmos DB transactional batch is atomic only within one logical partition; it cannot write documents in different containers or logical partitions as one batch. The partition key is therefore part of the consistency design, not only a scaling decision. The Microsoft Cosmos DB architecture describes reliable messaging, ordering, deduplication support, and TTL-based cleanup, while noting that its sample is not production-ready and has multithreading limitations. Treat the sample as an architectural illustration rather than a drop-in production implementation.

PostgreSQL

Logical replication is a database-change delivery option: it begins with a snapshot and streams later changes. It may suit integrations that need replicated row changes, while an application-level outbox is better suited to an explicit business-event contract. The PostgreSQL 13 logical replication documentation is for an unsupported release, so confirm details in documentation for the supported version in use.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Dataverse and Azure Service Bus

Microsoft’s Dataverse reference architecture writes an outbox record in the same transaction as the source record and uses an asynchronous plug-in to send messages to Azure Service Bus. Its operational recommendations include Azure Monitor metrics, Application Insights traces, retries, dead-letter handling, and application-level sequence numbers where needed. See the Dataverse reference architecture.

What should I check before putting an outbox into production?

Use this checklist to validate the whole delivery path, not only the database insert:

  • Ownership: Is there one clearly identified source of truth and service responsible for the business transaction?
  • Atomicity: Are the state change and outbox entry committed in one local transaction, within the database’s actual transaction scope?
  • Event identity: Does every event have a stable ID, aggregate ID, type, timestamp, and schema version? Is a sequence included when required?
  • Relay recovery: Can the relay safely restart, retry, and resume from durable progress without losing unacknowledged events?
  • Consumer behavior: Is deduplication durable and coordinated with the business effect? Can the consumer tolerate retries?
  • Ordering: Is the promised scope explicit, and does it match the relay, broker, and consumer behavior?
  • Poison events: Is there a quarantine or dead-letter path, with a procedure to inspect and recover rejected messages?
  • Observability: Are outbox age, relay lag, retries, duplicates, and queue depth visible to operators?
  • Retention and replay: Are cleanup, archival, retention, and replay rules defined before old entries accumulate?
  • Failure exercises: Have you verified crashes after commit, after broker publication but before recording success, and during consumer retries?
  • Workflow boundary: If multiple services must change state, is a saga or another explicit cross-service workflow coordinating them?

Frequently Asked Questions

Should an outbox event contain a full snapshot or just an entity ID?

There is no universal payload shape established by the pattern. A self-contained event can reduce consumers’ dependence on later reads, while a reference keeps messages smaller but requires the referenced data to remain available and suitable for the consumer’s purpose.

Can I use the outbox to replay events after a consumer outage?

Potentially, if the event records or an archive are retained and the consumer can safely process them again. Replay needs an explicit retention and offset strategy, because cleanup rules that are safe for routine delivery may remove data needed for recovery.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Should every database table change create an outbox event?

No. Emit events for meaningful facts or changes that other components need to act on, rather than treating every low-level row mutation as a public contract. This keeps consumers less coupled to internal schema details.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply. Prices as of November 8, 2026 12:27 am GMT.