M. Kodirov

STAGE 07 / LESSON 02

Load balancing and scaling

A load balancer distributes incoming requests among available application instances.

THE IDEA

Understand it.

Horizontal scaling adds instances; vertical scaling gives an instance more resources. A load balancer can route requests to healthy instances, but it cannot fix a slow database query or an overloaded dependency by itself.

Design for instances to restart. Keep shared state in an appropriate shared service rather than relying on one server’s memory, and use health checks that reflect whether an instance can serve traffic.

SEE IT IN CONTEXT

Multiple app instances

Users → load balancer → app instance A
                      → app instance B
                      → app instance C
                               ↓
                        shared database

The database can become the bottleneck even when more application instances are added.

LEARN FROM REAL WEBSITES

See it in the real world.

These simplified structures come from public sources. Company systems change, and the sources may describe only one project or an earlier design.

GitHub

GitHub, 2020

An ingress and internal gateway

GitHub's 2020 incident analysis describes its load balancer as an ingress for customer traffic and a gateway to internal services.

  1. Customer traffic
  2. GitHub Load Balancer
  3. Applications and services

What to learn: A traffic-routing layer can become a critical dependency; its failures need to be considered in the design.

Read the source: GitHub service disruptions analysis

Shopify

Shopify engineering, 2021

Route storefront requests

Shopify described using an nginx/OpenResty load balancer to shift storefront traffic between old and new implementations.

  1. Storefront request
  2. Load balancer
  3. Selected storefront

What to learn: Routing can support a gradual migration as well as distributing traffic; this describes the 2021 architecture.

Read the source: Shopify storefront routing

TRY IT YOURSELF

Practice.

Why might a login disappear when traffic moves from one app instance to another?

Show one possible answer

If session state exists only in one instance’s memory, another instance cannot see it. Use an appropriate shared session strategy or another deliberate design.

GO DEEPER

Official references.