jcm
jcm

Reputation: 5659

Parallel web service calls or Akka actors

I've only just learnt about Akka and actors and am unsure whether to use them for my following use case in a Play framework application.

What I want to do is have a user make a web request, which then needs to make somewhere between 20-50 Yelp API calls (in parallel), get those responses, do some processing and combine them into a single result.

What I want to know is whether using Akka actors will improve the scalability and decrease the response time to the user. Will using actors give me any benefit over just making the WS calls in my controller code (using a future for each).

I think I am having trouble understanding what benefit using actors might give me in this scenario as opposed to just a bunch of asynch web requests.

Upvotes: 2

Views: 933

Answers (1)

Actors themselves are just a means to achieve and manage parallelism. The gain that you get with for example spinning up one actor per async request that you're issuing is supervision hierarchies. For example, a master Actor can decide to kill respond with a failure message transparently already if one of the requests fails, or only after a number of them has failed etc. You can issue restarts (retries of these requests) etc. Without Actors you'd have to implement all this supervision logic yourself – which gets quite repetitive after a while.

To answer your question about scalability and response times: sadly "it depends" on your exact access patterns, but in general yes because you can fine-tune them way better than just one asynchronous http client as well as implement retries more easily.

If you want to check out how to collect responses from many async requests using Actors refer to this answer on stack overflow on "Waiting on multiple Akka messages".

Hope this helps.

Upvotes: 1

Related Questions