Video in progress
Where can load balancing happen in microservices?
In several places: for traffic coming from outside, at the front load balancer or the gateway; between services, at a Kubernetes Service, a service mesh sidecar, or a client-side balancer inside the caller.
📖 Answer
A typical request path looks like this:
user -> cloud LB / Ingress -> API Gateway (2-3 copies)
-> order-service (one of the instances)
-> payment-service (one of the instances)
At every arrow, someone answers the question "which instance do I send this to?"
The most common strategies:
- round robin: take turns, simple and often enough;
- least connections / least requests: to the least busy instance; better when response times vary;
- random: works better than expected, especially when there are many callers.
One trap: the balancer must send only to a live instance. Without a readiness check, an instance that's just starting (and hasn't connected to the database yet) also receives traffic, and you get errors during a deploy.
Sign up to mark studied questions and save your progress.