Video in progress
Why do you need service discovery? Can't we just put the IP address in the configuration?
In container and cloud environments, service instances keep appearing and disappearing and their IPs change. Service discovery automatically knows their current addresses, so the caller uses only the service name.
📖 Answer
Static configuration works with one server and one instance. But if order-service runs as 4 instances, autoscaling changes that from 2 to 8, and during a deploy the old instances go away and new ones come up with different IPs, a hand-written list goes stale immediately.
How discovery works:
- when a service starts, it registers with the registry: "I'm
order-service, my address is 10.0.3.17:8080"; - the registry runs health checks periodically or waits for heartbeats, and removes the ones that don't respond;
- a caller asks for the name
order-serviceand gets one of the live instances.
Options: Eureka, Consul, or Kubernetes itself. In Kubernetes the Service object and DNS (http://order-service:8080) do this job, so a separate Eureka usually isn't needed.
Sign up to mark studied questions and save your progress.