Google Cloud Load Balancing

 

Google Cloud Load Balancing — Easy Notes

1. Why do we need Load Balancing?

Suppose your application starts with 4 VMs, but during high traffic it scales up to 40 VMs.

The question is: How do users know which VM to connect to?

👉 Cloud Load Balancing handles this.

Load Balancer = Traffic Distributor

It distributes incoming user traffic across multiple VMs/backend instances.

             Users
          /    |    \
         ↓     ↓     ↓
       Load Balancer
       /   /   |   \
      ↓   ↓    ↓    ↓
    VM1 VM2  VM3 ... VM40

2. Benefits

  • Distributes traffic across multiple instances.
  • Prevents one VM from becoming overloaded.
  • Improves performance and availability.
  • Automatically responds to:
    • Changes in traffic
    • Number of users
    • Backend health
    • Network conditions
  • Supports cross-region load balancing.
  • Can automatically perform multi-region failover if a backend becomes unhealthy.
  • It's fully managed → you don't need to create or manage load-balancer VMs.
  • No pre-warming required, even when you expect a huge traffic spike.

3. What traffic can it handle?

Google Cloud Load Balancing can handle:

  • HTTP / HTTPS
  • TCP
  • SSL
  • UDP
  • Other IP traffic depending on the load-balancer type.

4. Main Types

A useful way to remember the classification is:

Google Cloud Load Balancing
│
├── Application Load Balancer
│      └── Application Layer (Layer 7)
│
└── Network Load Balancer
       └── Transport/Network traffic
           │
           ├── Proxy Network Load Balancer
           └── Passthrough Network Load Balancer

A. Application Load Balancer

Layer: Application layer / Layer 7

Primarily handles:

👉 HTTP / HTTPS

Best suited for web applications and APIs.

It can make routing decisions based on application information.

For example:

/user/*       → Backend A
/payment/*    → Backend B
/products/*   → Backend C

Important features:

  • Content-based routing
  • SSL/TLS termination
  • Reverse proxy
  • Can be external (internet-facing)
  • Can be internal

Simple example:

A user requests:

https://example.com/payment

The Application Load Balancer can inspect the request and send it to the appropriate payment backend.


B. Network Load Balancer

Designed for lower-level network traffic such as:

👉 TCP, UDP and other IP protocols

There are two important types:

1. Proxy Network Load Balancer

Acts as a reverse proxy.

Client
  ↓
Proxy Load Balancer
  ↓
Backend

The load balancer:

  • Terminates the client connection.
  • Creates a new connection to the backend.
  • Provides advanced traffic-management capabilities.
  • Can work with backends in different cloud environments and on-premises environments.

2. Passthrough Network Load Balancer

This one is different.

It does NOT terminate or modify the connection.

Instead:

Client
  ↓
Passthrough Load Balancer
  ↓
Backend

The traffic is directly forwarded to the backend.

Key advantage

It preserves the original source IP address.

This is useful when applications need:

  • Direct server return
  • Original client IP
  • A wider range of IP protocols

⭐ Quick Comparison

TypeMain LayerTrafficConnection
Application LBLayer 7HTTP/HTTPSReverse proxy
Proxy Network LBLower network/transportTCP, SSL, etc.Terminates & creates new connection
Passthrough Network LBNetwork/transportTCP/UDP/IPDoesn't terminate; forwards directly

🧠 Exam shortcut

Application LB → HTTP/HTTPS + smart/content routing

Proxy Network LB → Proxy + terminates connection

Passthrough Network LB → Direct forwarding + preserves source IP

And remember the overall purpose:

Load Balancer distributes traffic so that no single backend becomes overloaded and the application remains available and performant.



Think of a receptionist 🧑‍💼

Imagine you call a company.

1. Proxy Network Load Balancer = Receptionist talks to you

You
 ↓
Load Balancer (Receptionist)
 ↓
Server

You don't directly talk to the server.

The Load Balancer receives your connection, ends your connection, then creates a new connection to the server.

So there are actually 2 connections:

You ──────→ Load Balancer
              │
              └──────→ Server

That's why it's called Proxy.

Simple example

You send:

"Give me my account details."

The Load Balancer receives your request and then asks the backend server:

"Hey Server, give me this customer's account details."

So:

Client → Load Balancer → Server

The Load Balancer is acting as a middleman.


2. Passthrough Network Load Balancer = Receptionist just directs you

Here, the Load Balancer doesn't terminate your connection.

It basically says:

"Go to Server 2."

You
 ↓
Load Balancer
 ↓
Server 2

The important part is that your connection continues to the backend.

So there is essentially one end-to-end client connection:

You ─────────────────→ Server
          ↑
    Load Balancer
    only directs traffic

The Load Balancer passes the traffic through.


🔥 Biggest difference

ProxyPassthrough
LB terminates connection?✅ Yes❌ No
Creates new backend connection?✅ Yes❌ No
Acts as middleman?✅ Yes❌ Mostly just forwards
Original source IP preserved?Generally not end-to-end✅ Yes
Easy exampleReceptionist talks to server for youReceptionist points you to the right room

🧠 Remember this one line:

Proxy = "I receive your connection and make another connection."

Passthrough = "I just pass your connection/traffic through to the backend."

That's the main concept. 

Comments

Popular posts from this blog

Async/await

First negative in every window of size k

Next Smaller Element