Skip to content

Service Registry

One-Liner

A database containing the network locations (IP addresses and ports) of service instances in a distributed system.

What It Is

A central component in a service discovery system that acts as a directory for all available service instances. Services register themselves upon startup and deregister upon shutdown.

Why It Exists

In dynamic cloud environments, service instances are ephemeral. Their network locations (IP addresses and ports) are constantly changing. A service registry provides a single, up-to-date source of truth for where services can be found.

How It Works

  • Registration: Service instances register their network location with the registry when they start.
  • Deregistration: Service instances remove their entry from the registry when they shut down.
  • Health Checking: The registry (or an external agent) periodically checks the health of registered services and removes unhealthy instances.
  • Discovery: Clients query the registry to find available instances of a particular service.

Tradeoffs

Pros

  • Enables dynamic discovery.
  • Critical for microservices architectures.
  • Improves resilience.

Cons

  • The registry itself becomes a critical component that needs to be highly available and fault-tolerant.

Failure Modes

  • Registry Outage: If the service registry goes down, services cannot find each other, leading to a system-wide outage.
  • Stale Data: If health checks are not robust or services fail to deregister, the registry might contain outdated information, leading clients to try to connect to non-existent services.

Interview Traps

  • Not understanding why a service registry is necessary in dynamic environments.
  • Not mentioning health checking as a critical component.

Real-World Usage

  • Consul, ZooKeeper, etcd are common technologies used as service registries.
  • Kubernetes has its own built-in service discovery mechanism.

Anti-Patterns

  • Hardcoding service IP addresses instead of using a registry.
  • Not implementing robust health checks.
  • Client-Side vs. Server-Side Discovery
  • Health Checks
  • Distributed Consensus