← System Design
Service Discovery
ReliabilityLets services find the current network location of other services in a fleet where instances constantly start, stop, and move.
In a static world you could hardcode IPs; in a microservices/cloud world, instances are ephemeral (autoscaling, redeploys, crashes), so 'where is the order-service right now' is a question that must be answered dynamically. Service discovery solves this via a registry: services register themselves (or are registered by the platform) on startup, deregister on shutdown, and other services query the registry (or have it pushed to them) to find current healthy instances to call.
How it connects
Service Discovery as the source, with the components it typically interacts with.
- → Load Balancer: Client-side load balancing relies on service discovery to get the current list of healthy backend instances to balance across.
- → API Gateway: The gateway queries service discovery to resolve a logical service name to a live instance address before routing a request.
- → Consensus & Replication Protocols: Service registries (etcd/ZooKeeper/Consul) use a consensus protocol internally to keep the registered-instance list consistent across registry nodes.
- → Circuit Breaker & Bulkhead: When service discovery returns an instance that's actually failing, a circuit breaker at the caller trips to stop hammering it and forces a retry against a different instance.