Service Discovery
Finding each other.
With microservices, the order service needs to call the payment service. But payment runs on several machines, which come and go as they scale. How does order find a live one?

- Order calls payment
- Payment machines come and go
- How to find one?
A service registry
The answer is a service registry. When a payment server starts, it registers its address. It sends heartbeats to say it's still alive. When the order service needs payment, it asks the registry for live addresses. And servers that stop sending heartbeats are removed.
- Server starts
- Registers address
- Sends heartbeats
- Callers look up
- Dead ones removed

In practice
You rarely build this yourself. Kubernetes gives every service a stable name, like payments, and routes to live pods behind it. Tools like Consul provide a registry. And a service mesh can handle discovery, retries, and encryption between services, without changing your code.
| key | value |
|---|---|
| Kubernetes | stable service names |
| Consul | a registry |
| Service mesh | discovery + retries |
| DNS | often the interface |
Summary
Service discovery keeps a live list of where each service runs, so callers always find a healthy instance. Next, the simplest protection of all. Timeouts.
Key takeaways- Register on start
- Heartbeats
- Look up live addresses