I’m currently studying Elixir/Phoenix while using it for a hobby project.
I have a mobile messaging app that connects to a single node Phoenix server.
Upon making a connection to the server, the server will send a list of messages to the client app.
Can we expect messages to be received in the same order as the server sent them?
Pubsub is very easy, it just keeps a list of subscribers an dispatches events to them:
def dispatch(entries, from, message) do
for {pid, _} <- entries, pid != from do
send(pid, message)
end
:ok
end
So the question is, does erlang guarantee ordered messages:
10.8 Is the order of message reception guaranteed?
Yes, but only within one process.
If there is a live process and you send it message A and then message B, it’s guaranteed that if message B arrived, message A arrived before it.
On the other hand, imagine processes P, Q and R. P sends message A to Q, and then message B to R. There is no guarantee that A arrives before B. (Distributed Erlang would have a pretty tough time if this was required!)