Typorithm · medium

Load Balancing

load-balancingsystem-designload-balancerl4-l7health-check
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Load Balancing

0%

Scaling

A load balancer spreads traffic across servers using round-robin, least-connections, or hashing. L4 balancers work at the transport layer while L7 ones are application-aware. Health checks remove failing nodes, sticky sessions pin a user to one backend, and the balancer itself must be redundant.

A load balancer sits in front of a pool of servers and distributes incoming requests so no single node is overwhelmed. Common algorithms are round-robin (cycle through servers), least-connections (favor the least-busy node), and hashing (route by a key like client IP).

Balancers operate at different layers. An L4 (transport) balancer routes on TCP/UDP and IP:port without inspecting the payload, so it is fast but blind to content. An L7 (application) balancer reads HTTP, letting it route by path, header, or cookie at the cost of more work per request.

Health checks probe each backend and remove unhealthy ones from rotation. Sticky sessions (session affinity) keep a user on one server when state is not shared. Because the balancer is itself a single point of failure, it is deployed in an active-passive or active-active pair.

01

Algorithms: round-robin, least-connections, hashing.

02

L4 routes on TCP/IP; L7 is HTTP-aware (paths, headers).

03

Health checks evict unhealthy nodes from the pool.

load_balancer:
  algorithm: round-robin-or-least-conn
  layer: l4-tcp-or-l7-http
  health_check: remove-unhealthy
  sticky: session-affinity
  redundancy: active-passive

Read the implementation

Connect each part of the code to the concept before you type.

1. Distribution algorithm

Round-robin cycles through servers in order; least-connections sends each request to the node with the fewest active connections.

algorithm: round-robin-or-least-conn

2. OSI layer

An L4 balancer routes on TCP/UDP without reading the payload; an L7 balancer is application-aware and can route on HTTP paths and headers.

layer: l4-tcp-or-l7-http

3. Health checks

Periodic probes detect failing nodes and pull them out of rotation so traffic only goes to healthy servers.

health_check: remove-unhealthy

4. Sticky sessions

Session affinity pins a given user to the same backend, which matters when server-side session state is not shared.

sticky: session-affinity

5. LB redundancy

The balancer is itself a single point of failure, so it runs in an active-passive (or active-active) pair to avoid an outage.

redundancy: active-passive

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Load Balancing: Lesson & Practice · Typorithm | ApplyDjinn