HAProxy, or High Availability Proxy is used for load balancing.

Load-balancer servers are also known as front-end servers. Generally, their purpose is to direct users to available application servers. A load-balancer server may have only the load balancer application (HAProxy) installed or, in rare cases, it may be an application server in addition to a load balancer, which is not a recommended configuration.

Each load-balancer server has its own public IP address (typically an Elastic IP address in the case of Amazon EC2 clouds), but shares the same fully qualified domain name (e.g. host.domain.tld) as the other load-balancer servers in your configuration.


Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy. You set it up in front of any server that speaks HTTP and configure it to cache the contents. Varnish is a program that can increase the speed of a Web site while simultaneously reducing the load on the Web server.

The request which is made is retrieved and sent back by Varnish rather than the Web server. Varnish takes a look at what’s being asked for and forward the content to the Web server (known as a back end to Varnish). The back-end server does its general work and returns a reaction to Varnish, which gives the reaction to the customer that sent the first demand.

The advantage here is that the first request to new content will be same but since Varnish can store reactions from the back end in its reserve for future use. Varnish rapidly can serve the following reaction from its store without putting any unnecessary burden toward the back server.

The outcome is that the heap toward the back is lessened fundamentally, reaction times enhance, and more demands can be served every second. Something that makes Varnish so quick is that it keeps its reserve totally in memory rather than on plate.


What is a reverse proxy?

A proxy server is a go‑between or intermediary server that forwards requests for content from multiple clients to different servers across the Internet. A reverse proxy server is a type of proxy server that typically sits behind the firewall in a private network and directs client requests to the appropriate backend server. A reverse proxy provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers.

Common uses for a reverse proxy server include:

Load balancing – A reverse proxy server can act as a “traffic cop,” sitting in front of your backend servers and distributing client requests across a group of servers in a manner that maximizes speed and capacity utilization while ensuring no one server is overloaded, which can degrade performance. If a server goes down, the load balancer redirects traffic to the remaining online servers.

Web acceleration – Reverse proxies can compress inbound and outbound data, as well as cache commonly requested content, both of which speed up the flow of traffic between clients and servers. They can also perform additional tasks such as SSL encryption to take load off of your web servers, thereby boosting their performance.

Security and anonymity – By intercepting requests headed for your backend servers, a reverse proxy server protects their identities and acts as an additional defense against security attacks. It also ensures that multiple servers can be accessed from a single record locator or URL regardless of the structure of your local area network.

HA-Proxy VS Varnish

  • Varnish does not support SSL so thats one reason to use haproxy which will do SSL termination for you. But if SSL termination is done at the CDN level, it is a different case altogether.
  • While both HAProxy and Varnish can load-balance, only one of them is built for it.

If you are thinking of a full-fledge deployment, this is what is recommended:

  • Install both on the same box and configure Varnish to use HAProxy as its only backend.
  • The CDN gets pointed at HAPROXY, which then load-balances between Varnish and the backends, sending to Varnish by default unless the request comes from Varnish based on headers or source IP.

This way you can:

  • Easily bypass Varnish for upgrades or testing
  • Scale-out either tier to more boxes as your load increases
  • Use each software for its core purpose

The reason is that Varnish really only supports round-robin and random balancing algorithms.
HAProxy, on the other hand, is built for load-balancing, and thus supports:

  • round-robin (with weighting)
  • a static round-robin approach
  • least connections
  • first server available
  • bucketing based on source
  • bucketing based on URI
  • bucketing based on a URL parameter
  • bucketing based on an HTTP header
  • bucketing based on a cookie

Whether or not Varnish’s load-balancing is sufficient depends on your needs, but it certainly hasn’t superseded HAProxy.