educative.io

How does the messenger maintain the sequencing of the messages?

I think you really need to provide an example of this like one of the posters above stated. Im sure many are confused by how you worded it and a clear EXAMPLE, not a copy paste from what you’ve written in the course, would help tremendously. Please and thank you.

4 Likes

Hey, @Sorabh,

How did you come with the order on client side ?

@Design_Gurus: Can you please explain this with an example? I am still unable to understand.

Can you explain the solution to me in detail? I am still unable to understand

@Design_Gurus Does it mean that clients are producers and there is a consumer process at the server-side that consumes incoming messages one by one?
Moreover, is there only one consumer process at the server-side? Or someway else?

@Design_Gurus
I must say that the article leave a lot for guessing. Diagrams are your friends , use them instead of copy pasting already confusing paragraphs from the article. The sequencing is totally confusing. Is it a client that generates the sequence number or the chat server ?
How is chat stored in Hbase ? what is the key ? UserId is not sufficient.
You have interchangeably used client and user, making it more confusing.
There is no mention of how read/write path would work with Hbase row.

Giving different order of messages to different users can create confussion.
For Example : 2 people are deciding on something, A propose X and B propose Y at the same time.
In A window X come before Y and in B window Y come before X. Both of them being polite return with :+1: now for A Y is decided but for B X is decided.

This is a simple example but in the real world, this type of confusion can happen.

@Design_Gurus, what if we have a group chat, are we going to store a separate sequence number for each user in the group for every message?

Interesting that our answer to this problem is to not have a single source of truth whats-so-ever and instead have two clients with different ideas of ordering. I would have expected a solution that allowed for temporary misordering in the short term and once clients resolved with the server for source of truth to re-order them. This is what I’ve seen most messaging apps do.

We wouldn’t expect this forum for instance to show a different ordering for each user, right?

this link distributed computing - How does the messenger maintain the sequencing of the messages during chat and when users log in again? - Stack Overflow
explains the questions exactly. The author’s example is bad and did not explain the question clearly at all.

1 Like

@Design_Gurus You are answering the same things present in the course? We have paid to take this course and would appreciate your detailed explanation here.

@rahul9 Hello Rahul, Can you explain what you understood?

Any update? thank you

To the people confused about why timestamps are not useful for ordering: The problem is that the two clients’ devices’ clocks will most likely not be in sync with each other. For example, User A’s phone may have a clock that runs fast compared to user B. If this is the case, when messages are sent at about the same time, the message ordering will always place User A’s messages below user B’s. This will happen even if user A sent their message first. This will also cause user B’s message to appear ABOVE user A’s most recently sent message at times which could be confusing. If the clocks are particularly out of sync, we could potentially see some really wild ordering results.

The proposed solution isn’t perfect in that we don’t get a single source of truth for ordering. However, it does give users a consistent ordering without unexpected behavior from their point of view. It also requires the least network calls out of any of the schemes I’m able to think of which is very beneficial in an environment like this product’s where the network activity is very high.

3 Likes