Load balancers
One address spread over two or more of your web services, on one machine or across geos.
A load balancer gives several of your web services one address. It sends each request to one of them, in the way you choose, and skips a web service that isn't answering. The web services can be on any of the project's machines, in any geo.
Use one to keep an app online when a machine goes down, to spread traffic over more than one machine, or to serve visitors from machines in more than one geo.
Before you start
You need at least two web services running the same app and connected to the same database, so any of them can answer any visitor. Each web service can be in only one load balancer.
A web service with password protection, or a private service, can't join. Turn password protection off, or make the service public, first.
Create a load balancer
- On the project's Services page, click Add next to Load balancers.
- Fill in the form:
- Name: its address is this name under
appentic.app, likeshop.appentic.app. - Web services: switch on 2 to 10. Set Order or Weight if your routing algorithm uses them (see below).
- Routing algorithm: see Routing algorithms.
- Name: its address is this name under
- Click Create load balancer.
The form shows the monthly fee under Price. Setup takes a minute or two.
Routing algorithms
A member is a web service the load balancer sends traffic to.
| Algorithm | What it does |
|---|---|
| Round robin | Each request goes to the next member in turn. |
| Weighted round robin | Like round robin, with each member's Weight, from 1 to 100. A weight of 3 gets three times the requests. |
| Least connections | Each request goes to the member with the fewest requests in progress. |
| Random, two choices | Picks two members at random and sends the request to the less busy one. |
| Sticky, by cookie | A visitor keeps going to the same member, remembered in a cookie. |
| Sticky, by address | A visitor keeps going to the same member, chosen by their IP address. |
| Priority failover | Everything goes to the first healthy member in Order, 1 first. The others are hot standbys. |
Health checks
The load balancer skips a member that isn't answering:
- As it sends traffic. A member that refuses a request or returns an error is skipped for 30 seconds, and the request goes to another member.
- Ahead of visitors. When every member has the same health check path set, the load balancer also checks that path on each member every 5 seconds. See Health check path.
The machines it runs on
A load balancer runs on every machine its web services run on, so there's nothing to choose. Visitors can arrive at any of those machines, and each one spreads traffic over all the web services, wherever they run.
To keep the address answering if a whole geo goes down, put its web services in more than one geo.
If a machine stops answering, it's taken out of the load balancer's address within about a minute, and visitors go to its other machines. It goes back in once it answers again. A machine you stop or change is taken out straight away. Each change is recorded on the load balancer's Events page.
The Overview
The load balancer's Overview shows:
- Address: its
appentic.appaddress and its routing algorithm. - Web services: each member in order, the machine it runs on, its weight with weighted round robin, and whether it is Live.
- Machines: each machine it runs on, with Getting visitors, Taken out or Not checked yet, and when it was last checked.
Domains
A load balancer is the only way in to its web services. While a web service is a member, it has no address of its own. Its appentic.app address and custom domains stop answering, and its Settings page has no Domains section.
A web service's custom domains move to the load balancer when it joins, so a domain that was working keeps working.
On the load balancer's Settings page, under Domains:
- Appentic address: change its name under
appentic.appand click Update. The old address keeps working. The address is fixed while the load balancer has custom domains. - Your own domain: add domains you own, the same way as on a web service. See Custom domains.
Point your DNS at the load balancer's appentic.app address:
- A subdomain, like
www.shop.comorapp.shop.com: add a CNAME record pointing at the load balancer's address. - A root domain, like
shop.com: use your DNS provider's ALIAS, ANAME or CNAME flattening, pointing at the load balancer's address. Don't use an A record. It would point at one machine and stop working if that machine is taken out or changes.
The certificate is issued automatically and works in every zone the load balancer runs in.
Change it
On the load balancer's Settings page, under Traffic, switch web services on or off, change their Order and Weight, or pick another Routing algorithm. Changes save as you make them (an order or weight when you leave the field) and are live within a minute.
A web service restarts once when it joins or leaves. One that leaves gets its own address back, but its custom domains stay with the load balancer.
When you delete a web service, it leaves its load balancer. A load balancer whose last web service is deleted is removed with it.
Behind the firewall
When the project's firewall has Protect new web services and load balancers on (the default), a new load balancer starts behind it. The firewall then checks every request to the load balancer before a web service is chosen. Each of the load balancer's copies needs 64 MB more memory for the firewall's rules. See Firewall.
To put a load balancer behind the firewall or take it out, use the firewall's Settings, under Protects. If you remove the firewall, the load balancer keeps working without it.
Remove it
On the Settings page, under Danger Zone, click Remove load balancer and confirm. Its address stops working. Its web services get their own addresses back, and its custom domains move to its first web service, so they keep working. Billing stops as soon as it's gone.
A machine stays in use while it runs one of a load balancer's web services. Move those web services off it, or take them out of the load balancer, before you remove the machine.
Price
A load balancer has a monthly service fee, shown as Price on the create form and billed by the second. Each of its proxies also holds 96 MB of memory on its machine, or 160 MB behind the firewall. See How billing works.
Databases and key value stores
A load balancer is for web services only. To keep a database or key value store serving when its machine goes down, give it a standby. See Postgres standby and Key value store standby.