I'd like some advice from this group as to how I should proceed to build out some functionality using Play! and Akka.
First a litte background. I've created a dashboard-type application that queries an external web service for it's data. Some of these requests can be quite expensive, up to 30 seconds in some cases. When the user configures their dashboard with a specific chart, the specified parameters basically represent a request to the external service. We then issue the request, get the result, massage the data a bit in order to make it 'chartable', and serve it use to the browser chart widget via json. Each set or request parameters is stored in a mongo database as a set of dashboard preferences for each user.
Because requests can be fairly expensive, I would like to cache the results of the request in the mongo database as well. This way, I have the ability to reissue those results up until a configured 'stale' timeperiod has elapsed. In my skeleton design/thoughts, Akka actors are the perfect abstraction for this. Here's what I'm thinking...
As a request comes in from the client, the first thing that happens is the we look in the cache to see if there is a cached result. If so, we serve it and done. If not, we issue a message to a 'Request Scheduler (Actor)' with the request as the payload. The scheduler creates a child Actor supervised by the scheduler, passing it the initial request and a configured 'interval' (say every 15 minutes). The child actor is then responsible for making the request and putting it in the cache at every 'interval'.
With this architecture, the scheduler will create a child actor for each unique request and each child actor will be responsible to updating the mongo cache with the latest results.
A few questions...
1. Firstly, am I sane? :-) Does this make sense?
2. The set of actors need to be both bootstrapped at startup and created 'on-the-fly'. I'll have a bunch of requests in the mongo cache, so each one of those requests we will want to create a worker to start updating the cache.
3. The actors are stateful in that there is only one scheduler in the system but he's very lightweight as he only controls and dispatches to his workers. Once created, the workers are updating at every 'interval', even if no client requests are being issued. This way, when user do issue a request, they get fairly recent data. Given that Play! is stateless, how do I achieve this across requests?
4. Are there any examples out there that are using Akka with Play in a similair fashion?