users@jersey.java.net

[Jersey] Scaling with AsyncResponse

From: Robert DiFalco <robert.difalco_at_gmail.com>
Date: Fri, 12 Jul 2013 08:44:17 -0700

I have a couple of questions. With Jersey 1.x I am using a pretty typical
pattern for scaling. Basically, for any request that can take longer than
~1 second I return a polling URL. The client then calls this URL to get the
request status. If I am still processing the operation (but the request is
still valid) I return a 200. If the operation is done I return a 303 with a
new URL to the ready resource. In most cases I put the resource in REDIS
and the URL contains the key to the JSON in REDIS. This is obviously
important because I need the REST server to be stateless so it can scale
out. For example, the polling request could come once on one server and
again on another server. The SEE OTHER could end up directing the client to
another server than it was issued from. Make sense?

So my question is this. Does Jersey 2.0 give me anything to make this
pattern easier to implement? Additionally, what is AsyncResponse used for
and does it help me at all here?

These stateless Async calls can be tedious to implement since I have to
distribute the status (processing, gone, done, etc) as well as the resource
so it is available to each dyno that runs my REST service.

Is it true that AsyncResponse keeps the client connection for the complete
async operation? If so then I'm having a hard time understanding when I
should use it over the above pattern.

Thanks!