What is Service Discovery and how does Eureka work?

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)

  1. Eureka Server starts

  2. Microservices register with Eureka

  3. Services send heartbeats every 30 seconds

  4. Eureka removes unhealthy services

  5. Clients fetch registry & cache it locally

  6. 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:
register-with-eureka: false
fetch-registry: false

Eureka Client

eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka

🔹 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?

Leave a Reply