Implementing Request Routing via API Gateway
Imagine: you have 20 microservices, each with its own API version. Clients use different versions, and you need to deploy new ones without breaking compatibility. Without a single entry point, this becomes a nightmare—clients are tightly coupled to endpoints, and any change requires them to update. An API Gateway with flexible routing solves this in 1–2 days. We have implemented such systems for projects with 500+ API endpoints, ensuring 99.9% uptime. The average saving on one project is more than 150,000 rubles per year by reducing deployment time by 70%. We will assess your project for free within 1 business day.
Routing works on several levels: by URL path, HTTP headers, query parameters, and even by method. Combining them gives you full control over traffic. For example, you can direct enterprise clients to a dedicated cluster and others to a common pool. Or roll out a new version to 5% of users and monitor errors. Below we break down each type with configuration examples.
Routing Types: Comparison
| Type | Description | Example | Typical Scenario |
|---|---|---|---|
| Path-based | By URL path | /api/v1/users → users-service | API versioning |
| Header-based | By HTTP header | X-API-Version: 2 → v2 | Canary deployments |
| Query parameter | By query string | ?version=beta → beta | A/B testing |
| Method-based | By HTTP method | GET → read, POST → write | CQRS patterns |
Implementation in Kong
# Versioning via path prefix curl -X POST http://localhost:8001/services/users-v1/routes \ -d "paths[]=/api/v1/users" \ -d "strip_path=false" \ -d "name=users-v1-route" curl -X POST http://localhost:8001/services/users-v2/routes \ -d "paths[]=/api/v2/users" \ -d "strip_path=false" \ -d "name=users-v2-route" # Header-based routing curl -X POST http://localhost:8001/services/users-v2/routes \ -d "paths[]=/api/users" \ -d 'headers[X-API-Version][]=2' \ -d "name=users-v2-header-route" Implementation in Traefik
# dynamic/routing.yml http: routers: users-v1: rule: "PathPrefix(`/api/v1/users`)" service: users-v1-service priority: 10 users-enterprise: rule: "PathPrefix(`/api/users`) && Headers(`X-Tenant-Tier`, `enterprise`)" service: users-enterprise-service priority: 20 Traefik uses priorities: when multiple rules match, the one with the highest priority is chosen. This allows implementing exact routes (tenant-based) first, then general ones. In our projects, priorities reduced deployment time by 40%.
Implementation in NGINX
# /etc/nginx/conf.d/api-routing.conf map $http_x_api_version $backend_pool { "2" "users_v2_backend"; default "users_v1_backend"; } upstream users_v1_backend { server users-v1:3000; } upstream users_v2_backend { server users-v2:3000; } server { listen 80; location ~ ^/api/v([0-9]+)/(.+) { proxy_pass http://users_v${version}_backend/$path$is_args$args; } location /api/users { if ($http_x_tenant_tier = "enterprise") { proxy_pass http://enterprise-cluster; } proxy_pass http://users_v1_backend; } } Why Weighted Routing is Critical for Canary Deployments?
Canary routing is useful when you need to gradually roll out a new version and guarantee rollback on anomalies. We use weighted distribution: 95% traffic to the stable version, 5% to the new one. In Traefik, this is done via weighted services; in Kong, via a Lua plugin that selects upstream randomly. It is important to configure monitoring: according to our data, 80% of incidents are detected at 5% traffic, which allows reducing rollback time to 5 minutes. In one project, the client saved over 150,000 rubles per year by reducing deployment time.
Example of weighted routing configuration in Traefik
# Traefik weighted http: services: users-canary: weighted: services: - name: users-stable weight: 95 - name: users-canary weight: 5 Scenarios Covered by Routing
Beyond versioning and canaries, routing addresses tenant isolation (separating traffic by tenants), A/B testing (sending 50% of requests to an experimental version), and sticky routing (binding a client to one backend). For example, via the header X-Tenant-ID, you can direct enterprise clients to a dedicated cluster with guaranteed resources, and others to a common pool. This reduces latency for VIP clients by 30%. Real-time route monitoring (via Prometheus + Grafana) allows tracking errors and automatically rolling back on anomalies.
Tool Comparison: Kong vs Traefik vs NGINX
| Tool | Configuration | Priorities | Lua plugins | Performance |
|---|---|---|---|---|
| Kong | REST API + Dashboard | Yes | Yes | High (up to 50k rps) |
| Traefik | YAML/TOML | Yes | No (middlewares) | High (auto-reload) |
| NGINX | Nginx config | Via map/location | No (only modules) | Very high (100k+ rps) |
Tool choice depends on needs: Kong for complex logic with Lua, Traefik for dynamic environments (Kubernetes), NGINX for maximum performance. For example, NGINX handles up to 100k requests per second, twice as many as Kong. If you need high performance, choose NGINX. However, according to our tests, at 10k rps load, Kong is 40% slower than NGINX but provides more flexibility.
What's Included in the Work?
- Documentation on route configuration.
- Access to API Gateway and instructions for the team.
- Training engineers on routing basics.
- Support during implementation (2 weeks).
Process
- Requirements analysis: versioning, tenants, A/B, canary.
- API Gateway selection: Kong, Traefik, or Ingress Controller.
- Route design with priorities.
- Configuration implementation and Lua plugins (if needed).
- Monitoring setup (Prometheus + Grafana).
- Testing and load testing.
- Deployment and documentation.
Timeline and Scope
Setting up multi-level routing (path + header + tenant) takes from 1 to 3 business days depending on complexity. We provide documentation, access, and team training.
For further reading, see Wikipedia on API Gateway. If you need reliable request routing, contact us. We will audit your infrastructure within 1 day. Request a consultation—our engineers will help you choose the optimal solution.







