Skip to content
Tutorials Center
My learning

Topics

Lesson 21 of 57 ยท Networking

Load Balancer, Application Gateway and Front Door

Compare Azure Load Balancer, Application Gateway and Front Door: layer 4 vs layer 7, health probes, routing rules, WAF and TLS offload, with a runnable simulator.

One server is a single point of failure and a hard ceiling on capacity. A load balancer spreads incoming requests across several identical servers, notices when one stops answering, and stops sending it traffic. Azure offers four related services for this, and choosing between them is mostly a question of two things: at which network layer does the decision happen, and does it work inside one region or across the world?

The real services need an Azure subscription, so the commands here are read-only. The runnable examples are Node.js programs on the site's code runner. They are stand-ins that reproduce the logic you configure in Azure (round-robin, health probes, path-based routing and a toy web application firewall), not the services themselves.

Layer 4 versus layer 7

Network traffic can be understood at different levels. At layer 4 (the transport layer) a balancer sees IP addresses, ports and the protocol (TCP or UDP). It knows nothing about URLs or headers; it just forwards connections. At layer 7 (the application layer) the balancer understands HTTP: hostnames, paths, cookies and headers. That lets it route /api/* to one group of servers and /images/* to another, terminate TLS, and inspect requests for attacks.

Service Layer Scope Typical use
Azure Load Balancer 4 Regional Any TCP/UDP traffic: databases, game servers, non-web protocols, VM tiers
Application Gateway 7 Regional Web apps: path routing, TLS offload, WAF
Front Door 7 Global Global web apps: edge entry points, acceleration, WAF, failover between regions
Traffic Manager DNS Global DNS-based steering for any endpoint (see DNS and Traffic Manager)
flowchart TB
    U["Users worldwide"] --> FD["Front Door<br/>global, layer 7"]
    FD --> AG1["Application Gateway<br/>West Europe, layer 7"]
    FD --> AG2["Application Gateway<br/>East US, layer 7"]
    AG1 --> LB1["Load Balancer<br/>internal, layer 4"]
    LB1 --> VM1["VM tier"]
    AG2 --> VM2["VM tier"]

Services can be stacked: a global entry point, a regional web gateway, and an internal layer 4 balancer in front of a VM tier.

Azure Load Balancer

The Azure Load Balancer is a very fast layer 4 service. It has a frontend IP (public for internet traffic, private for an internal balancer), a backend pool (the VMs or scale set instances), health probes, and load-balancing rules that map a frontend port to a backend port, for example 443 to 8443.

By default it picks a backend with a hash of the connection's five-tuple (source IP, source port, destination IP, destination port, protocol). The same connection always lands on the same backend, while different connections spread out roughly evenly. You can switch to source-IP affinity so one client keeps returning to one server. Two practical facts: use the Standard SKU for new deployments (the Basic SKU is retired), and remember it does not understand HTTP, so it cannot terminate TLS or route by path.

Health probes

How does the balancer know a server is alive? It sends health probes at a set interval to a TCP port or an HTTP(S) path. If a backend fails a configured number of consecutive probes, it is taken out of rotation; when it passes enough probes again, it comes back. A good HTTP probe path checks something meaningful, such as /healthz returning 200 only when the app can reach its dependencies. A path that always returns 200 hides real failures.

Here is a stand-in that shows the mechanism. Notice that one failed probe is not enough to remove a server, so a few requests still reach the failing machine before the second probe marks it down. That is a trade-off between reacting fast and avoiding false alarms from a single dropped packet.

Node.js Round-robin with health probes

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Real Azure uses connection hashing instead of strict round-robin, but the health logic is the same idea. In round 4 every backend is down, so there is nobody left to send traffic to and clients get errors. That is why backends should be spread across availability zones and why the next lessons on reliability matter.

A read-only example of the real configuration:

Terminal
az network lb create \
  --resource-group rg-net --name lb-web --sku Standard \
  --frontend-ip-name fe-public --backend-pool-name be-web \
  --public-ip-address pip-lb-web

az network lb probe create \
  --resource-group rg-net --lb-name lb-web --name probe-https \
  --protocol Https --port 443 --path /healthz --interval 5 --probe-threshold 2

az network lb rule create \
  --resource-group rg-net --lb-name lb-web --name rule-https \
  --protocol Tcp --frontend-port 443 --backend-port 443 \
  --frontend-ip-name fe-public --backend-pool-name be-web --probe-name probe-https

Application Gateway

Application Gateway is a regional layer 7 service built for web traffic. It terminates the client's TLS connection (called TLS offload, or SSL termination), so your backends can speak plain HTTP inside the private network and you manage certificates in one place. Many teams also re-encrypt to the backend (end-to-end TLS) when policy requires encryption everywhere.

Its main building blocks are:

  • Listeners that match a port and optionally a hostname, which enables multi-site hosting (many domains on one gateway).
  • Routing rules, including path-based routing (/api/* to the API pool, everything else to the web pool).
  • HTTP settings and health probes per backend.
  • Optional cookie-based session affinity, URL rewrite and redirects.
  • It lives in its own dedicated subnet, and the v2 SKU supports autoscaling and zone redundancy.

Web Application Firewall

Application Gateway (and Front Door) can enable a Web Application Firewall (WAF). It inspects HTTP requests against rule sets based on the OWASP Core Rule Set to catch common attacks such as SQL injection and cross-site scripting. A WAF can run in detection mode (log only) or prevention mode (block). Start in detection, review the false positives, then switch to prevention.

The second stand-in combines path routing with a deliberately crude WAF. It is only a teaching toy; real WAF rules are far more sophisticated.

Node.js Path-based routing and a toy WAF

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The first matching rule decides the pool, which is why the catch-all web rule is last, the same ordering idea as NSG priorities. Requests for /api/ rotate through three API servers while everything else goes to the web pool, and the two attack-shaped requests never reach any backend.

Front Door

Azure Front Door is a global layer 7 entry point. Clients connect to the nearest Microsoft edge location (using anycast routing), and Front Door carries the request over Microsoft's backbone to the best healthy origin. That gives you:

  • Global load balancing and failover: origins in several regions, with health probes and priority or latency-based routing, so a regional outage moves traffic automatically.
  • Acceleration and caching: static content can be cached at the edge, and TLS is terminated close to the user.
  • WAF and custom domains with managed certificates at a single global point.
  • Rules to rewrite, redirect and add headers.

Application Gateway is the right choice when everything is in one region, or when you need a gateway inside a private network. Front Door is the right choice when users are spread across the world or you run the same app in multiple regions. Many large systems use both: Front Door in front, Application Gateway behind it in each region.

Choosing quickly

  1. Is the traffic HTTP(S)? If not (or you only need fast, simple distribution), use Load Balancer.
  2. If it is web traffic in a single region, use Application Gateway.
  3. If it is web traffic across regions or continents, use Front Door.
  4. Need to steer non-HTTP traffic across regions? Use Traffic Manager at the DNS level.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which service can route requests by URL path, such as /api/* to one pool and /images/* to another?

    Path-based routing needs layer 7 awareness of HTTP, which Application Gateway and Front Door have. The Load Balancer works at layer 4.
  2. 2. A backend fails its health probes. What does the load balancer do?

    After the configured number of consecutive failures the backend is taken out of rotation, and it returns after passing probes again.
  3. 3. What is TLS offload (termination) on Application Gateway?

    Terminating TLS at the gateway centralizes certificates and removes decryption work from the backends. You can still re-encrypt to them.
  4. 4. You run the same web app in West Europe and East US and want users sent to the nearest healthy region over Microsoft's network. Which is the best fit?

    Front Door is the global layer 7 service with edge locations, health probes and multi-region failover.
  5. 5. Why is a health probe that always returns 200 a poor design?

    A probe should reflect whether the app can really serve requests.

Summary

  • Load balancers spread traffic over healthy backends; health probes decide who is healthy.
  • Layer 4 services (Load Balancer) forward connections; layer 7 services (Application Gateway, Front Door) understand HTTP and can route by host or path, offload TLS and run a WAF.
  • Application Gateway is regional; Front Door is global with edge locations and cross-region failover; Traffic Manager steers at the DNS level.
  • Meaningful probe endpoints and zone-spread backends make the difference between graceful and total failure.
  • Services stack well: a global front, a regional gateway and an internal balancer for a private tier.

Next: DNS and Traffic Manager.