If the supervisor and its child actors are sharing the same messages, which is the right place to keep those case classes? Should it be in both Supervisor and the individual actors or should it be in a separate file? I have read that the best practice is to keep it in the companion object of the actor.


If child actors are short-lived workers, while supervisor is some static service - better put all messages it accepts in the supervisor's companion object along with the props factory. All clients will see it as the supervisor's protocol. Workers being hidden behind their supervisor.

But if you have a set of messages that pass between your actors across the system - you better put them in some separate file (and object) like TcpProtocol. Then you can import TcpProtocol._ in any actor and use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.