Microservices Patterns/Service Discovery & Registration

Discovery & Registration Patterns

Client-side vs server-side discovery, Consul/etcd/Kubernetes DNS, service registry lifecycle, and CAP trade-offs at the catalog layer.

3/5Overview: 35m

Why discovery exists

IPs and ports change on every deploy, autoscale event, and spot interruption. Clients need a stable namecurrent healthy instances.

Client-side vs server-side discovery

PatternFlowExamples
Client-sideClient queries registry, picks instance, connectsgRPC + xDS, Netflix Eureka + Ribbon (legacy), Consul agent
Server-sideClient → load balancer → registry-backed poolAWS ALB/NLB, K8s Service + kube-proxy, Envoy gateway

Server-side — simpler clients, LB is chokepoint. Client-side — smarter routing (latency-aware, subset), harder client libraries.

Service registry

Catalog of {service_name → [(host, port, metadata)]}.

Registration:

  • Self-registration — service starts, registers with Consul/etcd, deregisters on shutdown
  • Third-party — K8s controller watches pods, updates Endpoints

Deregistration on crash — TTL heartbeats; stale entries removed after missed beats.

Kubernetes model (interview staple)

Pod → labeled → Service (ClusterIP) → Endpoints object → kube-proxy/iptables or eBPF → DNS: my-svc.namespace.svc.cluster.local
  • ClusterIP — internal VIP, not routable outside cluster
  • Headless Service (clusterIP: None) — DNS returns pod IPs directly (StatefulSets, Cassandra)

Consul / etcd as registry

  • Consul — service catalog + health checks + KV + mesh connect
  • etcd — K8s' backing store; not usually called directly by apps

Distributed Systems → Consensus owns Raft/etcd correctness — here: apps consume the catalog API.

DNS-based discovery

Simple: payments.prod.internal → multiple A records (round-robin DNS).

Weaknesses: TTL caching, no health awareness, limited load balancing. Fine for stable fleets; K8s DNS is richer.

Service mesh discovery

Istio/Linkerd use service identity + control plane pushing endpoint lists to sidecars (xDS). App connects localhost:sidecar; sidecar knows real backends.

Failure modes (staff depth)

  • Thundering herd — registry restart, all clients refresh simultaneously
  • Stale cache — client holds dead instance until TTL
  • Split brain registry — rare with Raft; know health check design matters

Cross-reference: Networking DNS and L7 LB; Communication → gRPC for why connection reuse needs L7-aware balancing.

Further Reading

Hands-On Tasks (Optional)

Architecture drills and whiteboard exercises. Assumes Communication & Data Transfer and Distributed Systems fundamentals.

  • Choose discovery for three environments

    Bare-metal VMs, Kubernetes EKS, serverless Lambda calling internal gRPC. Specify registry, DNS name, and how clients resolve healthy instances.

    15m