Reputation: 748
I haven't come across many examples of combining Play with an akka-cluster backend AND a NoSql store like Cassandra, so I have some uncertainty in the implementation of such a system.
For the sake of being concrete, instead of abstractly describing the setup, i've come up with an example that represents a whole class of problems in which play and akka can shine:
consider: A database-backed (lets use Cassandra cluster) road trip app, where as you travel, it recommends points of interest. User has account, inputs settings, and some preferences. Theres a trip dashboard view that includes trip history, etc. The plan is to use Play and Angular for the web app, and most of the web app is a simple case of pulling user data and POI data from database and templating, updating views. However, the algorithms that compute and rank the POI in the area make akka-cluster and the actor model a compelling solution. it needs the user-data (updated daily) and the POI data (updated by location) as input then runs the algorithm based on that data.
Summary: - A play frontend that serves requests, and calls a service that is backed by database to fulfill request (get user data, template, etc) - An akka cluster backend that gets a request from the frontend(or client) to rank points of interest in the area based on user data, i.e. preferences, age, history. this also needs database access via an actor.
part of the discussion might necessarily include what is optimal for the chosen datastore, but here are high level solutions:
delegate all data access duties to the akka cluster, with Play merely forwarding both "get some data" requests as well as "do some calculations based on data x,y and z" requests to the backend. this eliminates multi-tenancy confusion
keep all the basic requests to fill templates with datastore data in the play side, and use the cluster only for the cpu-intensive calculations. play frontend forwards computation requests. this would mean both have access to cassandra cluster (scary?)
Play app does all but calculation, Akka-http exposes calculation Api for client(angular, both microservices have access to same cassandra cluster
eliminate play and make it a rest service with Akka-http and angular
Sorry if this was too high-level a question. any thoughts?
Upvotes: 0
Views: 888
Reputation: 11741
As you said this is high level question but I think you are on the right track i.e., you are considering different options. Another useful thing to do is consider the tradeoffs of each option.
To be more specific I would suggest the following. Basically assigning responsibilities to each layer ( or ring) in your architecture. The key idea being you should be able to deploy and scale each layer independently.
Assign all data access and compute to Akka. This will allow your Akka cluster to scale independently.It also means that your user interface layer doesn't know anything about your data stores. Say tomorrow you move from Cassandra to HBase your front end will have minimal impact.
Assign all HTTP and user interface related stuff to Play. Make sure you don't keep any state in Play. Push all state to Akka or your database. This will allow you to scale the Play layer horizontally.
Provide data end points to your Akka cluster using Spray REST services. You can add a caching layer in between to speed up access.
I won't recommend eliminating Play because it provides more than just REST end points.
Finally, in my experience this is no "right" architecture. It really boils down your specific needs and requirements.
Upvotes: 1