Node.js Course
Node.js
/
Advanced

Load Balancing

Definition

The process of distributing network traffic efficiently across multiple servers. It ensures no single server bears too much demand.

Explain Like I'm New

The traffic cop. If you scaled horizontally and have 5 Node.js servers, the Load Balancer sits in front of them. When 100 users visit your site, the Load Balancer directs 20 to Server A, 20 to Server B, etc. If Server C catches fire and crashes, the Load Balancer detects it instantly and redirects all traffic to the healthy servers, meaning the users never even notice the crash.

Real World Example

AWS Application Load Balancer (ALB) or NGINX. The DNS points `google.com` to the Load Balancer, which then silently forwards the traffic to Google's millions of internal servers.

Common Use Cases

  • •Distributing high traffic
  • •Ensuring High Availability / Fault Tolerance

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • Does the client communicate directly with the individual Node.js servers?

intermediate

  • What is 'Round Robin'?

Flash Cards

Question

Client communicate directly?

Click to reveal answer
Answer

No. The client only knows the IP address of the Load Balancer. The internal servers are hidden in a private network.

Question

What is Round Robin?

Click to reveal answer
Answer

The simplest load balancing algorithm. It just goes down the list sequentially: Request 1 goes to Server A, Request 2 to Server B, Request 3 to Server C, Request 4 back to Server A. Other algorithms route based on which server has the lowest current CPU usage.