Services scale up/down. IPs change. Hardcoded addresses die. Service discovery lets services find each other dynamically.
Registration
Service starts → registers with Consul/Eureka. Sends heartbeats. Deregisters on shutdown. Auto-deregister if no heartbeat.
Registration
Service starts → registers with Consul/Eureka. Sends heartbeats. Deregisters on shutdown. Auto-deregister if no heartbeat.
Client-side discovery
Client queries registry. Gets list of instances. Load balances itself. Fewer hops. Client must handle updates.
Server-side discovery
Client hits well-known LB. LB queries registry. Client is dumb. LB becomes bottleneck at scale.
DNS-based
Registry publishes DNS SRV records. Any DNS-aware client works. Simple. TTL introduces staleness.
Service mesh
Envoy sidecar handles discovery + LB + retries + tracing. App code just hits localhost. Complexity moved to infrastructure.