Decision 1Return 202 only after the transaction commits
Alternatives consideredRespond immediately and enqueue asynchronously; hold the request open until delivery succeeds.
WhyOne MongoDB transaction writes the ingress receipt, every fan-out delivery and the audit record. If it commits, the work exists; if it doesn't, nothing does.
Decision 2Use MongoDB as the queue instead of a broker
Alternatives consideredBullMQ + Redis; QStash.
WhyKeeping the queue in the same transactional database as the ingress receipt removes the database-to-broker dual-write gap entirely. At higher volume, the answer is a broker fed by a transactional outbox, not a dual write.
Decision 3Leases with fencing tokens instead of locks
Alternatives consideredLong-held locks; trusting one worker per job.
WhyWorkers reserve a delivery with an atomic compare-and-set and a 60-second lease. Completion is fenced by the lease token, so a stale worker cannot overwrite its replacement's result.
Decision 4Be honest about at-least-once delivery
Alternatives consideredClaim exactly-once.
WhyRelay can't prove a receiver did not accept a request before a worker crashed, so it doesn't pretend to. Every request carries a stable relay-event-id for the receiver to deduplicate on.
Decision 5Idempotency keys with content fingerprints
WhyA unique workspace + idempotency-key index resolves concurrent duplicates at the database level. Reusing a key with a different payload returns 409. The fingerprint uses canonical JSON, so key order doesn't matter.