Service Discovery in Microservices
Learn client-side and server-side service discovery patterns using tools like Consul, Eureka, and Kubernetes DNS.
srikanthtelkalapally888@gmail.com
Service Discovery in Microservices
Service discovery lets microservices find and communicate with each other dynamically, without hardcoded IPs.
The Problem
In dynamic environments, service instances:
- Scale up/down
- Restart with new IPs
- Move across hosts
Hardcoded endpoints break this dynamic nature.
Discovery Patterns
Client-Side Discovery
Client queries a service registry and chooses an instance.
Client → Registry → Get all instances of UserService
Client → Choose instance (load balance)
Client → Call UserService:8080
Tool: Netflix Eureka
Server-Side Discovery
Client calls load balancer which queries registry.
Client → Load Balancer → Registry lookup → Route
Tool: AWS ALB, Kubernetes
Service Registry
| Tool | Type | Features |
|---|---|---|
| Consul | Distributed KV | Health checks, DNS |
| Eureka | Netflix OSS | Simple HTTP |
| Zookeeper | Coordination | Strong consistency |
| k8s DNS | Built-in | CoreDNS-based |
Health Checks
Registry regularly polls services:
GET /health → 200 OK (healthy)
GET /health → 500 (removed from registry)
Self-Registration
Services register themselves on startup, deregister on shutdown.
Kubernetes DNS
In K8s, each Service gets a stable DNS name:
user-service.default.svc.cluster.local
Conclusion
Server-side discovery with Kubernetes DNS is the modern default. Use Consul for multi-cloud or VM-based environments.