Intelligent routing from DNS/GTM to L4/L7 balancing. Optimize for latency, cost, and resilience; use consistent hashing for stateful services.


1. Global Traffic Management (GTM)

A. DNS-Based Load Balancing (Geo-Routing)

  • Mechanism: DNS (Route 53, Cloudflare) returns region-specific IPs based on geography/health.
  • Strategies: Latency-based, Geo-proximity, Failover routing.
  • Trade-off: Slower failure reaction due to client-side DNS caching (TTL).

B. Anycast

  • Mechanism: One IP advertised globally; BGP routes to nearest healthy endpoint.
  • Use Case: CDNs, DNS providers (e.g., Google DNS) for low-latency/high availability.
  • Trade-off: Near-instant failover; requires advanced network infra.

2. Internal Load Balancing Strategies

A. Layer 4 (L4) Load Balancing

  • Mechanism: IP/Port-based (TCP/UDP), no HTTP inspection.
  • Strategies: Round-Robin, Least Connections, Source-IP Hash.
  • Benefits: Fast, lower overhead.

B. Layer 7 (L7) Load Balancing

  • Mechanism: Routes by headers, paths, cookies, methods.
  • Strategies: URL-based routing; A/B testing; canaries; SSL termination; API Gateway.
  • Benefits: Enables microservices routing and advanced traffic shaping.

C. Sticky Sessions (Session Affinity)

  • Mechanism: Cookie or source-IP affinity to same instance.
  • Use Case: Legacy stateful apps storing session on instance.
  • Trade-off: Uneven distribution; hinders rolling deploys—prefer stateless services.

3. Consistent Hashing for Stateful Services

Definition: Route requests/keys to a stable set of servers such that minimal remapping occurs on membership changes.

A. Problem with Standard Hashing

Using hash(key) % N means adding/removing a server reassigns most keys, causing cache misses and migrations.

B. Consistent Hashing Solution

  • Mechanism: Map servers and keys to a logical ring; route to first server clockwise.
  • Benefit: Only adjacent keys to the changed server are remapped; rest remain stable.
  • Use Case: Memcached, DynamoDB, Cassandra partitions.

Consistent Hashing Ring

Illustration of keys and servers on a ring; keys route clockwise to nearest server.