# Fire and forget requests

**URL:** <https://www.ruby-forum.com/t/fire-and-forget-requests/211257>\
**Category:** NGINX\
**Created:** [August 30, 2011, 11:35pm UTC](https://www.ruby-forum.com/t/fire-and-forget-requests/211257 "2011-08-30T23:35:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [August 30, 2011, 11:35pm UTC](https://www.ruby-forum.com/t/fire-and-forget-requests/211257/1 "2011-08-30T23:35:51Z")

</div>

Hi,

We have a very specific use case and are trying to find a solution for  
it.  
We started looking at nginx as a possibility for handling this use case  
as  
we already use nginx for some of our other webserver duties. I’ve done  
some  
testing and investigation but it doesn’t seem like we can use nginx to  
do  
what we want. However I thought I’d check with the community before  
dismissing it completely.

What we want is a fire and forget solution for request handling, where  
we  
can set up nginx to receive a request from our web servers, pass this  
request on to an external HTTP service or an HTTP backend and send a 200  
response back straight away to the requesting machine, leaving the  
original  
request to be handled at whatever speed the backend is capable of. We  
don’t  
care about the response from the backend server; this can simply be  
dropped  
once it’s received.

Is something like the above possible? I did some testing by setting  
nginx up  
as a load balancer, pointing at a backend web server, and using the  
“return”  
directive before the proxy\_pass directive but the return directive  
simply  
stops further execution of the request.

Any advice would be welcome.

Thanks,  
Guy

---

<div class="post-metadata">

**Author:** ![Guy\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/85e7bf/32.png) [@Guy\_K](https://www.ruby-forum.com/u/Guy_K)\
**Post date:** [August 30, 2011, 11:49pm UTC](https://www.ruby-forum.com/t/fire-and-forget-requests/211257/2 "2011-08-30T23:49:24Z")

</div>

On 8/31/11, Guy K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What we want is a fire and forget solution for request handling, where we  
> can set up nginx to receive a request from our web servers, pass this  
> request on to an external HTTP service or an HTTP backend and send a 200  
> response back straight away to the requesting machine, leaving the original  
> request to be handled at whatever speed the backend is capable of. We don’t  
> care about the response from the backend server; this can simply be dropped  
> once it’s received.
> 
> Is something like the above possible?

I think post\_action can help here.  
Basically you can respond with a simple static page and set  
post\_action to forward request to another location afterwards, which  
in turn can pass request to the upstream.

---

<div class="post-metadata">

**Author:** ![Guy\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/85e7bf/32.png) [@Guy\_K](https://www.ruby-forum.com/u/Guy_K)\
**Post date:** [August 30, 2011, 11:58pm UTC](https://www.ruby-forum.com/t/fire-and-forget-requests/211257/3 "2011-08-30T23:58:01Z")

</div>

I don’t believe nginx can do this since I think it’stoo linear in the  
way it processes the request  
The way I would approach this is by using the httpd built into C# -  
HttpListener  
Once you receive the initial request you can send 200 immediately then  
spawn a new thread with the request to your backend using HttpWebRequest  
Just some ideas… this is potentially very easy using C# - and I’m sure  
in quite a few other lanquages/scripts too

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf  
Of Guy K.  
Sent: 30 August 2011 22:35  
To: removed\_email\_address@domain.invalid  
Subject: Fire and forget requests

Hi,

We have a very specific use case and are trying to find a solution for  
it. We started looking at nginx as a possibility for handling this use  
case as we already use nginx for some of our other webserver duties.  
I’ve done some testing and investigation but it doesn’t seem like we can  
use nginx to do what we want. However I thought I’d check with the  
community before dismissing it completely.

What we want is a fire and forget solution for request handling, where  
we can set up nginx to receive a request from our web servers, pass this  
request on to an external HTTP service or an HTTP backend and send a 200  
response back straight away to the requesting machine, leaving the  
original request to be handled at whatever speed the backend is capable  
of. We don’t care about the response from the backend server; this can  
simply be dropped once it’s received.

Is something like the above possible? I did some testing by setting  
nginx up as a load balancer, pointing at a backend web server, and using  
the “return” directive before the proxy\_pass directive but the return  
directive simply stops further execution of the request.

Any advice would be welcome.

Thanks,  
Guy

---

<div class="post-metadata">

**Author:** ![Guy\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/85e7bf/32.png) [@Guy\_K](https://www.ruby-forum.com/u/Guy_K)\
**Post date:** [August 31, 2011, 4:45am UTC](https://www.ruby-forum.com/t/fire-and-forget-requests/211257/4 "2011-08-31T04:45:06Z")

</div>

This could be implemented by submitting background jobs to Gearman:

> **[gearman \[Gearman Job Server\]](http://gearman.org/)**

Guy K. wrote:

> we can set up nginx to receive a request from our web servers, pass this
> 
> Any advice would be welcome.

–  
Best regards,  
Valery K.

---

<div class="post-metadata">

**Author:** ![Guy\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/85e7bf/32.png) [@Guy\_K](https://www.ruby-forum.com/u/Guy_K)\
**Post date:** [August 31, 2011, 2:25am UTC](https://www.ruby-forum.com/t/fire-and-forget-requests/211257/5 "2011-08-31T02:25:10Z")

</div>

We did notice similar functionality with PHP FPM

[http://php.net/manual/en/install.fpm.php](http://php.net/manual/en/install.fpm.php)

_fastcgi\_finish\_request()_ - special function to finish request and  
flush  
all data while continuing to do something time-consuming (video  
converting,  
stats processing etc.);

Alternatively, and the approach we’re using is via Gearman message bus  
style  
system.

On Wed, Aug 31, 2011 at 7:27 AM, Richard K.  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Guy\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/85e7bf/32.png) [@Guy\_K](https://www.ruby-forum.com/u/Guy_K)\
**Post date:** [August 31, 2011, 11:43am UTC](https://www.ruby-forum.com/t/fire-and-forget-requests/211257/6 "2011-08-31T11:43:19Z")

</div>

From: Guy K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> What we want is a fire and forget solution for request handling, where we can set  
> up nginx to receive a request from our web servers, pass this request on to an  
> external HTTP service or an HTTP backend and send a 200 response back straight  
> away to the requesting machine, leaving the original request to be handled at  
> whatever speed the backend is capable of. We don’t care about the response from  
> the backend server; this can simply be dropped once it’s received.

What about using a simple fcgi script that returns 200 straight away and  
just write the request to a file/pipe/database/…

and another script that just reads the file/pipe/database/… for new  
requests and sends them to the backend?

JD
