StaffCoder
Spring Boot
Spring BootSpring Boot 4.1Java 25
12 modules · 48 challengesSign up
Module 12 · Microservices and Resilience

Service Registry Lookup Client

hard—No data yet

Problem statement

Implement the lookup path of a service registry client: every lookup resolves the peer address afresh, reaches it over the network, and turns each failure mode into its own status.

Requirements

InventoryLookupService

lookup(String sku)

  • Resolve the address published in the registry for the logical name inventory-service, ask the service at that address about the item, and answer with the sku, quantity and warehouse it reports
  • Ask the resolved service at /peers/inventory/ followed by the sku, relative to its published address, sending it a request over the network that the receiving service records as an inbound call. An answer produced inside this application instead of by the resolved service does not count
  • Resolve the address again for every lookup: once the same logical name is published against a different address, the next lookup is answered by the service at the new address and nothing further reaches the old one
  • If the registry publishes no address for inventory-service, fail with 503 and the message "Service not registered: inventory-service", and answer without sending a request to anything. Addresses published under other logical names do not make inventory-service resolvable
  • If the resolved service answers with a server error, fail with 502 and the message "Inventory service call failed"
  • If the resolved service answers that it does not know the sku, fail with 404 and the message "Item not found with sku: " followed by the requested sku
  • If the resolved service takes longer to answer than the wait limit, fail with 504 and the message "Inventory service timed out". The limit is the number of milliseconds configured under registry.client-timeout-ms, and an answer that arrives inside it is returned as a normal result however slow it was
  • Resolve every lookup on its own: an unpublished address, a server error, an unknown sku or a slow answer changes nothing for the lookups that follow, and each of them is answered from what the registry and the resolved service say at that moment

InventoryController

getInventory(String sku)

  • Answer GET /inventory/{sku} with 200 OK and the resolved item as the response body
  • A failed lookup answers with the status and the message listed above

Provided registry and stand-in services

  • The ServiceRegistry holds logical names against network addresses and starts empty; POST /registry and GET /registry publish and read entries
  • Two stand-in inventory services are served by this same application, at /peers/inventory/{sku} and /mirror/peers/inventory/{sku}, each answering with sku, quantity and warehouse and recording every inbound request
  • A support PeerControl can stock those services, make them answer with a server error, or make them answer slowly
  • A client builder carrying the configured wait limit is provided as a bean, as are the response types, the domain exceptions and the error handler

Sample Requests & Responses

Expand to view details on sample requests and responses.

Each stand-in inventory service starts stocked with SKU-1001 and SKU-2002, so the running application can be tried out by hand.

GET /inventory/SKU-1001 before anything is published in the registry

Response (503 Service Unavailable):

{
   "error": "Service not registered: inventory-service",
   "timestamp": "2026-08-11T10:00:50.041800Z",
   "path": "/inventory/SKU-1001"
}

POST /registry

Request:

{
   "logicalName": "inventory-service",
   "baseUrl": "http://localhost:8000"
}

Response (201 Created):

{
   "logicalName": "inventory-service",
   "baseUrl": "http://localhost:8000"
}

GET /registry

Response (200 OK):

[
   {
      "logicalName": "inventory-service",
      "baseUrl": "http://localhost:8000"
   }
]

GET /inventory/{sku}

Response (200 OK):

{
   "sku": "SKU-1001",
   "quantity": 42,
   "warehouse": "WH-NORTH"
}

GET /inventory/{sku} for a sku the resolved service does not stock

Response (404 Not Found):

{
   "error": "Item not found with sku: SKU-9999",
   "timestamp": "2026-08-11T10:00:50.250682Z",
   "path": "/inventory/SKU-9999"
}

GET /peers/inventory/{sku} on the provided stand-in service

Response (200 OK):

{
   "sku": "SKU-2002",
   "quantity": 7,
   "warehouse": "WH-SOUTH"
}

GET /inventory/SKU-1001 after inventory-service is published against an address that never answers

Response (504 Gateway Timeout):

{
   "error": "Inventory service timed out",
   "timestamp": "2026-08-11T10:01:01.450468Z",
   "path": "/inventory/SKU-1001"
}

More in Microservices and Resilience

See the module
Edge Router with Rate LimitingThis problem covers passing calls on to backing services by their path, while holding each caller to a call allowance.—No data yethardFallback Cache for Downstream OutageThis problem covers serving rates from a live feed and falling back to the last known answer while that feed is down.0%0 of 1 solvedhardRide Hailing Dispatch PlatformThis problem covers coordinating three network calls, backing off from one that keeps failing, and undoing work that cannot be completed.50%1 of 2 solvedhard

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.