Scaling with a Reverse Proxy

Learn how to scale a Node.js web application using a reverse proxy.

The cluster module, although very convenient and simple to use, isn’t the only option we have to scale a Node.js web application. Traditional techniques are often preferred because they offer more control and power in highly-available production environments.

The alternative to using cluster is to start multiple standalone instances of the same application running on different ports or machines, and then use a reverse proxy (or gateway) to provide access to those instances, distributing the traffic across them. In this configuration, we don’t have a primary process distributing requests to a set of workers, but a set of distinct processes running on the same machine (using different ports) or scattered across different machines inside a network. To provide a single access point to our application, we can use a reverse proxy, a special device or service placed between the clients and the instances of our application, which takes any request and forwards it to a destination server, returning the result to the client as if it was itself the origin. In this scenario, the reverse proxy is also used as a load balancer, distributing the requests among the instances of the application.

Note: For a clear explanation of the differences between a reverse proxy and a forward proxy, we can refer to the Apache HTTP server documentation.

The illustration below shows a typical multi-process, multi-machine configuration with a reverse proxy acting as a load balancer on the front:

Get hands-on with 1400+ tech skills courses.