Scrivio Interview library
DesignAdvanced6 min read · updated 12 November 2026

Teams use different context paths and ports for their services (some /, some /api, some /service-name), which complicates gateway routing, health checks and documentation. What standard would you set?

Run every service on the same internal port, for example 8080, with context path /, and let the gateway or ingress own the external path prefix. Keep Actuator on a standard path or a standard management port so health checks and scraping work the same everywhere, configure forwarded-header handling consistently so generated URLs are correct, put the standard in the service template and check it at deploy, and allow exceptions only with a reason, such as legacy clients tied to an old path.

Why this question is asked

Inconsistent ports and paths look harmless in one service and expensive across a hundred. Every gateway route needs a special case, health checks need a lookup table, documentation lists different base URLs, and a new engineer cannot guess where anything is. Interviewers ask this to see whether we can reduce variation without breaking what already works. In this answer, we will see what the variation costs, decide who should own each part of the address, set the standard for ports, paths and Actuator, make generated URLs correct, and plan enforcement and migration with exceptions.

1What the Variation Costs Today

Suppose the orders service uses port 8081 with context path /api, the billing service uses 8080 with /, and the shipping service uses 9000 with /shipping. The gateway now has a route per service that knows each one's port and how to rewrite its path. Kubernetes probes and the Prometheus scrape configuration must list three different health paths: /api/actuator/health, /actuator/health and /shipping/actuator/health. API documentation shows three styles of base URL, and links generated by the services follow three different rules.

None of this is hard for one service, but it multiplies, and each special case is a place for an outage: a gateway rewrite that drops a prefix, or a probe left on an old path that restarts healthy pods.

2Who Should Own Which Part of the Address

The cleanest split is that the platform owns the external address and the service owns only its internal one. The external path prefix, such as /orders in https://api.example.com/orders/..., is about routing and product structure, which is the gateway's job. Inside the cluster, each service is already identified by its Kubernetes Service name, such as http://orders:8080, so a prefix there adds nothing.

Step throughOne address, two owners
  1. Public URLhttps://api.example.com/orders/v1/items
  2. Gateway or ingressowns /orders, routes to the orders Service
  3. Kubernetes Serviceorders:8080, the internal name
  4. Spring Boot appport 8080, context path /, serves /v1/items
  5. Actuatorstandard path or port 9090, same in every service

5 layers, from the top down. Step through them one at a time.

The gateway owns the external prefix; every service looks the same inside.

3The Standard for Ports, Paths and Actuator

Every service listens on port 8080 with context path /. The gateway maps /orders/** to the orders service and strips the prefix, or passes it through with X-Forwarded-Prefix so the service knows it. Teams no longer choose a port or a path, which removes a decision that was never worth making.

Actuator is standardised in the same way. We pick one option and apply it everywhere: either /actuator on the main port, protected by path rules, or a separate management.server.port such as 9090 reachable only inside the cluster. Then probes, scrape configuration and dashboards are written once.

Properties
# Platform starter defaults: every service gets these unless it overrides them
server.port=8080
server.servlet.context-path=/
management.server.port=9090 # the platform's choice, the same everywhere
management.endpoint.health.probes.enabled=true
server.forward-headers-strategy=framework # applies X-Forwarded-* including Prefix
# One probe and scrape definition for all services, from the deployment template
# livenessProbe: { httpGet: { path: /actuator/health/liveness, port: 9090 } }
# readinessProbe: { httpGet: { path: /actuator/health/readiness, port: 9090 } }
# scrape: http://<pod>:9090/actuator/prometheus

4Making Generated URLs Correct Behind the Gateway

When the gateway strips /orders, the service sees /v1/items, and any link it builds, a redirect or a HAL link, would lack the prefix. The standard therefore includes forwarded-header handling: the gateway always sets X-Forwarded-Proto, Host, Port and Prefix and removes any copies sent by clients, and every service applies them with the same forward-headers-strategy from the starter. Then a link built by any service comes out as https://api.example.com/orders/v1/items without the service knowing its public address. Because the gateway is the only source of these headers, it is also the only place where they can be configured wrongly, which makes them easy to test.

5Enforcing the Standard and Handling Exceptions

A standard in a wiki page drifts within months. So the service template generates new services with the defaults, the platform starter carries them for existing services, and a deploy-time check reads the effective configuration and the deployment manifest and flags a service whose port, context path or management port differs from the standard without a recorded exception.

Exceptions are allowed when there is a real reason. The most common is a legacy client, for example a mobile app version still in the field that calls /api/orders directly, or a partner that cannot change a configured URL. For those, the gateway can keep the old public path and route it to the new internal layout, so the service itself still follows the standard and only the gateway carries the special case. The exception is written down with its reason and an end date, such as when the old app version falls below one percent of traffic.

Step throughBringing an existing service to the standard
  1. Do external clients depend on the old path?
    YesAdd a gateway route for the old pathNoChange the path directly
  2. Move the app to port 8080 and context path /
  3. Update gateway route and forwarded headers
  4. Probes and scraping from the shared template
  5. Links and redirects correct through the gateway?
    YesRemove the old route at its end dateNoFix headers, test again

5 steps in order. Play them, or step through them one at a time.

6Follow-up questions

Why not let each service keep its own context path as a namespace?

Because the Kubernetes Service name already namespaces it inside the cluster, and the gateway namespaces it outside. A third namespace in the context path only adds a rewrite rule to get wrong. Keeping / inside means the service can be moved behind a different external path without a code change.

Separate management port or main port with path rules?

A separate port is easy to keep off the public network with network policies, but it is a second listener whose probes check a different server than users hit. The main port keeps one listener but needs careful security rules. Either is fine; the standard's value comes from picking one and using it everywhere.

How do you migrate a hundred services without a big bang?

Change the starter defaults behind a flag, migrate service by service with the gateway keeping old public paths where needed, and verify each one with the same link and probe checks. The deploy check reports progress, so the remaining services are visible.

7Conclusion

In this answer, we set a standard where every service runs on the same internal port with context path /, and the gateway or ingress owns the external prefix. Actuator sits on a standard path or management port so probes and scraping are defined once, forwarded headers are set by the gateway and applied the same way in every service so URLs are correct, the standard lives in the template and starter with a deploy check, and exceptions such as legacy client paths are kept at the gateway with a reason and an end date.

What to say in the interviewAbout 90 seconds aloud

Open with

I would separate the internal address from the external one. Inside the cluster, every service runs on the same port, say 8080, with context path slash, because the Kubernetes Service name already identifies it.

Then, if they want more

Outside, the gateway or ingress owns the path prefix, like /orders, and routes it to the service. That makes gateway routes uniform and lets a service move behind a different public path without code changes.

Actuator gets the same treatment: we choose one approach, either a standard management port like 9090 that is only reachable inside the cluster, or /actuator on the main port with security rules, and apply it everywhere, so probes, Prometheus scraping and dashboards are written once in the deployment template.

Because the gateway strips or adds the prefix, forwarded headers must be handled consistently: the gateway sets X-Forwarded-Proto, Host, Port and Prefix and strips client copies, and every service applies them with the same forward-headers-strategy from the platform starter, so redirects and HAL links come out with the public URL.

The standard lives in the service template and the starter, and a deploy check flags differences. Exceptions need a reason, typically legacy clients on an old path, and I would keep those at the gateway as an extra route with an end date, so the service itself still follows the standard.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Boot reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Teams use different context paths and ports for their services (some /, some /api, some...": https://scrivio-interview-library.netlify.app/spring-boot/embedded-servers/a98f86ac94/