I have a NodeJS API web server (let's call it WS1) that receives RESTful HTTP requests from clients, and to respond needs to first query another local server (let's call it WS2).

The flow is pretty much like this:

1. WS1 receives an HTTP request from a client and parses it.
2. WS1 sends a request to WS2 for some information.
3. When WS1 receives the response from WS2, it finishes processing the original request and sends a response back to the client.

Until now all communication between WS1 and WS2 has been done through HTTP requests, since the two machines are on the same local network.

To speed things up though I'm considering to start using [**zmq**](http://zeromq.org/) instead. I've looked at the patterns they show on the docs, but still haven't figured out a concurrency problem.

WS1 can send many requests per second to WS2, and there's no guarantee that WS2 replies in the same order as it receives the requests, since some async operations can internally take longer than others.

So, using zmq with NodeJS, how do I make sure that when WS1 receives a message from WS2 it knows to what original client request it belongs to? Is there a built-in mechanism to take care of it?

Thanks!