# How to deal with user requests that take time to process?

**URL:** <https://www.ruby-forum.com/t/how-to-deal-with-user-requests-that-take-time-to-process/183510>\
**Category:** Rails\
**Created:** [February 15, 2010, 8:49pm UTC](https://www.ruby-forum.com/t/how-to-deal-with-user-requests-that-take-time-to-process/183510 "2010-02-15T20:49:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PierreW](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/da6949/32.png) [@PierreW](https://www.ruby-forum.com/u/PierreW)\
**Post date:** [February 15, 2010, 8:49pm UTC](https://www.ruby-forum.com/t/how-to-deal-with-user-requests-that-take-time-to-process/183510/1 "2010-02-15T20:49:49Z")

</div>

Hi guys,

Could you recommend a common design for the following case (or point  
me in the right direction):

- the user makes a request
- the server processes is it, but the process is long therefore it is  
split into “chunks”.
- the page is rendered with the first chunk
- when another chunk is ready, it is pushed to the client (say at the  
bottom of the page or something).

I guess a solution could be:

- do the process in the background, store the chunks in a DB (marked  
using session)
- get periodic AJAX calls from the client to check whether there is  
“something new available” in the DB
- if there is, push to the client.

But it seems a bit heavy (and could potentially be thread unsafe?) to  
me. Besides, it would be better to push the chunks as soon as they are  
ready rather than waiting for periodic calls.

Is there a preferred way to do that?

Thanks a lot,  
Peter

---

<div class="post-metadata">

**Author:** ![PierreW](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/da6949/32.png) [@PierreW](https://www.ruby-forum.com/u/PierreW)\
**Post date:** [February 16, 2010, 11:03am UTC](https://www.ruby-forum.com/t/how-to-deal-with-user-requests-that-take-time-to-process/183510/2 "2010-02-16T11:03:45Z")

</div>

On 15 Feb 2010, at 20:48, PierreW wrote:

> I guess a solution could be:  
> Is there a preferred way to do that?  
> Juggernaut (Flash based pushing) or Comet (persistent HTTP connection  
> pushing). Doubt there’s a lot of prechewed code for either of them out  
> there though.

Polling isn’t really that bad in this case imo. When there is no  
chunk, your app will just return a status, when there is, it returns  
data. That’s less actual data than Campfire has to deal with and they  
are using polling.

Best regards

Peter De Berdt
