Skip to content

Expose the outbox insert sequence to consumers as a message header #358

Closed

Description

@thomhurst

Consumers that keep a projection need a monotonic value per ordering key to reject stale or redelivered events ("apply only if newer than what I stored"). Today an application has to produce that value itself, usually with a counter row per aggregate that every writer locks. Ordered lanes now follow a database-assigned insert sequence (#353, shipped in #366 at c548832, D50). The remaining work is to project that value into dispatch and carry it on the message; OutboxRecord does not currently expose it.

Prerequisite #353 is complete; there is no remaining dependency on it.

Proposal

  • When an ordered row is dispatched, add its insert sequence as a header under the relayer. prefix.
  • Expose it on the consume side as a typed, lazily read value on the message context, absent when the producer did not supply it.
  • Document what it guarantees: increasing in commit order for sequential transactions on one ordering key from one outbox table; not gap-free; not comparable across outbox tables or tenants; no defined order for genuinely concurrent transactions.

Acceptance criteria

  • Real-PostgreSQL test: two sequential commits for one ordering key are received with increasing sequence values, including when the later commit has the smaller UUIDv7.
  • The header is written without a per-message string allocation; state the per-message cost in the PR.
  • Unordered routes either omit the header or document that the value carries no ordering meaning there.
  • website/docs/reference/ordered-dispatch.md shows a version-guarded consumer using the value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area: outboxenhancementin-progressphase-2: outbox

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions