Introduction
Introduction in HAProxy Guide.
Introduction#
HAProxy (High Availability Proxy) is a high-performance TCP/HTTP load balancer and reverse proxy server. In the HEAL platform, HAProxy serves as the primary entry point for all incoming traffic, distributing requests across multiple backend servers to ensure high availability, fault tolerance, and optimal performance.
HAProxy is widely recognized for its reliability and efficiency, handling millions of concurrent connections with minimal resource consumption. Within HEAL deployments, HAProxy is responsible for:
- Load balancing incoming HTTP/HTTPS requests across HEAL platform services.
- SSL/TLS termination to offload cryptographic processing from backend servers.
- Health checking of backend servers to route traffic only to healthy instances.
- Session persistence (sticky sessions) to maintain user session affinity.
- Request routing based on URL paths, headers, or other attributes.
Note:
HAProxy is a critical infrastructure component in HEAL multi-server deployments. Ensure correct planning and testing before making configuration changes in production environments.
Benefits#
Deploying HAProxy in a HEAL environment provides the following benefits:
- High Availability: HAProxy continuously monitors backend servers and automatically reroutes traffic away from unhealthy or unresponsive instances, ensuring uninterrupted service delivery.
- Load Balancing: Distributes incoming requests evenly across multiple backend servers using configurable algorithms (round robin, least connections, source IP hash, etc.), preventing any single server from becoming a bottleneck.
- SSL/TLS Termination: Handles SSL/TLS encryption and decryption at the proxy layer, reducing the computational overhead on backend application servers and simplifying certificate management.
- Performance Optimization: HAProxy is designed for high concurrency and low latency. It supports HTTP keep-alive, connection pooling, and content compression to optimize throughput and response times.
- Security: Provides an additional security layer by hiding backend server details from clients, supporting Access Control Lists (ACLs), rate limiting, and protection against common web attacks.
- Flexible Routing: Supports content-based routing using ACLs to direct traffic to specific backends based on URL paths, HTTP headers, cookies, or query parameters.
Architecture#
The following describes the HAProxy architecture within a HEAL deployment:

Deployment Modes#
The following are the deployment modes of HAProxy:
| Mode | Description | Use Case |
|---|---|---|
| HTTP Mode | HAProxy operates at Layer 7 (application layer), inspecting HTTP headers, URLs, and cookies for intelligent routing. | HEAL UI, API Gateway, Grafana dashboards |
| TCP Mode | HAProxy operates at Layer 4 (transport layer), forwarding raw TCP connections without inspecting content. | Database connections, OpenSearch, gRPC services |
Behaviour Details#
Health Checking#
HAProxy performs periodic health checks on backend servers to determine their availability:
- HTTP Health Checks: Sends HTTP requests (e.g., GET /health) to backend servers and validates the response status code.
- TCP Health Checks: Verifies that a TCP connection can be established to the backend server's port.
- Inter/Fall/Rise Parameters:
- inter — Interval between health checks (default: 2000 ms).
- fall — Number of consecutive failures before marking a server as DOWN (default: 3).
- rise — Number of consecutive successes before marking a server as UP (default: 2).
Load Balancing Algorithms#
| Algorithm | Description |
|---|---|
| round robin | Distributes requests sequentially across servers. Supports server weights. This is the default algorithm. |
| leastconn | Routes requests to the server with the fewest active connections. Best for long-lived connections. |
| source | Hashes the client's source IP address to ensure the same client always reaches the same server (session persistence). |
| uri | Hashes the request URI to distribute requests for the same resource to the same server (useful for caching). |
| hdr (name) | Hashes a specific HTTP header value for routing decisions. |
Session Persistence (Sticky Sessions)#
HAProxy supports multiple session persistence mechanisms to ensure a client's requests are consistently routed to the same backend server:
- Cookie-based persistence: HAProxy inserts or reads a cookie to identify the target backend server.
- Source IP persistence: Uses the source-balance algorithm to hash the client IP address.
- Stick Tables: In-memory tables that track client sessions using various keys (source IP, cookie, URL parameter).
Connection Handling#
- Max Connections: The maxconn parameter in the global section limits the total number of concurrent connections. Backend servers also have individual maxconn settings.
- Connection Queuing: When a backend server reaches its maxconn limit, HAProxy queues additional requests and forwards them as connections become available.
- Timeouts: Configurable timeouts for client connections (timeout client), server connections (timeout server), and connection establishment (timeout connect).
Logging#
HAProxy logs detailed information about each request, including the following:
- Client IP, request method, URL, HTTP status code.
- Backend server selected, response time, and bytes transferred.
- Connection state, termination cause, and retry count.
Logs are typically sent to a syslog server (rsyslog) and can be integrated with HEAL's log monitoring for centralized analysis.