Add lastSequenceNumber bigint to conversations (or a counter table) and assign each new message sequenceNumber = ++counter inside the same transaction that persists the message, using UPDATE ... RETURNING / row lock. Must be correct under concurrent senders and horizontal scaling.
Acceptance criteria:
- Sequence numbers are gapless and strictly increasing per conversation
- Concurrent sends do not produce duplicate sequence numbers
- Assignment happens atomically with message persistence
Add
lastSequenceNumberbigint toconversations(or a counter table) and assign each new messagesequenceNumber = ++counterinside the same transaction that persists the message, usingUPDATE ... RETURNING/ row lock. Must be correct under concurrent senders and horizontal scaling.Acceptance criteria: