Why discovery exists
IPs and ports change on every deploy, autoscale event, and spot interruption. Clients need a stable name → current healthy instances.
Client-side vs server-side discovery
| Pattern | Flow | Examples |
|---|---|---|
| Client-side | Client queries registry, picks instance, connects | gRPC + xDS, Netflix Eureka + Ribbon (legacy), Consul agent |
| Server-side | Client → load balancer → registry-backed pool | AWS 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 environments15m
Bare-metal VMs, Kubernetes EKS, serverless Lambda calling internal gRPC. Specify registry, DNS name, and how clients resolve healthy instances.