Intermediate14 min readยท Topic 4.4

Service discovery

Client-side vs server-side discovery, DNS-based, Consul, etcd, ZooKeeper

๐Ÿ”Key Takeaways

  • 1
    Service discovery solves 'how does Service A find Service B's IP address in a dynamic environment?'
  • 2
    Client-side: client queries a registry and chooses a server; Server-side: load balancer queries the registry
  • 3
    DNS-based is simplest but has TTL caching issues; dedicated registries (Consul, etcd) are more dynamic
  • 4
    In Kubernetes, kube-dns + Services provide built-in service discovery

Finding Services in Dynamic Environments

In microservices, services are deployed across many hosts with dynamic IPs. Containers start, stop, and move constantly. Hardcoded IP addresses are impossible. Service discovery is the mechanism by which services locate each other.

Discovery Patterns

Client queries the service registry (Consul, etcd) for available instances of the target service. Client picks one (with client-side load balancing).

Pros: No extra network hop, client can implement smart routing.

Cons: Every client needs discovery logic, language-specific client libraries required.

Service Discovery Tools

ToolTypeHealth ChecksKey Feature
ConsulRegistry + DNSHTTP, TCP, gRPC, scriptMulti-DC, service mesh integration
etcdDistributed KV storeVia watcher patternUsed by Kubernetes, strong consistency (Raft)
ZooKeeperCoordination serviceEphemeral nodes + sessionsApache ecosystem, battle-tested
Kubernetes DNSBuilt-in DNSReadiness/liveness probesNative to K8s, zero additional infra
AWS Cloud MapManaged registryRoute 53 health checksAWS-native, integrates with ECS/EKS

Advantages

  • โ€ขEnables dynamic, elastic microservice architectures
  • โ€ขAutomatic failover from unhealthy instances
  • โ€ขZero-config in Kubernetes

Disadvantages

  • โ€ขAdds infrastructure complexity
  • โ€ขRegistry itself must be highly available
  • โ€ขDNS caching creates stale routing

๐Ÿงช Test Your Understanding

Knowledge Check1/1

In Kubernetes, how is service discovery typically implemented?