Amit Pal
Amit Pal

Reputation: 11042

How google load balancer maintain consistency in routing?

I have two google cloud instances running on different regions (West and East). Each instances have their own database. I am using Google Load balancer to route the traffic based upon the client's IP address (This is what Google load balancer is doing internally on Network load balancing).

For example, Bob is requesting from the east region and GLB will route the request to east region node only. Similarly, Dave is requesting from the west region and GLB will route the request to west region node.

Scenarios: 1. Bob just sign up and a new entry added to the East region database. 2. Bob tries to fetch his profile but somehow request went to the West (Bob now using a VPN) region and there is no information available.

Is there a way that I can customize GLB? If yes, then I can solve this problem by applying consistency hashing on the load balancer (using userId as a hash function) which will make sure that the request coming from Bob will always go to East region.

Upvotes: 0

Views: 534

Answers (1)

John Hanley
John Hanley

Reputation: 81336

You can use the HTTP Load Balancer options: Session Affinity and Client IP Affinity.

There are subtle issues with any method, read the documentation carefully. The biggest issue is for clients behind a NAT (airport, hotel, Starbucks, etc.). Their public IP address is the same for all clients behind the NAT, therefore all traffic will go to the same backend for Client IP based affinity. I recommend using cookies.

Session affinity uses Client IP or Generated Cookie to make traffic decisions. This can keep traffic routed to the same backend.

Session Affinity

Client IP affinity directs requests from the same client IP address to the same backend instance based on a hash of the client's IP address.

Using Client IP Affinity

Upvotes: 1

Related Questions