Skip to main content

Async processing

Two durable mechanisms and one that does not survive a crash.

MechanismProcessSurvives process crashFailure
Prisma outbox, @OutboxHandler consumersDispatcher only on the workerYes. The row commits with the business writeRetried per consumer, reported to Sentry
Bull queueWorker processorsYes. RedisBull attempts, Sentry on the last one
@OnLocalEvent listenersListeners loaded in the emitting processNoReported 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​

OutboxDispatcherService:

BehaviorValue
PollEvery 1 second
ClaimBatch 100, FOR UPDATE SKIP LOCKED
Dispatch concurrency10 events
ConsumersEvery @OutboxHandler for the event type, found at startup by OutboxHandlerRegistry
Per consumerIdempotentEventHandlerService: 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
SuccessAll consumers succeeded or were already done: status PROCESSED. No consumers: PROCESSED
Consumer throwOther consumers still run. Attempts increment, stay PENDING until 10, then DEAD. lastError lists consumer: message
ReportingreportError on attempt 1 and on DEAD (level fatal), tagged event.type, consumer, attempt, tenant
Backoffmin(60_000, 2^attempts * 1000) ms
Stale PROCESSINGOlder than 5 minutes returns to PENDING without incrementing attempts
PurgePROCESSED older than 30 days, batches of 5000, max 20 batches. Cron 03:00
ProcessedEvent purgeOlder 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.

Pool starvation

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.

NameProducerListener
channel.createdChannelServicechannel location auto-bind
channel.updatedChannelServicewebhook health
audit.logaudit interceptor, WooCommerce webhook healthAuditLogListener
product.content.changedproduct event publisherProductEmbeddingListener
product.channel-allocation.changedproduct eventsProductStockSyncListener
return.status.changedreturn commandnone
return.stock.restoredreturn inventorynone
No consumer

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.

Details: Events, Queues and ADR-0001.