qeled / discordie

Predictable JavaScript abstractions for Discord API.
https://qeled.github.io/discordie/
BSD 2-Clause "Simplified" License
190 stars 45 forks source link

Text Que out of order #29

Open Ryu945 opened 8 years ago

Ryu945 commented 8 years ago

Occasionally, the text que will get out of order. For example, out of 100 messages sent in a row, two neighbouring messages will be swapped with each other once. This happens consistently.

qeled commented 8 years ago

If you mean this is happening when sending messages - Discord uses snowflakes which is a distributed system which means order within couple tens milliseconds is not guaranteed.

See more here: https://github.com/twitter/snowflake/tree/b3f6a3c6ca8e1b6847baa6ff42bf72201e2c2231

We have a number of API resources that assume an ordering (they let you look things up "since this id").

However, as a result of a large number of asynchronous operations, we already don't guarantee in-order delivery.

We can guarantee, however, that the id numbers will be k-sorted (references: http://portal.acm.org/citation.cfm?id=70413.70419 and http://portal.acm.org/citation.cfm?id=110778.110783) within a reasonable bound (we're promising 1s, but shooting for 10's of ms).

Ryu945 commented 8 years ago

Is there a way to fix it like put a required delay between every message sent to lower the probability/stop this from happening?

macdja38 commented 8 years ago

@Ryu945 if it's imperative it does not happen you could always manually add a setTimeout to your 2nd message or send it on the callback of the first message. These could both become harder to implement in a more complex system though.

Ryu945 commented 8 years ago

Thanks for the information. I might have to add that. I posted here because I thought achieving correct message order in synchronus code was something the API would be interested in programming in.