Search code examples
model-view-controllerplayframeworkakkaactorreactive-programming

When does it make sense to use Actors in a web application


I have been browsing Typesafe Activator templates. Often in the Typesafe templates (Reactive Stocks / Maps / *) I see an actors folder within the app folder. Obviously, this is supposed to hold actors, but how would one add actors to a Play application. I know that Play is an MVC framework, and that means:

  1. Models act as templates for structured data, and are used for interaction with the database and passed to views
  2. Views are web pages, and typically can have data injected into them.
  3. Controllers contain business logic, and may bridge models and views

If this is so, what are Actors for? What do they add that Models, Views, and Controllers do not provide? What would be some practical uses of Actors while developing reactive web applications?

EDIT

While reviewing Play documentation, I have found that Actors may be useful for scheduling. Are there any other uses for Actors?


Solution

  • The Play Framework uses controllers to handle the requests. The controller fetches the data from the models and transforms/filters/modifies it, so that the views can handle the data. The controller also contains the whole business logic.

    The way the Play Framework is designed, those controllers should handle those requests either really quick, or return an asynchronous Promise. This is where the actors come in handy. If you have requests which take a long time to compute, you can use an actor to handle the request asynchronous. Have a look at the documentation.