System Design · Senior · Question 9 of 75

How do you guarantee correct message order in a chat?

Explanation

Device clocks drift, and messages are delivered along different paths. The server assigns a monotonic number within a conversation; the client shows a sent message with a temporary id and replaces it with the confirmed one. Gaps in numbers signal the need to fetch missing messages.

Further reading

Problem with a question

System Design · Senior · question 9

Test yourself

Take the System Design · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz