Sikau

AWS · Day 11 · about 40 min

Load balancing

Spread requests across targets and skip the unhealthy ones.

One address, many servers

Visitors should not need to know that your site runs on three servers. A load balancer gives them one address, then forwards each request to one of several targets. If a server crashes, the balancer stops sending it traffic and nobody notices.

AWS offers the Application Load Balancer for HTTP and HTTPS (it can route by path or host name) and the Network Load Balancer for raw TCP and UDP at very high volume. In both, you register targets and the balancer spreads the load.

Health checks

How does the balancer know a server is broken? It runs a health check: every few seconds it requests a path such as GET /health from each target. A target that keeps failing is marked unhealthy and skipped; when it passes again it rejoins.

  • Make /health cheap and honest: it should return 200 only when the app can really serve requests.
  • A health check that only returns 200 always hides real failures.
  • A health check that calls five other services can take everything down at once.

The rest of this lesson

  • Round robin, skipping the sickexplain
  • Who answers?predict
  • A server failsorder
  • Pick the balancermatch
  • Build a balancerwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browserright here

Continue with Google

See all 13 lessons of AWS