How to do Weighted Round-Robin Load Balancing with ngrok Cloud Edges
The purpose of Load balancing is to improve application performance and reduce burden by distributing incoming traffic across servers. This leads to faster response times for user-facing applications.
Weighted Round-robin load balancing while similar to round-robin load balancing here you can assign a numeric weight to all of the applications behind the load balancer. Weights can be assigned based on factors such as the application state, server’s processing power or total bandwidth.
Prerequisites
To follow this guide, you will need:
- An ngrok Pro or Enterprise account.
- A local computer with
ngrok
installed by following our installation guides.
If you are going to be following along using ngrok CLI, you will need:
- An ngrok API key configured on your ngrok agent.
If you are going to be following along using CURL, you will need:
- An ngrok API key as an environment variable named
NGROK_API_KEY
.
Step 1 — Create a Reserved Domain
We're going to be using ngrok edges to load balance across multiple tunnels.
To start load balancing traffic with ngrok edges, you need to have a reserved domain.
Let’s reserve a subdomain on ngrok.app
:
- ngrok CLI
- CURL
Loading…
- Replace or set
NGROK_SUBDOMAIN
as the subdomain you'd like to use for this guide.
Loading…
- Replace or set
NGROK_API_KEY
to your ngrok API key. - Replace or set
NGROK_SUBDOMAIN
as the subdomain you'd like to use for this guide.
After running, you should see the following:
Loading…
When you have completed this step, you can move on to the next step.
Step 2 — Create a ngrok Cloud Edge
Now we can create a ngrok Cloud Edge that points to our
newly reserved domain on port 443
:
- ngrok CLI
- CURL
Loading…
- Replace or set
NGROK_SUBDOMAIN
with the value used in the previous step.
Loading…
- Replace or set
NGROK_API_KEY
to your ngrok API key. - Replace or set
NGROK_SUBDOMAIN
with the value used in the previous step.
After running, you should see:
Loading…
Export the id
value as a new environment variable named NGROK_EDGE_ID
:
Loading…
Now that we have an edge, we can move onto the next step.
Step 3 — Create Tunnel Group Backends
Now that we have an edge we can begin to build the parts to do weighted load balancing.
Lets create two tunnel-group backends to do traffic management on our edge.