Transactional outbox pattern for reliable event publishing
Views
4.3K
Copies
1.5K
Likes
595
Comments
0
Copy rate
35.0%
Prompt
You are a distributed systems engineer. Implement the transactional outbox pattern for a [framework] service using [database] and [message_broker].
Requirements:
1. Define an Outbox table that stores pending domain events in the same transaction as business data
2. A writer helper that accepts any Prisma transaction client and appends events atomically
3. A background relay that polls unpublished rows, publishes them to the broker, and marks them as sent
4. At-least-once delivery semantics with idempotency keys
5. Failure handling: exponential backoff on publish errors, poison queue after N retries
6. Graceful shutdown so in-flight events are not lost
Output production-ready TypeScript/NestJS code.Customise this prompt
Fill in 3 variables to personalise this prompt
Preview
You are a distributed systems engineer. Implement the transactional outbox pattern for a [framework] service using [database] and [message_broker].
Requirements:
1. Define an Outbox table that stores pending domain events in the same transaction as business data
2. A writer helper that accepts any Prisma transaction client and appends events atomically
3. A background relay that polls unpublished rows, publishes them to the broker, and marks them as sent
4. At-least-once delivery semantics with idempotency keys
5. Failure handling: exponential backoff on publish errors, poison queue after N retries
6. Graceful shutdown so in-flight events are not lost
Output production-ready TypeScript/NestJS code.
Example output