How is load balancing performed across multiple instances of a service, and how does it interact with service discovery?
Last updated
Service discovery supplies the live list of instance addresses. The load balancer then picks one per request using round-robin, least-connections, weighted, or consistent hashing.
Server-side LB: a component like NGINX or a cloud ELB sits behind one virtual address and forwards traffic. Client-side LB: the caller queries the registry (Eureka, Consul) and picks an instance itself, saving a network hop.
Instances register on startup and deregister or expire on shutdown or failed health checks. The balancer must react quickly so traffic stops hitting dead instances.