High-performance TCP/HTTP load balancer and proxy server
Core Idea: HAProxy is an open-source software solution providing high availability, load balancing, and proxying for TCP and HTTP-based applications, known for its reliability, performance, and low resource consumption.
Key Elements
Key Features
- Layer 4 (TCP) and Layer 7 (HTTP) load balancing
- SSL/TLS termination
- Health checking of backend servers
- Sticky sessions and persistence
- Access control lists (ACLs)
- Content switching and redirection
- Detailed monitoring and statistics
- Zero-downtime reloads
Technical Specifications
- Event-driven, single-process model
- Non-blocking architecture
- Extremely low latency (microseconds)
- Support for tens of thousands of concurrent connections
- Configurable load balancing algorithms
- Advanced queuing mechanisms
- Header manipulation and rewriting
- WebSocket support
Architecture Components
- Frontend: Defines listening sockets and their behaviors
- Backend: Defines groups of servers to handle requests
- Listen: Combined frontend and backend for simpler configuration
- ACLs: Conditions for request manipulation
- Stick Tables: For persistence and rate limiting
- Health Checks: For server availability monitoring
Implementation Example
Basic HAProxy configuration (haproxy.cfg):
global log /dev/log local0 user haproxy group haproxy maxconn 50000 daemon
defaults log global mode http option httplog option dontlognull timeout connect 5000 timeout client 50000 timeout server 50000
frontend http_front bind *:80 stats uri /haproxy?stats default_backend web_servers
backend web_servers balance roundrobin option httpchk HEAD / HTTP/1.1\r\nHost:\ localhost server web1 192.168.1.10:80 check server web2 192.168.1.11:80 check
Load Balancing Algorithms
- Round Robin: Requests distributed in rotation
- Least Connections: Sent to server with fewest connections
- Source IP Hash: Based on client's IP address
- URI Hash: Based on request URI
- URL Parameter: Based on query string parameter
- Header: Based on HTTP header value
- Random: Random distribution with weighting
Use Cases
- High-traffic website load balancing
- API gateway functionality
- Database load balancing
- Service discovery integration
- Microservices architecture entry point
- TCP protocol proxying (MySQL, SMTP, etc.)
- Zero-downtime application deployments
Additional Connections
- Broader Context: Load Balancers, Reverse Proxy
- Applications: High Availability Architecture, Web Infrastructure
- See Also: Nginx, Traefik, Envoy (alternative proxies)
References
- HAProxy official documentation: https://www.haproxy.org/
- "Load Balancing with HAProxy" by Nick Ramirez
#load-balancing #high-availability #networking #infrastructure #reverse-proxy
Connections:
Sources:
- From: Worklog n8n