I was following an app example from RockTheJVM (Daniel Ciocîrlan): https://blog.rockthejvm.com/akka-cassandra-project/
For implementing API Rest it uses Akka Http. To access Cassandra it uses Doobie.
When a request wants to create a bank account the implementation sends a message to an akka actor, then the actor create the account in Cassandra. It is something like this:
POST Request -> Akka Http endpoints -> Actor (ask/pipe pattern) -> Doobie -> Cassandra
My question is what's the benefit or advantages of using actors? Is it because of Akka Persistence? Why if I don't want or don't need Akka Persistence, an implementation like this:
POST Request -> Akka Http endpoints -> Doobie -> Cassandra
Is there any benefit of adding actors without using Akka Persistence?
CodePudding user response:
The main reason is separation of concerns. Each step in the actor-based version has a different role.
The Akka Http endpoints
process REST(HTTP) requests and turn them into application operations (Akka messages).
The Actor (ask/pipe pattern)
implements the application operations. This uses one or more database operations, internal state, and information from other parts of the application (other Actors).
The Doobie
element is just responsible for implementing database operations.
With the shorter pipeline you have a single element that is mapping REST API calls directly to database accesses, which is inflexible and (trust me on this one, I have the scars) leads to poor system design.