Service Discovery
In Kubernetes, Docker Swarm, or any auto-scaling environment, service instances come and go. Hard-coding http://inventory-service:8080 breaks the moment a container restarts on a different port or IP. Service discovery solves this with a registry: each instance registers itself on startup ("I am inventory-service, version 2.1, at 10.0.4.12:8080, healthy") and deregisters on shutdown.
Clients — or an API Gateway, or a service mesh sidecar — query the registry to find a healthy instance before each request. Kubernetes DNS (inventory-service.default.svc.cluster.local) is a built-in form of service discovery. Consul, Eureka, and etcd are standalone registries used outside Kubernetes or for multi-cluster setups.
Check your understanding
Why do hard-coded IPs fail in orchestrators?Show answerHide answer
Answer
Instances restart with new IPs/ports; discovery or DNS must track healthy endpoints.What does registry.getHealthy represent in the sketch?Show answerHide answer
Answer
Pseudo-code for looking up a healthy instance — real systems use DNS, a client library, or a mesh sidecar.Name a built-in Kubernetes discovery mechanism.Show answerHide answer
Answer
Service DNS (e.g. inventory-service.default.svc.cluster.local).