Async processing
Two durable mechanisms and one that does not survive a crash.
| Mechanism | Process | Survives process crash | Failure |
|---|---|---|---|
Prisma outbox, @OutboxHandler consumers | Dispatcher only on the worker | Yes. The row commits with the business write | Retried per consumer, reported to Sentry |
| Bull queue | Worker processors | Yes. Redis | Bull attempts, Sentry on the last one |
@OnLocalEvent listeners | Listeners loaded in the emitting process | No | Reported to Sentry, never retried |
Do not replace an outbox enqueue with a local event for a side effect that must happen. A listener registered only on the worker will not see an API emit, and the emit is not transactional.
Dispatcher
| Behavior | Value |
|---|---|
| Poll | Every 1 second |
| Claim | Batch 100, FOR UPDATE SKIP LOCKED |
| Dispatch concurrency | 10 events |
| Consumers | Every @OutboxHandler for the event type, found at startup by OutboxHandlerRegistry |
| Per consumer | IdempotentEventHandlerService: inserts ProcessedEvent (event, consumerName), optionally locks the order, then calls the handler with that transaction. A transactional: false consumer is called with no transaction open and recorded after it returns |
| Success | All consumers succeeded or were already done: status PROCESSED. No consumers: PROCESSED |
| Consumer throw | Other consumers still run. Attempts increment, stay PENDING until 10, then DEAD. lastError lists consumer: message |
| Reporting | reportError on attempt 1 and on DEAD (level fatal), tagged event.type, consumer, attempt, tenant |
| Backoff | min(60_000, 2^attempts * 1000) ms |
Stale PROCESSING | Older than 5 minutes returns to PENDING without incrementing attempts |
| Purge | PROCESSED older than 30 days, batches of 5000, max 20 batches. Cron 03:00 |
ProcessedEvent purge | Older than 90 days, same batching |
A consumer that succeeded is not called again when another consumer of the same event fails. A transactional consumer commits its writes with its ProcessedEvent row. A transactional: false consumer is at least once and must be safe to repeat.
A transactional consumer that runs queries outside its transaction holds one pool connection idle per in-flight event while it waits for another. With 10 events in flight and a pool of 10, nothing can proceed and every transaction times out after 5 seconds. Declare such a consumer transactional: false; the decorator refuses a consumer that takes no transaction parameter without it.
DEAD rows are not automatically returned to PENDING. There is no replay tool yet.
Local events
Best effort, in the emitting process, through EventEmitter2. Listeners use @OnLocalEvent, which catches, logs and reports a failure without rethrowing. A bare @OnEvent fails yarn architecture:check.
| Name | Producer | Listener |
|---|---|---|
channel.created | ChannelService | channel location auto-bind |
channel.updated | ChannelService | webhook health |
audit.log | audit interceptor, WooCommerce webhook health | AuditLogListener |
product.content.changed | product event publisher | ProductEmbeddingListener |
product.channel-allocation.changed | product events | ProductStockSyncListener |
return.status.changed | return command | none |
return.stock.restored | return inventory | none |
return.status.changed and return.stock.restored are emitted with no listener. Move them to the outbox before attaching a side effect that must happen.