Messagingsequence idmonotonic countermessage sequence

Sequence number

Definition

A sequence number is a monotonically increasing value assigned to each message within a scope, such as a conversation, partition or entity, so its position relative to others is known.

In practice

Networks and consumers reorder and repeat messages, and wall clocks on different machines disagree. A counter assigned by one authority per scope gives an unambiguous order: chat apps sort messages by the conversation's sequence, clients sync with "everything after 1,204", and consumers drop an update whose number is not newer than the one already applied. TCP uses the same idea per byte.

The number must come from a single writer per scope, such as the database row or partition leader, or two writers will hand out the same value. Gaps can be legitimate (a failed transaction consumed a number), so treat them as a hint to resync rather than proof of loss. Global sequences across everything become a bottleneck; scope them narrowly.

Example

A client last saw message 1,204 in conversation c-77; after reconnecting it asks for after=1204 and receives 1,205 to 1,219 in order.