Meta-PokéBase Q&A
0 votes
117 views

Sometimes in chat, i see two messages and later I look back and see the order has reversed.
For example-
Person 1: hello
Person 2: hi
a few minutes later, i check back and the order has changed to
Person 2: hi
Person 1: hello
Why does this happen?

by

2 Answers

3 votes
 
Best answer

Let's put it this way. When you send a message, it takes some time to reach the server, and then the server adds that message as the newset message in the chatlog. However, on your screen, you don't need to wait that time; it's immediately going to show up as the newest message.

Now let's assume someone else's message reaches the server before yours. That means that, chronologically, his message is older than yours. The server will then tell you someone else sent a message, but in your perspective, that message was sent AFTER you sent yours, meaning on your screen, that message will be the newset one, not your own message.

So it'll look something like this:
Let's assume time starts at t = 0
At t = 1, Person A sent a message
At t = 2, you sent your message, and the server receives Person A's message. Your screen shows that you have the newset message.
At t = 3, the server receives your message. At the same time, you receive Person A's message as an update from the server. Your screen shows that Person A now have the newset message, but the server received your message just now, putting your message as the newest message.
At t = 4, Person A receives your message as an update from the server.

Now let's assume you reload the page. The server will have to send the entire chatlog (or what's still visible) to you, meaning you will see what the server chronologically received. This means that, in your point of view, your message will now appear as the newest, thus seeming like they "swapped".

This is probably a gross oversimplification.

TLDR: The messages take time to get to the servers and update everyone else's devices, but for you, you sent the message instantly. When you reload, you sync up with the server, which may seem like messages have "swapped".

by
selected by
but what about when the swapping is between other peoples messages?
It's because those other messages are already displayed in the proper order.
The best way to visualize this might be to say you have a situation where one message is being sent per minute (plenty of time for you to receive it in the correct order) and then suddenly two people send a message at the same time, and then they return to one message per minute, those two messages sent at the same time might "swap" when you refresh, but the rest won't because they were already in the correct position.
2 votes

Network latency. If you've ever played an online video game and seen visible "lagging" (often called 'rubber banding') it's a similar phenomenon. The client (you) is receiving the messages in the wrong order, and when you refresh the page they're being retrieved from the server in the order they were actually sent according to their logged timestamps.

When messages are coming in live, they're coming in the order you receive them. But when you connect to the chat, you're retrieving messages from the server. So page refreshes ignore the order you originally received them.

by
yea latency is the official terminology but I wanted to explain it in simpler terms so others can understand