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?