Service Discovery Pattern

Category:

Service Discovery enables services to register themselves and discover other services dynamically, removing the need to hardcode IPs/ports/URLs.

Two Roles:

  1. Service Registry: A central database that tracks service instances (e.g., Eureka, Consul, etcd)
  2. Service Client:
    • Register itself with the registry (if it’s a server)
    • Query registry to find other services (if it’s a consumer)

When to Use It

You need Service Discovery when:

SituationWhy You Need It
Services scale dynamicallyTheir IPs/ports change frequently
You deploy in cloud/KubernetesPods and containers are ephemeral
You want resilience + flexibilityAvoid hardcoded URLs
You want load-balanced discoveryIntegrate with client-side LB

Service Discovery Options

ToolUse Case
EurekaSpring Cloud / Netflix stack
ConsulMulti-platform, key-value + health
Kubernetes DNSBuilt-in DNS-based discovery
AWS Cloud MapAWS

Summary

ComponentRole
Eureka ServerService Registry
Eureka ClientRegisters with and queries Eureka
LoadBalancer (Ribbon or Spring LB)Chooses instance
RestTemplate / FeignMakes the call

When to Use Service Discovery

ScenarioUse Discovery?
Dynamic microservices (cloud)✅ Yes
Monolith or fixed deployment❌ No
Containerized (K8s, ECS) apps✅ Yes
Static VM-based architecture❌ Often not


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *