← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

Service Discovery Patterns

Architecture Intermediate
debt(d8/e6/b7/t6)
d8 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'silent in production until users hit it' (d9), slightly better at d8 because misconfigured readiness probes or DNS caching only manifest during rolling deployments or scaling events — no linter or SAST catches 'you forgot to configure a readiness probe' or 'your PHP-FPM worker is caching DNS'. Kubernetes manifest linters can flag missing probes but not their correctness.

e6 Effort Remediation debt — work required to fix once spotted

Closest to 'cross-cutting refactor across the codebase' (e7), adjusted down to e6 because while the quick_fix (use service names not IPs) is mechanical, fixing the systemic issues — adding retries with backoff, configuring DNS TTL across PHP-FPM workers, switching service types — touches deployment manifests, client code, and infrastructure config across multiple components.

b7 Burden Structural debt — long-term weight of choosing wrong

Closest to 'strong gravitational pull' (b7) — service discovery choice shapes every inter-service call, deployment strategy, health-check design, and failure-handling pattern. Switching from client-side (Consul) to server-side (Kubernetes Services) or vice versa is a major undertaking that affects all callers.

t6 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7), adjusted to t6 because the misconception is explicit: developers assume Kubernetes 'handles it' and skip readiness probes, leading to traffic hitting unready pods. The behavior contradicts the naive mental model where 'Service exists = traffic routes correctly', but it's a well-documented gotcha most teams hit once.

About DEBT scoring →

Also Known As

service registry Consul service location DNS service discovery

TL;DR

The mechanism by which services in a distributed system locate each other's network addresses — eliminating hardcoded IPs by maintaining a registry that services register with and query at runtime.

Explanation

In a dynamic microservices environment, service instances start, stop, and move constantly — hardcoded IP addresses are untenable. Service discovery solves this with two main patterns. Client-side discovery: the client queries a service registry (Consul, etcd, ZooKeeper) directly and load-balances among returned instances. Server-side discovery: the client sends requests to a load balancer or API gateway that queries the registry internally — the client is unaware of the registry. Service registries can be self-registration (each service registers itself on startup and deregisters on shutdown) or third-party registration (an external system like Kubernetes watches for containers and updates the registry). DNS-based discovery (Kubernetes Services, AWS Route 53) is a common simplification.

Common Misconception

Kubernetes eliminates the need to understand service discovery. Kubernetes implements server-side discovery transparently, but you still need to understand it to: configure readiness probes correctly (ensures instances register only when ready), understand DNS TTL behaviour, diagnose connection refused errors during rolling deployments, and choose between ClusterIP, NodePort, and LoadBalancer service types.

Why It Matters

Service discovery is why microservices can scale — instances spin up and down without reconfiguring callers. Kubernetes Services are the most common implementation today: a stable DNS name and virtual IP that routes to healthy pods. Understanding the pattern explains why Kubernetes service names work as hostnames and why you should never hardcode pod IPs.

Common Mistakes

  • Not configuring readiness probes — pods receive traffic before they are ready, causing request failures during deployments.
  • Using NodePort services for internal communication — NodePort exposes on every node IP; use ClusterIP for internal traffic.
  • Ignoring DNS caching in long-running PHP processes — PHP-FPM workers cache DNS resolutions; configure dns_cache_ttl or use a service mesh for real-time discovery.
  • Not handling connection refused gracefully during rolling updates — implement retries with exponential backoff when calling other services.
  • Treating service discovery as a single mechanism — client-side (Eureka, Consul) vs server-side (load balancer) have different failure modes; know which one you are using.

Code Examples

✗ Vulnerable
# ❌ Hardcoded IP — breaks on every pod restart
# config.php
define('PAYMENTS_URL', 'http://10.0.2.15:8080');

# ❌ Using pod IP from kubectl get pods — ephemeral
curl http://$(kubectl get pod payments-xxx -o jsonpath='{.status.podIP}'):8080/health
✓ Fixed
# ✅ Kubernetes Service DNS — stable, load-balanced
# config.php
define('PAYMENTS_URL', 'http://payments-service:8080');
// Resolves to the ClusterIP of the payments Service
// Kubernetes kube-proxy load-balances across healthy pods

# ✅ Kubernetes Service manifest
apiVersion: v1
kind: Service
metadata:
  name: payments-service
spec:
  selector:
    app: payments   # Matches pods with this label
  ports:
    - port: 8080
      targetPort: 8080

# ✅ With readiness probe — pod only registered when ready
readinessProbe:
  httpGet:
    path: /health
    port: 8080
  initialDelaySeconds: 5
  periodSeconds: 10

Added 23 Mar 2026
Edited 18 Apr 2026
Views 133
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 0 pings F 2 pings S 1 ping S 0 pings M 1 ping T 0 pings W 0 pings T 1 ping F 0 pings S 1 ping S 0 pings M 2 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 2 pings M 0 pings T 1 ping W 0 pings T 0 pings F
No pings yet today
No pings yesterday
ChatGPT 60 Perplexity 16 Amazonbot 15 Google 8 SEMrush 8 PetalBot 7 Bing 6 Scrapy 6 Ahrefs 5 Majestic 2 Applebot 2 Meta AI 1 Twitter/X 1 Baidu 1
crawler 135 crawler_json 3
DEV INTEL Tools & Severity
⚙ Fix effort: Medium
⚡ Quick Fix
In Kubernetes, always use Service names as hostnames (http://payments-service) not pod IPs. Configure readiness probes so pods are not registered until they are actually ready to serve traffic.
🔗 Prerequisites


✓ schema.org compliant