Search code examples
scalaasynchronousplayframeworkakkaactor

Play Async Vs Akka Actor


I'm new to both Play framework and Akka Toolkit.

We are trying to build an orchestration layer between the web client and microservices using Play.
So basically for every request from the client, Play has to do a WS call and return the JSON (as well as cache it).

Now when doing the WS call, we can use Play Async APIs or use Akka actors. Does one of these options outweigh the other anyway?

Is there any recommendation on when one should venture into using Akka actors along with Play compared to directly using Play Async APIs?


Solution

  • In Akka, main notion as an actor, which is an object with memory to keep state. Sequential operations to that state are serialized by the system and cannot interfere. In Java8 promise/futures, main notion is asynchronous method call, and if different methods belong to the same object, it is user's responsibility to provide serial access - which is not easy and can be error prone. Then, using futures implies creation of a Future object for each separate operation, which can be considered as overhead if the operations are fine-grained. On the other hand, CompletableFuture has means to combine several events into one like allOf(), which has no direct analogue in Akka.