DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Transforming Proprietary Trace Context to W3C Trace Context
  • Safeguarding Web Applications With Cloud Service Providers: Anti-CSRF Tokenization Best Practices
  • Provision Cloud Infrastructure Using Google Duet AI
  • Private Cloud's Deployment

Trending

  • Exploring Intercooler.js: Simplify AJAX With HTML Attributes
  • Secrets Sprawl and AI: Why Your Non-Human Identities Need Attention Before You Deploy That LLM
  • Accelerating Debugging in Integration Testing: An Efficient Search-Based Workflow for Impact Localization
  • Can You Run a MariaDB Cluster on a $150 Kubernetes Lab? I Gave It a Shot
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Using Global Cloud Load Balancer to Route User Requests to App Instances

Using Global Cloud Load Balancer to Route User Requests to App Instances

A geo-distributed messenger application development journey continues: my next challenge is forwarding application requests to the instance closest to the user.

By 
Denis Magda user avatar
Denis Magda
DZone Core CORE ·
Oct. 20, 22 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
5.4K Views

Join the DZone community and get the full member experience.

Join For Free

Ahoy, Mateys! 

In my last two articles, I showed you how to deploy microservice instances across several cloud regions and how to set up a geo-distributed API layer. 

All seems good, except that I’ve now got several standalone application instances running across the US West, Central, and East regions, and each instance has its own private IP address.

Standalone applications running in multiple regions

My next challenge is figuring out how to forward application requests to the instances closest to the user. 

I don’t want my Web UI and mobile apps to keep track of all the IPs and decide how and where to route user requests. This is way too complicated and becomes unmanageable. Instead, the Web UI and mobile apps need to connect to a single IP address, which lets other components of my geo-distributed solution decide where to route a particular user request.

What could those components be, matey? 

You’ve guessed it: usually, a proxy and load balancer. 

In this article, I’ll show you how to configure a global cloud load balancer that serves as both a proxy and a load balancer. This type of load balancer comes with a single IP address that can be accessed from any location on earth and can route a request to the nearest (active!) application instance.

So, if you’re still with me on this journey, then, as the pirates used to say, “Weigh Anchor and Hoist the Mizzen!” which means, “Pull up the anchor and get this ship sailing!”

Explaining Global Cloud Balancer Usage

Before diving into details and technicalities, let’s use a few illustrations to see the value of the load balancer.

Suppose Ms. Blue, one of my application users, is vacationing in the Tampa Bay area of Florida. She promised not to open my corporate Slack-like messenger (the geo-distributed app I’m building) while on vacation. 

She failed to keep her promise, but for a good reason. She couldn’t resist sharing a few pictures from the pristine beaches of Tampa Bay.

What happens when Ms. Blue shares photos

The diagram above shows what happens when Ms. Blue opens the app and sends a few gorgeous photos. 

The app connects to the global load balancer's public IP address, 35.186.215.175. Next, the load balancer determines that the application instance with IP 10.1.12.8 is closest to Ms. Blue (both Ms. Blue and the instance are on the US East coast). Finally, the load balancer asks the East Coast instance to upload the pictures.

Next, Mr. Green, a colleague of Ms. Blue, working from his Seattle-based company office, receives a push notification from the messenger and can’t resist checking what’s been posted. 

Diagram of what happens when Mr. Green opens the photos

Mr. Green opens the mobile app and the app connects to the same load balancer using the same public IP address, 35.186.215.175. This time, the load balancer forwards Mr. Green’s request to the application instance from the West Coast that uses 10.1.11.16 IP address.

Also, the load balancer is instrumental in case of cloud outages. Let’s consider a final example.

A few days later, Ms. Blue decides to make her colleagues jealous again and opens the app to send another set of fabulous pictures. The application connects to the load balancer on the same public IP address (35.186.215.175) and…

What happens when a storm affects the US East Coast region and Ms. Blue shares photos

…this time the load balancer forwards Ms. Blue’s request to the application instance in the US Central with IP address 10.1.10.10. 

This is because a storm in the Atlantic impacted the availability of the entire US East Coast cloud region. The US Central region is up and running as normal, and is now the closest for Ms. Blue. So, the request is routed there automatically.

Alright, matey, now let’s move forward and look into the architecture, or the main building blocks, of the global cloud load balancer.

Global Load Balancer Architecture

The global load balancer is comprised of several building blocks. Take a look at the picture below and review the components from left to right. 

Global load balancer architecture

This picture represents the architecture of the load balancer in Google Cloud. The components might vary depending on your cloud environment. But you can be sure that every major cloud environment supports the global load balancer.

So, moving from left to right in the picture: As you already know, users connect to the public IP address assigned to the load balancer (or DNS name that translates to this address). After that, the load balancer consults with existing forwarding rules to determine which target proxy needs to handle the request.

Once the target proxy is selected, the proxy checks its URL map to decide which backend services are responsible for the request.

Finally, the backend service delegates the request to one of its backends (actual application instances). In our case, during normal operations, requests from Mr. Green, based in Seattle, will be processed by the US West backend instance. The traffic from Ms. Blue will go to the backend in the US East region.

If you wish to learn more about the global load balancer’s architecture, check out this documentation for an extensive overview of all its components. 

Global Load Balancer Deployment

At last, matey, let’s go ahead and deploy an instance of the global external load balancer in Google Cloud.

Assuming that applications instances are already running across US West, Central, and East, these are our next steps (explore how to deploy the instances in Google Cloud):

1. Reserve a static public IP address for the load balancer:

Shell
 
gcloud compute addresses create load-balancer-public-ip \
  --ip-version=IPV4 \
        	  --network-tier=PREMIUM \
              --global


2. Configure a health check for a backend service:

Shell
 
gcloud compute health-checks create http load-balancer-http-basic-check \
        --check-interval=20s --timeout=5s \
        --healthy-threshold=2 --unhealthy-threshold=2 \
        --request-path=/login \
        --port 80


3. Create the backend service for the HTTP traffic and provide the just-created health check to ensure the application instances are up and running:

Shell
 
gcloud compute backend-services create load-balancer-backend-service \
        --load-balancing-scheme=EXTERNAL_MANAGED \
        --protocol=HTTP \
        --port-name=http \
        --health-checks=load-balancer-http-basic-check \
        --global


4. Provide the backend service with backends (application instances) across several cloud regions:

Shell
 
gcloud compute backend-services add-backend load-balancer-backend-service \
        --balancing-mode=UTILIZATION \
        --max-utilization=0.8 \
        --capacity-scaler=1 \
        --instance-group=ig-us-central \
        --instance-group-zone=us-central1-b \
        --global
    
    gcloud compute backend-services add-backend load-balancer-backend-service \
        --balancing-mode=UTILIZATION \
        --max-utilization=0.8 \
        --capacity-scaler=1 \
        --instance-group=ig-us-east \
        --instance-group-zone=us-east4-b \
        --global
    
    gcloud compute backend-services add-backend load-balancer-backend-service \
        --balancing-mode=UTILIZATION \
        --max-utilization=0.8 \
        --capacity-scaler=1 \
        --instance-group=ig-us-west \
        --instance-group-zone=us-west2-b \
        --global


5. Finally, configure the default URL map to route all requests to the created backend service:

Shell
 
gcloud compute url-maps create load-balancer-url-map --default-service load-balancer-backend-service


After the backend service is ready, go ahead and configure the frontend part of the load balancer which is the forwarding rule and target proxy.

1. Create an HTTP proxy providing the URL map:

Shell
 
gcloud compute target-http-proxies create load-balancer-http-frontend \
        --url-map load-balancer-url-map \
        --global


2. Define a forwarding rule to direct the traffic from the public Internet to the just created proxy:

Shell
 
gcloud compute forwarding-rules create load-balancer-http-frontend-forwarding-rule \
        --load-balancing-scheme=EXTERNAL_MANAGED \
        --network-tier=PREMIUM \
        --address=load-balancer-public-ip  \
        --global \
        --target-http-proxy=load-balancer-http-frontend \
        --ports=80


That’s it! The global external load balancer is fully configured. It might just take a few minutes for your configuration to propagate worldwide.

Testing Load Balancer

Now, it’s testing time!

I’ll play the role of Ms. Blue, who wants to share gorgeous photos from Tampa Bay. A colleague of mine who is based in Seattle will be Mr. Green.

The manual testing is straightforward. I’m opening the messenger in my browser using the load balancer’s public IP address and uploading a few pictures:

Uploading pictures in messenger in browser

How do I ensure those pictures were uploaded through an instance in the US East?

Well, I opened the monitoring tab for the load balancer and confirmed all my requests are delegated to the ig-us-east instance:

Load balancer details: all requests delegated to the ig-us-east instance

After that, my Seattle colleague opens the app to check the pictures. In a few moments, I can see that the load balancer directs his traffic to the ig-us-west!

Load balancer details: traffic directed to ig-us-west

Job done! 

The global load balancer is fully configured and functions globally. This means my geo-distributed messenger can seamlessly process user requests with high performance across the globe and withstand various cloud outages.

What’s on the Horizon?

Alright, matey! 

My geo-distributed app now functions across multiple cloud regions and availability zones. But the app, API layer, and database still run within the boundaries of the USA. 

My next move would be to scale the messenger to other countries and continents and experiment with several YugabyteDB deployment options (my geo-distributed database).

Follow me to be notified as soon as the next update is published! And check out the previous articles in my geo-distributed messenger application development journey.

Cloud Load balancing (computing) mobile app Requests

Opinions expressed by DZone contributors are their own.

Related

  • Transforming Proprietary Trace Context to W3C Trace Context
  • Safeguarding Web Applications With Cloud Service Providers: Anti-CSRF Tokenization Best Practices
  • Provision Cloud Infrastructure Using Google Duet AI
  • Private Cloud's Deployment

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!