Free tools for application high availability

High availability can be implemented through server clustering and load balancing. Clustering can be supported by corosync and pacemaker. On the load balancing side, there are dedicated hardware such as F5 which is expensive. Alternatively, there are three common ways to achieve load balancing with application, Linux Virtual Server (LVS), Nginx and HA Proxy.

LVS is part of standard Linux kernel. It performs layer 4 load balancing. TCP or UDP port drives load balancing decision so it consumes less memory and CPU. It is therefore more performant than layer 7 load balancing or DNS rotating, and the configuration required is less complex since it only supports simple load balancing rules. It works with any type of application traffic. LVS works in two modes:

  • Network Address Translation (NAT): LVS needs to assume the gateway of real servers (RS). VIP is assigned to LVS. LVS applies DNAT on inbound packets, so that the destination IP becomes RS. RS returns packet with IP of itself as the source IP and destination IP being LVS. At this point LVS performs SNAT so the source IP becomes the VIP and send it to the client. Client perceives VIP as the source;
  • Direct Routing (DR): LVS and RS clusters all bind to the VIP. RS servers have VIP assigned to a non-ARP interface (i.e. loopback). When LVS takes inbound packet, it updates the MAC address in ethernet frame to that of RS. The RS will accept the packet because MAC address matches at ethernet layer and IP address matches at network layer. It is not even aware of the existence of LVS. The return packet made directly to the client as indicated in the destination IP without going through LVS. DR mode does not modify IP address. It only modifies IP address on the way in. The returning traffic is not throttled by LVS and performs better. It is common in large website.

Nginx is a high-performance, event-driven, cross-platform layer 7 load balancing application. It runs as a reverse proxy where it receives request for the Internet and forwards it to internal servers. It consumes less memory than many of its alternatives for layer 7 load balancing. There are many strategies for load balancing such as weight, ip hash. It supports 20-30 k concurrent connections, and support compression and health check. It is known to be very stable and common for small and medium volume.

HAProxy supports both layer 4 and layer 7 load balancing. It supports load balancing based on cookie and session, as well as health check. Since it is layer 4 load balancing, it supports any TCP protocol such as read traffic for MySQL.  

Leave a Comment