Gateway Routing: One Entry Point That Sends Each Request to the Right Service
Learn how one gateway in front of many services lets apps keep one address while the back end is split, moved, or upgraded.
In short
Gateway routing puts one gateway in front of many services so apps keep one address while each request is sent to the right service behind it.
12 min readFree
What You Will Learn
Many systems start as one big program. As they grow, teams split them into smaller services, and then every app that uses them must know many addresses. This lesson teaches Gateway Routing, a design pattern that solves that problem. You will learn what a gateway is, how it picks a destination for each request, how a team can change the back end without touching the app, and what risks the gateway itself brings.
Key words
- Service
- A small program that does one job, such as handling orders or user accounts.
- Endpoint
- A specific address where a service accepts requests, such as a path on a web address.
- Client
- Any program that sends requests, such as a phone app or a web browser.
- Gateway
- A server that receives incoming requests first and passes each one on to the right place.
- Reverse proxy
- A server that stands in front of other servers, takes their requests, forwards them, and returns their replies.
- Backend
- A service behind the gateway that does the real work.
- Request attribute
- A detail of a request that a gateway can read, such as its path, host name, header, or method.
- Host name
- The domain part of a web address, such as api.shop.com.
- Header
- Extra labeled information sent with a request, such as a version tag.
- Routing rule
- An instruction that says, for example, if the path starts with /orders/, send the request to the order service.
What Is the Problem Without a Gateway?
Picture a shop app that calls the user service, the order service, and the search service directly. Each service has its own address, so the app must store every address and know which service owns which task. That works on day one. It becomes fragile once the back end starts to change.
Clients hold many addresses
Each app build stores a list of service addresses. Changing one address means shipping a new app version, and users do not always install updates quickly.
Every move breaks a caller
If a team moves a service to a new server or renames its path, every caller that still uses the old address fails until someone updates it.
Internal design leaks out
Callers can see how the back end is cut up. Splitting one service into three turns one known address into three, and the app has to learn all of them.
Gateway Routing fixes this by giving the app one front door. With this pattern, the client application only needs to know about a single endpoint and communicate with a single endpoint. The rest of the layout becomes the gateway's job.
How Does Routing Work?
The gateway sits at one public address. It reads parts of each incoming request, compares them with its rules, and forwards the request to the backend that matches. Then it returns the reply. You can use an API gateway as a reverse proxy to route client requests to different application services. The client never needs to know which backend answered.
- 1
Receive the request
The client sends a request to the one public address, such as api.shop.com.
- 2
Read its details
The gateway looks at details it can see, such as the path, the host name, a header, or the method.
- 3
Find the matching rule
It searches its rules for one that fits the request. A common rule matches a path prefix, such as /orders/ and everything under it.
- 4
Forward to the backend
It sends the request to the chosen service using that service's real internal address.
- 5
Return the reply
The backend answers the gateway, and the gateway passes the answer back. The client only ever sees the public address.
The gateway can also check more than the path. The gateway can route based on multiple criteria — path, query parameters, HTTP method, request headers, API version — and can perform transformations on the way in or out. In this lesson we focus on the routing part only.
Routing at this layer is called layer 7 routing. Layer 7 means the gateway works with the content of the HTTP request, such as its path and headers. Application Gateway is a managed load balancing service. It provides perform layer-7 routing, SSL termination, and a web application firewall (WAF). Load balancing means spreading requests across several copies of a service. SSL termination means the gateway opens the encrypted connection from the client, so the services behind it do not have to. A WAF is a filter that blocks common web attacks. Other products that do the same job include the open-source reverse proxies NGINX and HAProxy, which support features such as load balancing, SSL termination, and layer-7 routing.
Keep one point clear. A gateway is useful when many services sit behind one entry point. A microservices architecture does not automatically require a gateway. Choose it because it solves a real problem for your team.
How Are Request Attributes Matched?
A rule is a test on one or more request attributes. The most common test is the path. A rule might say that any request whose path starts with /products/ goes to the catalog service. Other tests work the same way. The host name can separate api.shop.com from admin.shop.com. A header can carry an API version, so version 2 clients reach a newer service. The method can separate reads from writes, so GET and POST go to different places. When a rule has several tests, the request must pass all of them to match.
Tip
Start with path rules. They are easy to read, easy to test, and cover most early cases. Add header or method rules only when you have a clear reason.
Rules in Practice
The code below is a tiny model of a routing table. It is not a real gateway, but it shows the core idea. Each rule maps a path prefix to a backend name. The first rule that matches wins in this model. Real products use their own matching order, so always check the rules of the product you use.
rules = [
("/products/", "catalog"),
("/orders/", "orders"),
]
def route(path):
for prefix, backend in rules:
if path.startswith(prefix):
return backend
return "not found"
for path in ["/orders/42", "/products/7", "/cart"]:
print(path, "->", route(path))
Output
/orders/42 -> orders /products/7 -> catalog /cart -> not found
Notice what the app does not contain. It holds no service addresses at all. It sends /orders/42 to the same public host as before. Only the table on the gateway knows that orders live somewhere else.
Worked Example: An Online Shop
An online shop serves everything from api.shop.com. At first, one large program handles products, orders, and accounts. The team then splits it. The phone app should keep calling the same address. Here is how the gateway makes that possible, using NGINX as the gateway.
- 1
Start with one address
All requests to api.shop.com go to the old monolith. The phone app calls api.shop.com/orders/42 and gets an answer.
- 2
Add the catalog rule
The team deploys a catalog service and adds a rule so that every path under /products/ goes to it.
- 3
Add the order rule
The team deploys an order service and adds a rule so that /orders/ and everything under it goes to that service.
- 4
Move orders to a rewritten service
Later, the team builds a rewritten order service. They edit the single orders rule to point at the new service. The phone app is not changed or re-released.
- 5
Check the result
The team sends a test request to api.shop.com/orders/42 and confirms that the new service answers. If something breaks, they can point the rule back at the old service.
The configuration below shows the idea in NGINX. Each location block is a rule. The proxy_pass line names the backend. The rewritten service is called orders-v2, and only its line changed.
server {
listen 80;
server_name api.shop.com;
location /products/ {
proxy_pass http://catalog-service:8080;
}
location /orders/ {
proxy_pass http://orders-v2:8080;
}
}
This setup has a detail worth knowing. When proxy_pass has no path of its own, Nginx forwards the path exactly as the client sent it. That means the rewritten order service must accept the same /orders/ paths the old one did. If it uses different paths, you need a rewrite step, and that is where mistakes often hide. Azure Application Gateway is a managed layer-7 load balancer with SSL termination and a web application firewall.
How Do You Move Services and Roll Out Safely?
Once the gateway holds the rules, the back end can change freely. A team can split a service, rename it, move it to new servers, or run two versions side by side. The clients only notice if the gateway's public behavior changes. That is the main benefit: the app stays stable while the team works behind the door.
The same tool supports careful releases. This pattern can be used for deployments, by allowing you to manage how updates are rolled out to users. Instead of switching everyone at once, the team can send a small share of traffic to the new version and watch for errors.
Moving a service
Point one rule at the new server. Callers keep the same address and never see the move.
Running two versions
Route one path to version 1 and another path, or a header value, to version 2. Old and new versions can live together for a while.
Gradual rollout
Send a small share of requests to the new version, then raise the share as confidence grows.
The next sample models a 10 percent rollout. It sends every tenth request to the new version. Real gateways usually offer a weight setting for this, but the counting idea is the same.
def pick(n):
return "orders-v2" if n % 10 == 0 else "orders-v1"
counts = {"orders-v1": 0, "orders-v2": 0}
for n in range(100):
counts[pick(n)] += 1
print(counts)
Output
{'orders-v1': 90, 'orders-v2': 10}
Tip
Change one rule at a time, and keep a note of the old setting. If the new version fails, the fastest fix is usually to switch the rule back.
What Are the Trade-offs and Cautions?
Gateway Routing is powerful, but it adds a new part to the system. Every request now passes through the gateway, so its health and speed matter to everything else. Here are the main risks.
Single point of failure
If the only gateway stops, every client loses access to every service, even healthy ones. Run more than one gateway behind a stable address, so a failed copy can be replaced.
Possible bottleneck
The gateway service can introduce a bottleneck. A slow gateway slows every request, so measure its speed under real load.
Business logic creep
Teams are tempted to add pricing, discounts, or other business rules to the gateway. That turns a simple router into a hard-to-change program that every team depends on.
Redundancy and monitoring are the usual answers to the first two risks. Gateway routing enables you to route traffic to only healthy nodes in your system. A gateway that checks backend health can stop sending traffic to a broken service. Monitoring should show request counts, errors, and response times for each route, so problems appear before users complain.
The third risk needs discipline. The key is keeping it thin — routing, auth, rate limiting, and observability belong in the gateway; business logic does not. Keep the gateway focused on finding the right destination. Put shop rules inside the services that own them.
Small systems may not need the pattern at all. This pattern might not be suitable when you have a simple application that uses only one or two services. Weigh the extra part against the benefit of hiding change from clients.
Rules also need upkeep. When you update services or add new ones, you might need to update the gateway routing rules. Treat rule changes like code changes, with a review and a record of who changed what.
Check Your Understanding
Quick check
A team splits its single monolith API into user, payment, and search services. The mobile app is already released and cannot be updated quickly. What should the team put in front of the services so the app keeps one address?
Quick check
A team wants to test a new order service with a small share of real users. The app must not change. Which setup gives the safest test?
Key Takeaways
Gateway Routing puts one entry point in front of many services. The gateway reads request details such as the path, host name, header, or method, finds the matching rule, and forwards the request to the right backend. Clients keep one address, so teams can split, move, rename, and version services without breaking apps. The same rules can also send a small share of traffic to a new version. The cost is a new component that must be redundant, monitored, and kept simple. Use it when several services need one front door, and keep business logic out of the gateway.
Sources
- Gateway Routing pattern, Azure Architecture Center (Microsoft Learn)
- API gateways in microservices, Azure Architecture Center (Microsoft Learn)
- The API gateway pattern versus direct client-to-microservice communication, .NET Architecture Guide (Microsoft Learn)
- NGINX Reverse Proxy admin guide (docs.nginx.com)
- Nginx Reverse Proxy: How to Configure proxy_pass and Headers (Linuxize)
- API Gateway vs Reverse Proxy: Differences and Use Cases (API7.ai)
- API Gateway Patterns for Microservices 2026 (apiscout.dev)
- API Gateway Patterns: More Than Just a Reverse Proxy (James Ross Jr.)
Last updated on 18 November 2026
Related lessons
Learn with me
Every lesson is free. I add new ones as I learn. Have a question, or want help with your own work? Book a short call.