Skip to content

Service Discovery

In one line

Service discovery finds service instances dynamically — essential when containers scale up and down constantly.

In simple words

Service discovery is how services find each other in a dynamic environment where instances are constantly created and destroyed. Instead of hardcoding IP addresses, services register themselves and look up others dynamically.

Two patterns: client-side (client queries registry) and server-side (load balancer queries registry). Two types: DNS-based (Kubernetes DNS) and key-value store (Consul, etcd).

Example

javascript
// Kubernetes DNS: reach service by name
const res = await fetch('http://my-api.production.svc.cluster.local:8080/users');
// Consul: discover healthy instances
const services = await consul.health.service({ name: 'user-service', passing: true });

Kubernetes DNS lets services find each other by name. Consul provides a registry with health checks — only healthy instances are returned.

Common confusions

  • Confused with: Load Balancer

    The difference: A load balancer distributes traffic across known instances. Service discovery finds what instances exist in the first place. They work together.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary