Service discovery
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
- Explain client-side vs server-side discovery and load balancing.
- Use DNS-based discovery (Docker Compose now, Kubernetes Services in MID-057).
- Explain health-check-driven routing and what happens to in-flight requests during deployment.
Lessons
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)
| ID | Outcome | Task |
|---|---|---|
| MID-036-EX01 | 1 | Compare client-side and server-side discovery in a table with an example of each. |
| MID-036-EX02 | 2 | Replace hard-coded hosts in the Shop config with Compose service names and environment variables. |
| MID-036-EX03 | 2 | Show that DNS resolves inventory to several addresses inside the Compose network and explain JVM caching effects. |
| MID-036-EX04 | 3 | Explain what a readiness probe does for routing during a rolling deployment. |
| MID-036-EX05 | 1 | Choose a load-balancing strategy for fast uniform GETs and for mixed fast and slow requests. |
| MID-036-EX06 | 3 | List 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:8080in Compose and@Value("${inventory.url}")or a property class. - EX03 From the
orderscontainer,getent hosts inventory(ornslookup) 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.
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).