Transactional outbox in Node (DB write + event)

12909
0

The moment you split ‘write to DB’ and ‘publish to a queue’ into two independent operations, you create a place to lose data. Publish first and a DB failure means consumers act on something that never happened. Write first and a publish failure means the system becomes inconsistent. My default is the outbox pattern: insert an outbox row in the same BEGIN/COMMIT transaction as the business write, then publish asynchronously with retries + a deterministic dedupe_key. It’s boring, but it’s correct. I also keep outbox payloads minimal integration events (not an internal state dump) to reduce coupling and make replays safe.