Skip to content
Ameen Abozaid
MID-036

Service discovery

  • 5 Lessons
  • 1.5 h practice (estimate)
On this page 8 topics

Overview

Topics

  • DNS-based discovery
  • platform-native discovery
  • load balancing

Learn first

1.5 h of practice (estimate)

Learning outcomes

  1. Explain client-side vs server-side discovery and load balancing.
  2. Use DNS-based discovery (Docker Compose now, Kubernetes Services in MID-057).
  3. Explain health-check-driven routing and what happens to in-flight requests during deployment.

Lessons

  1. 01Finding services
  2. 02DNS-based discovery
  3. 03Platform-native discovery
  4. 04Load-balancing strategies
  5. 05Demo: scaling inventory to three replicas

Lab and exercises

Lab

MID-036-LAB1 · Scale out

Outcomes: 1–3 · Time: ~1.5 h Run three inventory replicas behind Compose DNS (no fixed host ports). Make orders call inventory by name and log which replica answered. Run a load test and kill one replica partway through. Record error counts and latency before, during, and after.

Acceptance: errors are limited to in-flight requests on the killed replica; a short written explanation says why, and what retries and graceful shutdown would change.

Exercises (assessment: quiz)

IDOutcomeTask
MID-036-EX011Compare client-side and server-side discovery in a table with an example of each.
MID-036-EX022Replace hard-coded hosts in the Shop config with Compose service names and environment variables.
MID-036-EX032Show that DNS resolves inventory to several addresses inside the Compose network and explain JVM caching effects.
MID-036-EX043Explain what a readiness probe does for routing during a rolling deployment.
MID-036-EX051Choose a load-balancing strategy for fast uniform GETs and for mixed fast and slow requests.
MID-036-EX063List steps for a graceful shutdown of a Spring Boot service so in-flight requests finish.
Show solutions
  • EX01 Client-side: caller asks a registry and picks (Eureka). Server-side: caller uses a stable name or proxy that picks (Compose DNS, Kubernetes Service). Client-side adds library and registry; server-side hides it.
  • EX02 INVENTORY_URL: http://inventory:8080 in Compose and @Value("${inventory.url}") or a property class.
  • EX03 From the orders container, getent hosts inventory (or nslookup) lists addresses; JVM and HTTP client caches plus keep-alive connections can pin traffic to one replica.
  • EX04 Only instances reporting ready receive traffic; new Pods join after passing readiness and old ones leave before termination, so traffic does not hit instances that are starting or stopping.
  • EX05 Round robin for uniform GETs; least connections (or power of two choices) for mixed durations.
  • EX06 Enable server.shutdown=graceful, set a shutdown timeout, fail readiness first, wait for load balancer to stop sending traffic, then finish in-flight work and exit (verify property names for your Spring Boot version).

Outcome 3 is also covered by quiz Q08 to Q10.

Quiz

Outcomes: O1 discovery and balancing styles · O2 DNS-based discovery · O3 health-driven routing and deployments.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1In client-side discovery, who picks the instance?O1
  2. 2Which is server-side discovery?O1
  3. 3Least-connections balancing suits:O1
  4. 4In Docker Compose, services reach each other by:O2
  5. 5Why can balancing look uneven with keep-alive connections?O2
  6. 6A hard-coded replica IP:O2
  7. 7A readiness probe decides:O3
  8. 8When a replica is killed during load, errors are mostly:O3
  9. 9Graceful shutdown helps by:O3
  10. 10On a platform that already provides discovery, adding a registry is:O3

Practical part

Six exercises MID-036-EX01 to EX06 plus MID-036-LAB1. Pass: at least five exercises, 8 of 10 quiz answers, and a lab run with errors limited to in-flight requests and a correct explanation.

Common mistakes

Hard-coded hosts; service registries added where the platform already provides discovery.

Assessment

Quiz.

Career relevance

Kubernetes Services (MID-057) and service mesh (SRB-009).

Type to search levels, phases, modules and lessons.