01 / 25 · Traffic and capacity

Load balancing

One address receives requests and shares them across healthy copies of your application. It chooses a destination; it does not create extra servers or make slow database queries disappear.

What you will practise

  • Trace a request to a healthy replica
  • distinguish routing from creating capacity
  • calculate survivor capacity

Before you start: Client, request, server and replica.

About 4 minutes · offline-generated English female narration · captions included. Diagrams are conceptual; timings are illustrative.

Download MP4Captions

Listen without the videoDownload audio

The same pre-recorded voice as the video. Starting audio pauses the video, and starting the video pauses audio.

Chapters and full transcript

Let us understand load balancing. A school has three lunch counters. A helper sends each child to an open counter instead of letting everyone crowd around the first. If a counter closes, the helper stops using it. But if all counters share one empty kitchen, the helper cannot create food. Likewise, distributing requests does not remove a shared database bottleneck. One address receives requests and shares them across healthy copies of your application. It chooses a destination; it does not create extra servers or make slow database queries disappear.

Follow the normal path. Visitors send event requests to one endpoint. The load balancer selects an application target so visitors do not need to know individual server addresses. Alternate requests between App A and App B. This shares turns, but a slow request can still occupy one target much longer than another. In our fictional SeatSpot ticket app, many people open the same event at once. One application instance becomes overloaded while a second has spare capacity. A load balancer makes the spare capacity reachable through the same public endpoint.

Now change one condition. App A stops passing readiness checks. Detection takes time; requests already in flight may fail and must be handled safely by the client. A common misunderstanding is this: Round robin means equal CPU usage. It shares turns; request cost and connection lifetime can differ. Think about this. App A fails. Can App B always take all its traffic? Pause the video and make your prediction. Only if App B and the shared dependencies have enough tested spare capacity. Health checks also take time to remove App A.

Let us reason with a concrete example. Suppose one tested replica handles 200 requests/second within the latency objective and the expected peak is 450. Three replicas provide 600 requests/second in the simplified model. Losing one leaves 400, below the peak. Four leave 600 after one failure. Real capacity must be load-tested with the database and dependencies. Use four if that failure headroom is required and affordable. Monitor per-target latency, error rate and queueing; do not infer usable capacity from instance count alone. These figures are teaching examples, not production guarantees.

Turn the idea into a design decision. New requests go to App B after the target is removed. App B needs enough spare capacity; routing cannot manufacture capacity during an outage. Both copies use the same order system. A repeated booking request carries the same idempotency key so a lost response does not charge twice. When you try the practice task, look for this result. The surviving target receives new traffic, but the database remains shared.

Check your understanding. Check latency and errors at the balancer, application and database. If both applications wait on the database, adding routing rules will not fix that bottleneck. Here is a challenge. You have three replicas each safe at 150 requests/second. Peak demand is 350. Can you survive one replica failing? Pause before the answer. After a failure, two replicas provide 300, below 350. Four total leave 450 after one failure in this simplified model. Also test dependency limits and the actual request mix. For an interview, defend a routing policy, session state and failure headroom. Say what you would measure, not only which tool you would buy.

Start with an everyday picture

A school has three lunch counters. A helper sends each child to an open counter instead of letting everyone crowd around the first. If a counter closes, the helper stops using it. But if all counters share one empty kitchen, the helper cannot create food. Likewise, distributing requests does not remove a shared database bottleneck.

Why SeatSpot needs this

In our fictional SeatSpot ticket app, many people open the same event at once. One application instance becomes overloaded while a second has spare capacity. A load balancer makes the spare capacity reachable through the same public endpoint.

Trace one step at a time

Move through the diagram at your pace. Teal paths are active; unavailable components are labelled.

VisitorsLoad balancerApp AApp BOrders DB

Step 1 of 6 · One entry point

One public address

Visitors send event requests to one endpoint. The load balancer selects an application target so visitors do not need to know individual server addresses.

Read all six mechanism steps
  1. One public address

    Visitors send event requests to one endpoint. The load balancer selects an application target so visitors do not need to know individual server addresses.

  2. Share requests

    Alternate requests between App A and App B. This shares turns, but a slow request can still occupy one target much longer than another.

  3. A target fails

    App A stops passing readiness checks. Detection takes time; requests already in flight may fail and must be handled safely by the client.

  4. Use the healthy target

    New requests go to App B after the target is removed. App B needs enough spare capacity; routing cannot manufacture capacity during an outage.

  5. Protect the booking

    Both copies use the same order system. A repeated booking request carries the same idempotency key so a lost response does not charge twice.

  6. Measure the whole path

    Check latency and errors at the balancer, application and database. If both applications wait on the database, adding routing rules will not fix that bottleneck.

Pause and make a prediction

App A fails. Can App B always take all its traffic?

Answer aloud or write your reasoning in the lesson notes before revealing the explanation.

Correct a common misunderstanding

Claim to question: Round robin means equal CPU usage.

Better explanation: It shares turns; request cost and connection lifetime can differ.

Route six paper requests

A paper or whiteboard task. No cloud account or paid infrastructure is required.

  1. Draw two app boxes and one shared database.
  2. Assign six requests alternately to the apps.
  3. Cross out App A, then recalculate capacity before rerouting.

Check what you can explain

This is your self-check, not an automated grade. Try again without the diagram tomorrow.

0 of 3 goals checked. Choose one remaining idea to practise next.

These checkboxes reset when you leave. Use your saved lesson notes and completion marker to record lasting progress.

Teach it back

Without looking, explain what this component changes, what it does not solve and what happens if it fails. Use the animation to check your explanation, then switch to Engineering.

Try it before viewing the solution

You have three replicas each safe at 150 requests/second. Peak demand is 350. Can you survive one replica failing?

Check one key idea

A load balancer is healthy but all database calls are slow. What should you investigate?

Your explanation and interview notes

Saved only in this browser when storage is available. Export a backup from the course page before clearing browser data or moving devices.

Loading your local notes…

Official references and next reading

The explanation, fictional examples and animations are original teaching material. Vendor behavior depends on the specific product/version; use its documentation before deploying.