0Pricing
System Design Basics for Backend Developers · レッスン

負荷分散の戦略

ロードバランサーが複数のサーバーにトラフィックを分散して水平スケーリングを可能にする仕組みを学び、一般的なルーティングアルゴリズムとヘルスチェックについても扱います。

「負荷分散の戦略」はCoddyKit上の無料System Design Basics for Backend Developersレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはSystem Design Basics for Backend Developers学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 System Design Basics for Backend Developersコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Why Load Balancing?

Once you scale horizontally, you have many identical servers. But how do clients know which one to hit? A load balancer sits in front of your servers and spreads incoming requests across them.

  • Prevents any single server from being overwhelmed
  • Enables seamless scaling up and down
  • Improves availability if one server fails

Where the Balancer Sits

A load balancer is a reverse proxy: clients connect to one address, and the balancer forwards the request to a healthy backend. The client never sees the internal topology.

This indirection is what makes adding or removing servers invisible to users.

Client --> [Load Balancer] --> Server A
                            --> Server B
                            --> Server C

Round Robin

Round robin is the simplest algorithm: requests are handed to servers in rotation. Server A, then B, then C, then back to A.

It works well when all servers are equally powerful and requests cost roughly the same.

requests = ['r1','r2','r3','r4']
servers = ['A','B','C']
for i, r in enumerate(requests):
    print(r, '->', servers[i % len(servers)])

Least Connections

Least connections routes each new request to the server with the fewest active connections. This is smarter when request durations vary widely.

A server stuck on slow requests will not keep receiving new ones.

Weighted Algorithms

If servers have different capacity, assign weights. A server with weight 3 receives roughly three times as many requests as a server with weight 1.

  • Weighted round robin
  • Weighted least connections

IP Hash & Sticky Sessions

IP hash routes a given client consistently to the same server based on a hash of its IP. This creates sticky sessions, useful when a server holds in-memory session state.

Note: stickiness undermines stateless design. Prefer external session stores when possible.

def pick(ip, n):
    return hash(ip) % n
print('192.168.0.5 ->', pick('192.168.0.5', 3))

Health Checks

A load balancer periodically pings each backend with a health check (e.g. GET /health). Unhealthy servers are removed from rotation automatically.

This is how the system survives a server crash without manual intervention.

Layer 4 vs Layer 7

Layer 4 balancing operates on TCP/UDP, routing by IP and port — fast but blind to content. Layer 7 operates on HTTP, so it can route by URL path, headers, or cookies.

  • L4: high throughput, simple
  • L7: content-aware, supports path-based routing

DNS Load Balancing

At the largest scale, a single load balancer becomes a bottleneck. DNS-based balancing returns different server IPs to different clients, spreading load before traffic even reaches a balancer.

Often combined with regional balancers for global apps.

Avoiding the Single Point of Failure

The load balancer itself must not be a single point of failure. Run it in an active-passive or active-active pair, with a floating virtual IP that fails over if the primary dies.

Putting It Together

A typical scalable setup: DNS spreads clients across regions, regional L7 balancers do health-checked path routing, and least-connections distributes to a fleet of stateless app servers behind them.

Each layer removes a bottleneck and adds resilience.

Quick Check

Test your understanding of load balancing algorithms.

Recap

You learned how load balancing makes horizontal scaling practical:

  • Round robin, least connections, weighted, and IP hash algorithms
  • Health checks remove failed servers automatically
  • Layer 4 vs Layer 7, plus DNS balancing at scale
  • The balancer must itself be redundant

よくある質問

「負荷分散の戦略」レッスンは無料ですか?

はい。「負荷分散の戦略」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、System Design Basics for Backend Developersコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 System Design Basics for Backend Developersコースには全4レッスンが含まれています。

「負荷分散の戦略」で何を学びますか?

ロードバランサーが複数のサーバーにトラフィックを分散して水平スケーリングを可能にする仕組みを学び、一般的なルーティングアルゴリズムとヘルスチェックについても扱います。 ブラウザで直接実行するハンズオンコードでSystem Design Basics for Backend Developersを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

System Design Basics for Backend Developersを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのSystem Design Basics for Backend Developersは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「負荷分散の戦略」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このSystem Design Basics for Backend Developersレッスンでコードを書いて実行できますか?

はい。すべてのSystem Design Basics for Backend Developersレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 垂直スケーリングと水平スケーリング
  2. ステートレスサービスとステートフルサービス
  3. 分散システム入門
  4. 負荷分散の戦略
← System Design Basics for Backend Developersに戻る