Routing and Upstream
Routing Concept
Routing consists of two fundamental components in an API Proxy:
The entry point where requests enter the API Proxy. Clients send requests to this endpoint.
The backend API where requests are routed. The API Proxy sends requests to this address.
Routing Flow
The following diagram shows how request and response flow occurs through the Gateway with the Routing and Upstream mechanism:
sequenceDiagram
participant Client as 👤 Client
participant Gateway as 🚪 API Gateway
participant ClientRoute as 🔀 Client Route
participant RoutingLogic as ⚙️ Routing Logic
participant Upstream as 🎯 Upstream Target
participant Backend1 as 🖥️ Backend 1
participant Backend2 as 🖥️ Backend 2
Client->>Gateway: HTTP Request<br/>(Path, Method, Headers)
Note over Gateway: Request Reached Gateway
Gateway->>ClientRoute: Route Request to Client Route
Note over ClientRoute: Client Route Evaluation<br/>Path, Host, Header, Method
ClientRoute->>RoutingLogic: Appropriate API Proxy Found<br/>Forward to Routing Logic
Note over RoutingLogic: Routing Operations
RoutingLogic->>RoutingLogic: Load Balancing<br/>Strategy Applied<br/>(Round Robin, Least Connections, etc.)
RoutingLogic->>RoutingLogic: Path Rewrite<br/>(If Needed)
RoutingLogic->>Upstream: Upstream Target Selected
Note over Upstream: Backend Target Determined
alt Successful Routing
Upstream->>Backend1: Request Forwarded to Backend<br/>(Load Balanced)
Backend1->>Upstream: Response Returns
Upstream->>RoutingLogic: Processed Response
RoutingLogic->>Gateway: Routing Completed
Gateway->>Client: HTTP Response
else Failover Scenario
Upstream->>Backend1: Request Forwarded to Backend 1
Backend1-->>Upstream: ❌ Error (Timeout/Error)
Upstream->>Backend2: Failover: Switch to Backend 2
Backend2->>Upstream: ✅ Successful Response
Upstream->>RoutingLogic: Processed Response
RoutingLogic->>Gateway: Routing Completed
Gateway->>Client: HTTP Response
end
Note over Client,Gateway: Process Completed
Client sends request to API Proxy
Entry point where requests enter the API Proxy
Path, Method, Protocol and Port definitions
Load Balancing, Failover and routing logic is applied
Backend API where requests are routed
Backend address, protocol and configuration
Processed request is sent to backend API
Upstream Target
Upstream Target is the address of the backend API to which requests from clients in an API Proxy are routed. Upstream Target is the point where the API Proxy communicates with the backend.
Upstream Target Overview
Upstream and target concepts are fundamental concepts used when routing to backend services in API Proxies. Upstream Target represents the physical or logical address of the backend API. The API Proxy routes requests coming from Client Route to this target.
URL or IP address of the Backend API
HTTP, HTTPS, gRPC, WebSocket protocols
Load balancing between multiple backend instances
Switching to alternative backend in error conditions
Upstream and Target
Upstream: Configuration where backend services to which the API Proxy routes requests are defined. An upstream can contain multiple targets.
Target: Backend service addresses defined within an upstream. Each target contains a URL and necessary configuration information.
Upstream Target Structure
An Upstream Target contains the following information:
http://backend-service:8080/api/products
│ │ │ │
│ │ │ └─ Backend Path
│ │ └─ Port
│ └─ Host/Service Name
└─ Protocol
Example Upstream Targets
http://product-service:8080
https://api.backend.com/v1
grpc://backend-service:50051
ws://websocket-service:8080