Path-Based Routing (Mini API Gateway)

All challenges

Path-Based Routing (Mini API Gateway)

Your platform team consolidated three services behind one gateway host: the API service (/api/…), the static asset service (/static/…), and the admin service (/admin/…). The gateway is nginx — and whoever set it up left a single catch-all route pointing at the API service. Everything "works": every request gets a friendly 200. It's just that /static/app.css and /admin/stats are answered by the wrong service, with the wrong content, while two perfectly good services sit idle. No errors, no alerts — the sneakiest kind of broken.

System Architecture

/api /static /adminEVERYTHINGClient SimulatorNGINX GatewayAPI ServiceStatic ServiceAdmin Service

Your task

Turn nginx into a real gateway: route each path prefix to its own service — /api → api-service, /static → static-service, /admin → admin-service — so every request is answered by the service it was meant for.

You edit only nginx.conf (the nginx workload, cloned into your dev-vm):

  • The challenge is the location blocks. The backends answer at api-service:80, static-service:80, and admin-service:80, and every response body says who answered: {"service": "static-service", …}.
  • Commit + push → the platform rebuilds the image and restarts nginx.
  • A broken config fails nginx at startup — check the deployment logs.

Pass criteria

The grader checks every response body for which service actually answered, over ~1 minute:

  • Zero routing failures — no HTTP errors, and no wrong-service answers. A 200 from the wrong backend counts as a failure, exactly as production would eventually.
  • All three routes verifiably served — each family (/api, /static, /admin) shows a sustained rate of confirmed-correct answers. A route you forgot (or a service you cut off) fails on its own line.

Where to look

  • Logs — the simulator counts correct / misrouted / httpErrors; misrouted is the number you drive to zero.
  • dev-vm — for p in /api/users /static/app.css /admin/stats; do echo -n "$p -> "; curl -s http://nginx:80$p | grep -o '"service":"[^"]*"'; done.

Submit once misrouted has held at 0 for a clean minute — submissions are free, so your best score counts.

  • One location block per prefix; nginx picks the longest matching prefix, so the catch-all / can stay as a default.
  • proxy_pass http://upstream; (no URI) forwards the path as-is; proxy_pass http://upstream/; (with one) replaces the matched prefix. The backends echo the path they received — curl makes the difference obvious. Here the simple form is your friend.