How do services find each other when instances come and go?
“Instances autoscale, get rescheduled and roll out several times a day. How does Service A find a healthy instance of Service B, and what goes wrong with stale information?”
What this tests
- Why static configuration fails in a dynamic fleet
- Registry with registration, heartbeats/TTL and health checks
- Client-side vs server-side discovery, DNS and service mesh
- The stale-registry failure and the registry as a dependency
Answers by level
Read the beginner answer first and notice what is missing.
Static config breaks the first time the autoscaler adds an instance nobody listed, or a rolling deploy replaces every IP. A service registry fixes it: each instance registers itself (or the orchestrator registers it) on start with its address and a health endpoint; it renews a heartbeat with a TTL (say 10–30 s); the registry drops entries whose TTL expires or whose health check fails. Service A queries the registry (or a local cache of it) and load-balances across healthy instances.
Two shapes: client-side discovery, where A holds the list and picks an instance (fewer hops, smarter routing, but every language needs the client library), and server-side, where A calls a stable name and a load balancer or proxy does the lookup (simpler clients, one more hop). Kubernetes services are server-side via DNS plus kube-proxy; a service mesh puts a sidecar next to each instance and does discovery, retries and mTLS there — see Service Discovery.
Green flags · Red flags
- Explains why static config fails with autoscaling and rolling deploys
- Registration, heartbeat TTL and health checks, with numbers
- Client-side vs server-side discovery with a tradeoff
- Stale-registry failure modes in both directions
- Treats the registry as a dependency and caches the last good list
- "We keep the IPs in a config file and redeploy when they change."
- Assumes DNS is refreshed per request in every runtime
- No idea what happens when the registry is down
- Picks a TTL without relating it to failure duration