riker-rs / riker

Easily build efficient, highly concurrent and resilient applications. An Actor Framework for Rust.
https://riker.rs
MIT License
1.04k stars 69 forks source link

Message Order Guaranteed? #140

Open jbabyhacker opened 4 years ago

jbabyhacker commented 4 years ago

If you have a system with two actors, A and B. Actor A is repeatedly sending messages very quickly to Actor B. Will Actor B always receive the messages in the same order Actor A sent them? For example, sending messages 1,2,3,4,5 from Actor A to Actor B where 1 is sent first and 5 is sent last. Does Riker guarantee Actor B to receive 1,2,3,4,5 and not 1,2,4,3,5?

hardliner66 commented 4 years ago

In the current implementation messages should always arrive in the order they are sent. But, if I understand correctly, Riker (the project) itself does not guarantee any messaging order, which means that you should not rely on a guaranteed message order because it could change in the future.

Maybe @leenozara can say a bit more about this topic.

For the future it would be nice if we could provide this guarantee, so that people can rely on causal message ordering.

jbabyhacker commented 4 years ago

Thanks. I'm glad the order is maintained in the current implementation. I would be nice if the project would consider providing this guarantee.

leenozara commented 3 years ago

Message order is guaranteed by sender-receiver pair. Messages sent by ActorA to ActorB will not be received out of order. This is implicit from guarantees 2 and 3 in https://riker.rs/actors/#message-guarantees. I.e. An actor instance handles only one message at a time, so it can only place a message on a receiving actor's mailbox one at a time. Actors process the messages in the order they are received.

This only applies to user-level messages. System messages are processed ahead of user messages, but they too are processed in the order they are received.

Riker message guarantees are per Actor System (local only). We will keep these guarantees but they won't be extended to remote systems when we introduce remoting.