AI Hints
Home›System Design Tutorial›Services and Timeouts
System Design · Lesson 77 of 120

Service Discovery

Finding each other.

⏱ 2 min read▶ Video at 1:32:42🎓 Free
Watch this lesson in the System Design courseWatch on YouTube ↗Full System Design course

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?

Service Discovery
From the video: Service Discovery
  • 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.

  1. Server starts
  2. Registers address
  3. Sends heartbeats
  4. Callers look up
  5. Dead ones removed
A service registry
From the video: A service registry

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.

keyvalue
Kubernetesstable service names
Consula registry
Service meshdiscovery + retries
DNSoften 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
Next up: Timeouts — never wait forever