Services scale up/down. IPs change. Hardcoded addresses die. Service discovery lets services find each other dynamically.

Service AService BService CRegistryConsul / Eureka / etcdClient-side LBapp knows all instancesServer-side LBgateway routesDNS-basedSRV recordsMesh (Envoy)sidecar proxyRegistrationon startup/deregister
Service discovery: registry + client/server LB or DNS or mesh
Advertisement

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.

Advertisement

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.

Registry + client/server/DNS/mesh. Mesh wins at large scale. DNS is simplest to start.