What is Service Discovery

Service discovery is the mechanism by which one service in a distributed system finds the network location (IP address and port) of another service it needs to call. In a microservices architecture where services start, stop, and move frequently, hardcoding addresses is not viable.

How it works

Client-side discovery — the client queries a service registry (Consul, etcd, ZooKeeper) to get the list of available instances for a service, then picks one (often using client-side load balancing). Netflix Eureka popularized this pattern.

Server-side discovery — the client sends requests to a load balancer or DNS name. The load balancer queries the registry and routes the request. The client does not know about individual instances. AWS ALB and Kubernetes Services work this way.

DNS-basedDNS records return the addresses of service instances. Simple but limited by DNS TTL caching — changes propagate slowly.

Services register themselves on startup and deregister on shutdown. Health checks ensure dead instances are removed.

Why it matters

Without service discovery, services rely on configuration files with hardcoded addresses. Every deployment, scale event, or failure requires manual configuration updates. Service discovery automates this, enabling dynamic scaling, rolling deployments, and automatic failover.

In Kubernetes, service discovery is built-in through DNS: order-service.default.svc.cluster.local resolves to the pod IPs of the order service.