Sub topic 3
Hardware, Software, and Cloud Load Balancers
Assume you understand HTTP, TCP, IP addresses, ports, and basic configuration files. This chapter compares deployment choices and covers safe removal, failure handling, and troubleshooting.
Hardware, software, and cloud load balancers
A hardware load balancer is a dedicated appliance designed for high throughput. It can provide specialized TLS processing and network features, but it costs more and can create dependence on one vendor.
A software load balancer runs on a server or virtual machine. NGINX and HAProxy are common examples. They are flexible and easy to automate, but you must manage their capacity, updates, and redundancy.
A cloud load balancer is a provider-managed service. It usually scales across multiple zones and integrates with cloud health checks, certificates, and access controls. It reduces maintenance, but its features and pricing depend on the provider.
| Type | Main advantage | Main trade-off |
|---|---|---|
| Hardware | Predictable high throughput | Cost and vendor dependence |
| Software | Flexible and portable | You manage operations |
| Cloud | Managed scaling and availability | Provider-specific behavior and cost |
Connection draining and graceful deploys
When removing a backend, stop sending it new connections but allow existing requests to finish. This process is called connection draining. It prevents interrupted downloads, uploads, and long-running requests.
Set a drain timeout longer than normal request duration. Requests that exceed the timeout may need cancellation or retry handling at the application layer.
Hash-based balancing and consistent hashing
Hash-based balancing calculates a value from a client property, such as an IP address or session key. The result selects a backend. Consistent hashing reduces remapping when servers are added or removed, which helps caches and stateful services.
Use it when keeping a key on the same backend matters. Prefer ordinary balancing when backends are stateless and even distribution matters more.
Removing the load balancer as a single point of failure
Run load balancers as a redundant pair or as a managed multi-zone service. A virtual IP, health-aware DNS record, or cloud front end can direct clients to a healthy instance.
Global load balancing with DNS and anycast
DNS-based global balancing returns an address for a nearby or healthy region. DNS caching means changes are not immediate. Anycast announces the same IP from several locations, and network routing usually sends clients to a nearby site. Anycast can fail over quickly, but routing behavior is less directly controlled.
Metrics, logs, and troubleshooting
Monitor request rate, latency, status codes, active connections, connection errors, backend health, and queue depth. Logs should include the selected backend, request ID, client address, and timing fields.
When users report failures, compare load-balancer logs with backend logs. A healthy check endpoint may still hide failures in real application paths, so test representative dependencies without making checks too expensive.
Exercise
Which design best supports a stateless web application that needs multi-region failover: consistent hashing, one hardware appliance, or redundant regional load balancers with DNS health checks?
Show answer
Redundant regional load balancers with DNS health checks. Stateless servers do not require session affinity, and DNS can direct users away from an unhealthy region.