The moving target problem
Service instances start, stop, and move across hosts as they scale or recover. Hardcoding addresses breaks the moment an instance changes. Service discovery lets a caller find a healthy instance at runtime.
The registry
A service registry holds the live address of every instance. Instances register on startup and send heartbeats; unhealthy ones are removed.
Two lookup styles
- Client side discovery: the caller asks the registry and picks an instance itself.
- Server side discovery: the caller hits a load balancer that queries the registry and forwards the request.
Why it matters
Discovery plus health checks means traffic only reaches live instances, enabling autoscaling and self healing without manual address updates.
Key idea
Service discovery uses a registry of live, health checked instances so callers always reach a working address as instances scale and move.