Why static addresses fail
In a dynamic system, service instances start, stop, and move across hosts constantly. Hard coding an address breaks the moment an instance is rescheduled. Service discovery is the mechanism by which a caller finds a healthy address for the service it wants to reach.
Two main patterns
- Client side discovery has the caller query a registry for available instances, then pick one itself. The client owns the load balancing logic but must understand the registry.
- Server side discovery puts a router or load balancer in front. The caller talks to a stable endpoint, and the router consults the registry and forwards the request. The client stays simple.
Instances register themselves on startup and send periodic heartbeats so the registry can drop ones that have died, a process called health checking. The registry is critical infrastructure, so it is usually run as a fault tolerant cluster. A common simplification is to expose discovery through DNS, letting clients resolve a service name to current instances without speaking a custom protocol.
Key idea
Service discovery uses a registry of self registering, heartbeating instances so callers can always find a healthy address, either by querying directly or through a router.