Architecture

Service Discovery

Understanding service discovery in microservices architecture.

3 min readConcepts · System Design

What is Service Discovery?

Service Discovery is the mechanism by which services locate each other in a distributed system. In dynamic environments where services scale up/down and IP addresses change, hardcoding addresses is impractical.


The Problem

The ProblemFlowchart

What if Service B scales or moves?


Service Discovery Types

Client-Side Discovery

Client queries registry and chooses which instance to call:

Client-Side DiscoveryFlowchart

Examples: Netflix Eureka, Consul (client mode)

Server-Side Discovery

Load balancer queries registry and routes request:

Server-Side DiscoveryFlowchart

Examples: AWS ALB, Kubernetes Services


Service Registry

Central database of service instances:

ServiceInstanceStatusMetadata
user-svc10.0.0.1:8080Healthyv2.1
user-svc10.0.0.2:8080Healthyv2.1
order-svc10.0.0.3:8080Healthyv1.5

Registration Patterns

Self-Registration

Service registers itself on startup:

Self-RegistrationFlowchart

Third-Party Registration

Separate registrar watches and registers services:

Third-Party RegistrationFlowchart

Health Checking

Ensure only healthy instances receive traffic:

MethodDescription
HeartbeatService sends periodic "I'm alive"
Active probeRegistry pings service endpoint
TTLEntry expires if not renewed

ToolTypeFeatures
ConsulGeneral purposeService mesh, KV store
etcdKey-valueKubernetes backing store
ZooKeeperCoordinationLeader election
EurekaNetflix OSSJava-focused
Kubernetes DNSNativeBuilt into K8s

Kubernetes Service Discovery

# Service definition
apiVersion: v1
kind: Service
metadata:
  name: user-service
spec:
  selector:
    app: user
  ports:
    - port: 80
      targetPort: 8080

Access via DNS: user-service.namespace.svc.cluster.local


Interview Tips

  • Explain client-side vs server-side discovery
  • Describe service registry and health checks
  • Know tools: Consul, etcd, Kubernetes DNS
  • Discuss registration patterns (self vs third-party)
  • Mention challenges: consistency, availability of registry

Finished reading?

Mark it done to track your progress in Concepts.