AlgoViz

Cloud load balancing

medium 25 min

A cloud load balancer is a load balancer you rent.

See it run

A balancer you rent: the same path in three clouds, what grows by itself, what happens when a zone fails and what you pay for.

Operations

One path, three clouds

The same three stops on AWS, Google Cloud and Azure: a global entry, a load balancer, and regions.

Step 1 of 5

AWS: the entry

CloudUsersRoute 53 or CDNALB or NLBone per regionus-east-14 regionsus-west-2eu-west-1ap-southeast-1

Users find the entry with Route 53 or CloudFront.

Step 1: AWS: the entry

def handle(request):    entry = nearest_entry(request.client)    region = choose_region(entry, healthy_regions())    target = pick(region.target_group)   # healthy only    return forward(request, target)
Reacts in
Milliseconds
You pay
Hour + usage
Own proxies
machines, patches, on-call

The names change between clouds. The three questions (near whom, which region, which server) do not.

In the real world

The same cloud load balancing doing real jobs. Pick one and step through it.

A global entry over two regions of equal size.

Step 1 of 4

Both serve

CloudUsersGlobal entryone addressRegion Europe45% busyRegion Asia45% busy

Half and half

Each region works at 45% of its capacity.

Step 1: Both serve

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • Believing the balancer scales the servers

    critical

    It grows alone. The servers behind it need their own scaler.

    Wrong
    create(load_balancer)# "it is managed, it scales"
    Right
    create(load_balancer)create(auto_scaler, requests_per_target=800)schedule(servers=24, before="sale")
  • Storing the address

    major

    Addresses behind the name change when the balancer scales.

    Wrong
    API = "203.0.113.10"
    Right
    API = "api.example.com"   # or a kind with static addresses
  • No spare zone

    critical

    When one of three zones fails, the other two receive 50% more each.

    Wrong
    per_zone = peak / (per_server * 3)
    Right
    per_zone = ceil(peak / (per_server * 2))
  • Leaving health checks at the default

    major

    A dead server may receive traffic for about a minute.

    Wrong
    health_check(path="/")   # 30 s, 2 failures
    Right
    health_check(path="/health", interval=10,             timeout=2, unhealthy=2)

Interview tips

  • How to explain it

    • A load balancer you rent.
    • The provider scales, patches and replaces it.
    • You choose kind, zones, checks and spare capacity.
  • Memory trick: CLOUD

    • Configuration as code, Load distributed.
    • On-demand scaling, Uptime agreement.
    • DNS built in.
  • Choose by

    • Web requests or connections?
    • One region or many?
    • Must the address be fixed?
  • Check before launch

    • Cross-zone setting.
    • One zone of spare.
    • Detection time and draining.
    • The largest billed measure.