https://github.com/zehelein/pg-transactional-outbox
A library to implement the transactional outbox pattern for PostgreSQL, a message broker or event stream, and TypeScript.
https://github.com/zehelein/pg-transactional-outbox
inbox inbox-pattern logical-replication microservices nodejs outbox outbox-pattern postgres postgresql transactional-inbox transactional-outbox typescript
Last synced: 8 months ago
JSON representation
A library to implement the transactional outbox pattern for PostgreSQL, a message broker or event stream, and TypeScript.
- Host: GitHub
- URL: https://github.com/zehelein/pg-transactional-outbox
- Owner: Zehelein
- License: mit
- Created: 2022-12-29T15:19:56.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-10-10T21:09:31.000Z (8 months ago)
- Last Synced: 2025-10-12T10:56:01.553Z (8 months ago)
- Topics: inbox, inbox-pattern, logical-replication, microservices, nodejs, outbox, outbox-pattern, postgres, postgresql, transactional-inbox, transactional-outbox, typescript
- Language: TypeScript
- Homepage:
- Size: 1.38 MB
- Stars: 31
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# pg-transactional-outbox
The transactional outbox and transactional inbox patterns are used to ensure
exactly-once processing of messages in event-driven architectures, where the
loss or duplication of a message could have significant consequences. This
library guarantees that a message is sent at least once, but processed exactly
once, and is useful in scenarios where the reliability and atomicity of message
processing is important. This pattern is an alternative to distributed
transactions using a two-phase commit, which can lead to bottlenecks with a
large number of microservices communicating with each other.

_Message delivery via the PostgreSQL-based transactional outbox pattern
(generated with Midjourney)_
## Library
This `pg-transactional-outbox` library implements the mentioned transactional
outbox and transactional inbox pattern for PostgreSQL. It stores the outgoing
messages reliably as part of your business logic DB transactions. It stores
incoming messages exactly once and lets your handlers process them exactly once.
The `./lib` folder contains the `pg-transactional-outbox` library and unit
tests. You can find an introduction to the transactional outbox and inbox
pattern in the [README.md](./lib/README.md). This should be your starting point.
## Integration Tests
You can find the integration tests in the `./__tests__` folder. This folder
includes outbox listener and inbox listener integration tests that use a
PostgreSQL instance for the actual tests. Check the
[README.md](./__tests__/README.md) file for further details.
## Examples
The `./examples` folder contains example implementations using actual message
brokers like RabbitMQ.
Currently, there is an example of how to implement the transactional outbox and
inbox pattern when using RabbitMQ as the messaging broker. You can find more
details in the [README.md](./examples/rabbitmq/README.md).