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 databaseThe 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, 2020An 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.
- Customer traffic
- GitHub Load Balancer
- 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 analysisShopify
Shopify engineering, 2021Route storefront requests
Shopify described using an nginx/OpenResty load balancer to shift storefront traffic between old and new implementations.
- Storefront request
- Load balancer
- 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 routingTRY 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