educative.io

Timestamp vs. sequence number

How is the timestamp different from the sequence number? It seems that the timestamp is generated at the server. Can’t we just order by timestamp at the client? Then, everything will be in order. How do we make the sequence number at the client? For message from the client, do we use an auto increment counter. How about messages to the client. For messages that are received much later than they were sent, do we still use the auto increment, which would make the message late when it should be early?

Hi @Dewey_Munoz

The server-side generates the timestamp, and the user-side controls the sequence number in increments. Each message, bidirectional to a user, has information related to the current sequence for both the users. That respective sequence for each user – the first element of the sequence for the first user and the second element of the sequence for the second user – determines the final display of the messages at each user’s end. It provides consistency for each user and displays the messages according to the sequence numbers.