HAProxy vs nginx
LB choice.
Overview
HAProxy and nginx are the two dominant open-source load balancers and they overlap heavily on HTTP. The differences land at the edges: HAProxy is purpose-built as an LB (superior TCP load balancing, fine-grained traffic management), nginx is a web server that also load-balances (mature HTTP/2 and HTTP/3, static-file serving, reverse-proxy plus LB in one). Both scale to massive traffic.
- HAProxy: TCP and HTTP LB-focused. Purpose-built load balancer. Best when LB is the primary use case.
- nginx: web server plus LB. Web-serving plus LB plus reverse proxy in one binary. Best when LB and origin coexist.
- HAProxy plus superior TCP LB. Fine-grained TCP load balancing. Default for non-HTTP workloads (MySQL, Redis, gRPC).
- nginx plus better modern HTTP. Mature HTTP/2 and HTTP/3 support. Default for HTTP-heavy modern workloads.
The approach
HAProxy for TCP load balancing, nginx for HTTP plus origin or static serving, either for HTTP-only LB (pick the one the team already knows). Use cloud LB (ALB, Cloud Load Balancing) where possible to avoid self-hosting either; document the rationale per tier so the choice is defensible.
- HAProxy for TCP. MySQL LB, Redis LB, gRPC over TCP. Default for non-HTTP.
- nginx for HTTP plus origin. Box also serves static or terminates TLS for many backends. Default for multi-purpose.
- Either for HTTP-only LB plus cloud LB option. Both work for plain HTTP LB; cloud LB replaces self-hosted entirely for many cases.
- Documented choice per tier. Per-tier rationale captured. Future migrations have a paper trail.
Why this compounds
The right LB choice compounds across years. Traffic-management patterns and team expertise align with the tool; cross-tier tooling (health checks, observability, deploy automation) gets reused. Switching cost grows year over year, so getting the choice right at design time pays back indefinitely.
- Better performance. Right LB for the workload. Latency stays low.
- Better operational fit. LB matches existing team knowledge. Velocity stays high.
- Reduced switching cost. Right choice up front avoids the migration that costs an engineer-quarter at year three.
- Year-one investment, year-two habit. First year builds patterns; subsequent decisions run on the same rationale.