What is Service Discovery?

In microservices, service instances:
-
Scale up/down dynamically
-
Change IPs frequently
👉 Service Discovery helps services find each other dynamically without hard-coded URLs.
🔹 Types of Service Discovery
1️⃣ Client-side Discovery
-
Client asks registry for service instances
-
Client chooses one (load balancing)
📌 Example: Eureka
2️⃣ Server-side Discovery
-
Load balancer queries registry
-
Client unaware of services
📌 Example: Kubernetes Service
🔹 What is Netflix Eureka?
Eureka is a service registry where:
-
Services register themselves
-
Other services discover them
It is commonly used with Spring Cloud Netflix.
🔹 Eureka Architecture
Service A ──register──▶ Eureka Server
Service B ──register──▶ Eureka Server
Service A ──discover──▶ Eureka ──returns──▶ Service B instance
🔹 How Eureka Works (Step-by-Step)
-
Eureka Server starts
-
Microservices register with Eureka
-
Services send heartbeats every 30 seconds
-
Eureka removes unhealthy services
-
Clients fetch registry & cache it locally
-
LoadBalancer selects instance
🔹 Why Eureka is Highly Available?
-
Clients cache registry
-
Even if Eureka goes down → services still talk
-
Self-preservation mode prevents mass eviction
🔹 Example Configuration
Eureka Server
Eureka Client
🔹 Eureka vs Consul
| Feature | Eureka | Consul |
|---|---|---|
| Health Check | Heartbeat | Active |
| DNS Support | ❌ | ✅ |
| KV Store | ❌ | ✅ |
| Service Mesh | ❌ | ✅ |
🔹 Real-World Example
💡 Payment Service scales from 2 → 10 instances
Eureka automatically updates registry
Clients start calling new instances
⭐ Interview One-Liner
“Eureka enables dynamic service discovery by allowing services to register and discover each other without hard-coded endpoints.”
🔹 Common Follow-Up Questions
-
What is Eureka self-preservation mode?
-
How does load balancing work with Eureka?
-
Eureka vs Kubernetes Service Discovery?