Service discovery
Definition
Service discovery maps a service name to the addresses of its live instances, using a service registry that instances join when ready and leave on shutdown or when health checks or heartbeats stop.
In practice
In autoscaled and container platforms instances are short-lived and change address constantly, so fixed IPs in configuration go stale within minutes. With client-side discovery the caller fetches the instance list and balances itself (gRPC resolvers, mesh sidecars); with server-side discovery it calls a stable name and a load balancer follows the registry (a Kubernetes Service). DNS-based discovery sits in between.
Freshness is the hard part. A crashed instance stays in the registry until its TTL expires or a health check fails, and DNS caches and long-lived connections delay changes further. Instances should deregister before stopping and then drain, and callers should retry on another instance. The registry itself must be highly available, or discovery becomes the single point of failure.
Example
A payments instance renews its Consul entry every 10 seconds with a 30-second TTL; after it crashes, callers may still pick it for up to 30 seconds unless they retry on another instance.