Application Gateway Routing Rules

Application Gateway routing rules are the heart of how your gateway directs incoming traffic to the appropriate backend resources. These rules determine which backend pool receives traffic based on the request's characteristics.

Types of Routing Rules

Application Gateway supports two primary types of routing rules:

Basic Rules

A basic rule associates a listener with a single backend pool. All traffic received by the listener will be directed to this backend pool. This is suitable for simple scenarios where all requests to a specific port and host are intended for the same set of servers.


// Example of a basic routing rule configuration (conceptual)
{
  "name": "BasicRuleToAppServer",
  "listener": "ListenerForHTTP",
  "backendPool": "AppServersPool"
}
        

Path-Based Rules

Path-based routing allows for more granular control. You can define multiple rules that match specific URL paths within a single listener. This enables you to route requests to different backend pools based on the requested URL. For example, requests to /images/* could go to an image processing backend, while requests to /api/* go to an API backend.

A path-based rule consists of:

Content-Based Routing

Application Gateway can also perform content-based routing, which allows you to route traffic based on HTTP headers, query string parameters, and other request attributes. This provides even greater flexibility in directing traffic to specific backend services.

How Routing Rules Work

  1. Listener Match: When a request arrives at Application Gateway, it first checks if it matches any of the configured listeners based on protocol, port, hostname, and IP address.
  2. Rule Evaluation: If a listener is matched, Application Gateway evaluates the associated routing rules.
  3. Path Matching (for Path-Based Rules): For path-based rules, Application Gateway examines the URL path of the incoming request and compares it against the defined path match conditions. The most specific match is typically prioritized.
  4. Header/Content Matching (for Content-Based Routing): If content-based routing is configured, Application Gateway analyzes the request headers and body to determine the routing path.
  5. Backend Pool Selection: Based on the matched rule, Application Gateway selects the appropriate backend pool.
  6. Request Forwarding: The request is then forwarded to one of the healthy instances within the selected backend pool, using the configured HTTP settings.

Key Components of a Routing Rule

Component Description
Listener The front-end IP, port, protocol, and optionally, hostname, that Application Gateway listens on for incoming requests.
Request Routing Rule The core component that links a listener to a backend target (backend pool or Application Gateway's own HTTP settings).
Path Rules Define conditions (URL paths, hostnames) for path-based routing.
Backend Pool A group of backend servers that will receive traffic.
HTTP Settings Defines the protocol, port, cookie-based affinity, connection draining, and probe settings for traffic sent to the backend pool.

Default Rule

Every Application Gateway must have at least one default rule. This rule is used if no other specific routing rule matches the incoming request. It's typically configured to route traffic to a default backend pool.

Important: Ensure your routing rules are configured correctly to avoid unexpected traffic behavior or application downtime. Always test your routing configurations thoroughly.

Example: Routing to Microservices

Consider an application with multiple microservices deployed across different backend pools:

You can configure a single listener and a path-based routing rule to direct traffic like this:

This allows for efficient and organized traffic management for a microservices architecture.