How to Round-Robin Load Balance 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.
Round-robin load balancing is a simple method to distribute client requests among a group of services. To do this, the load balancer goes through the list of servers and sends each request to the next server in the list, starting again from the beginning after reaching the end of the list.
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
ngrok api reserved-domains create \
--url ${NGROK_SUBDOMAIN}.ngrok.app
- Replace or set
NGROK_SUBDOMAIN
as the subdomain you'd like to use for this guide.
curl \
-X POST https://api.ngrok.com/reserved_domains \
-H "Authorization: Bearer ${NGROK_API_KEY}" \
-H "Content-Type: application/json" \
-H "Ngrok-Version: 2" \
-d @- <<BODY
{
"name":"${NGROK_SUBDOMAIN}.ngrok.app",
}
BODY
- 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:
200 OK
{
"id":"rd_2MT5Bqt0UzU0mFQ0zr8m1UQWCfm",
...
}
When you have completed this step, you can move on to the next step.