elements
Blog Demos UI Docs Pricing
Elements Manual
  • Getting Started
  • CLI
  • Build
  • Browser
  • Packages
  • TypeScript
  • Elements HTML
  • Assets
  • RPC
  • Router
  • Session
  • Database
  • Migrations
  • LiveTable
  • Channel
  • Jobs
  • Email
  • Payments
  • JSON
  • Async
  • Style
  • UI
  • JSOC
  • Config
  • Tests
  • Logs
  • Deploy
    • Setup
    • Sizing
    • AWS
    • DigitalOcean
    • Email Setup
    • CDN
    • Walkthrough
    • Domain
    • What Deploy Does
    • Environments
    • Load Balancer
    • Operations
    • Machines
  • Editors
  • Recipes
  • Licenses
  • Releases
Manual / Deploy/ Load Balancer

Load Balancer

elements man deploy/load-balancer

TLS, DNS, routing, and the certificate lifecycle Elements manages for you.

Every Elements deploy machine runs its own load balancer. It is part of Elements, starts alongside the app, and gives you two things automatically: SSL via Let's Encrypt for every configured domain, and request balancing across every machine in the environment. There is no extra software to install, no separate appliance to put in front of the cluster, and no separate config file to maintain. The load balancer reads the same config.jsoc your app reads, and it auto-reloads on new builds as needed, so changes to domains, certificates, or services propagate without restarting anything.

Because every machine runs the same load balancer and knows about every other machine in the environment, you can point your DNS at one of your machines, several of them, or all of them. Whichever box receives a request will distribute it across the cluster.

What it does:

  • HTTP listener on port 80 (configurable). Serves ACME challenges and 301-redirects to HTTPS when TLS is on.
  • HTTPS listener on port 443 (configurable). Terminates TLS, then proxies to the app or service backend.
  • Auto SSL via ACME / Let's Encrypt. Certificates issued and renewed automatically for every configured domain.
  • Static SSL: bring-your-own certificates served by SNI match (overrides ACME for those hosts).
  • Host routing: dispatches by Host header to the app or a named service.
  • Round-robin: balances requests across all machines in the environment.
  • Failover: retries other machines when a backend fails. Serves the maintenance page only when every backend is unreachable.
  • Redirects: 301 from the www pair of each server.domain value to the value, before any service routing.
  • Maintenance: serves a static maintenance page on elements maint on.

The load balancer hot-swaps its handler atomically when the project config changes. Adding a domain, flipping ssl, or rotating a static cert takes effect without dropping connections.

Domains

The LB serves every value of server.domain (elements man config), read from the deploy machine's own environment: the machine evaluates config.jsoc with its config/env/<name>.env, so env!("DOMAIN") is the production host there. Each value is certified along with its www pair, and the pair is a 301 to the value with the path and query kept: www.example.com goes to example.com, or example.com goes to www.example.com when the value is the www form. A host that is itself a value is never redirected, so listing both serves both. Local names (localhost and anything under .localhost) are skipped.

Auto SSL (acme)

When ssl: true (the default when server.domain has a public host) and the machine has a publicIp, the LB enables ACME via Let's Encrypt. When a deploy changes the host list, the LB requests a certificate for every server.domain value and service host right away, a few at a time, using the HTTP-01 challenge served on port 80. A www pair is requested only when its name resolves, and a host with a valid cached certificate is not requested again. Handshakes use the cached certificate. Renewal happens automatically before expiry.

Set up:

  1. Configure the domain in server.domain (and any service domains).
  2. Point DNS at the machine's public IP.
  3. Open ports 80 and 443 to the public internet.

A host whose certificate fails (DNS not pointing at the machine yet, ports closed) is logged on the machine with the reason, and is tried again on its first HTTPS request.

ACME is enabled when deploy.ssl is true (default if server.domain has a public host), at least one domain is configured, and the machine has a publicIp. When any condition is missing, TLS is disabled and the LB serves cleartext on port 80. Useful for internal-only deployments or local testing.

Static TLS Certs

To override ACME for specific hosts, drop a cert/key pair on disk and reference them in deploy.tlsCerts:

config.jsoc
deploy: { tlsCerts: { "*.example.com": { cert: "config/tls/wildcard.crt", key: "config/tls/wildcard.key" }, "example.com": { cert: "config/tls/wildcard.crt", key: "config/tls/wildcard.key" }, "api.example.com": { cert: "config/tls/api.crt", key: "config/tls/api.key" }, }, }

When the LB sees a matching SNI hostname, it serves the static cert instead of talking to ACME. Match priority:

  1. Exact match (api.example.com).
  2. Single-label wildcard (*.example.com).

ACME continues to operate for any host without a static entry. The two modes coexist per-host.

Cert paths resolve relative to the project root. Keep keys out of version control (mode 600; add to .gitignore).

DNS

Point DNS at the public IP of one or more machines. For a small app, point at production0 and stop:

DNS records
A example.com <production0 publicIp>

For redundancy or scale, point at multiple machines:

DNS records
A example.com <production0 publicIp> A example.com <production1 publicIp> A example.com <production2 publicIp>

DNS round-robin distributes incoming requests across machines. The LB on each machine then round-robins to all the other machines, so a request that hits the busiest machine still gets balanced. Multiple A records also give you DNS-level failover: if one machine is unreachable at the network level, the resolver uses another.

Failover is built in: each load balancer retries the next machine on a failed request. A DNS provider with health checks works alongside it.

Routing

The LB looks at the Host header on each request:

  1. Strip the port.
  2. If the host is the www pair of a server.domain value, return 301 to the value.
  3. If the host matches a service's domains, proxy to that service's port (round-robined across machines).
  4. Otherwise, proxy to the app backend (default port 4000, round-robined across machines).
config.jsoc
deploy: { services: [ { name: "api", port: 8080, domains: [env!("DOMAIN_API")], bin: "services/api/bin/api", }, ], }

Service hosts are plain values, usually from env!() so each environment has its own. They are not server.domain keys: the router never sees service traffic. They get no www pair.

Round-Robin and the public/private Distinction

Public requests (source IP outside the private network) are round-robined across every machine in the environment that has a privateIp. Each LB picks a different machine on each request via an atomic counter.

Requests from a private IP (other LBs forwarding to this one) are served locally instead of being round-robined again. This prevents infinite loops where two LBs forward to each other indefinitely.

Failover

When a backend connection fails (refused, timeout), the LB tries the next machine. It cycles through every backend before giving up. Only when every backend is unreachable does the LB serve the maintenance page.

A single machine going down doesn't take traffic out. Add machines for headroom; the cluster heals itself per request.

Maintenance Page

Terminal
elements maint on # every production machine elements maint off elements maint on -remote=staging elements maint on -remote=production#production1

While it is on, every machine serves the static maintenance page on every request instead of proxying. It takes effect at once, from any terminal, and does not wait on a build or a deploy in progress: use it for a planned outage, a release you want hidden while you fix it, or a deploy that is taking longer than it should. It stays on until elements maint off, and a deploy does not turn it off. A project server restart clears it.

A normal deploy never shows the page. Deploys are zero-downtime: the previous release serves until the new one is ready. For a deploy with a long-running migration, elements deploy -maint shows the page on every machine from just before the app database migration until the release, then takes it down. The build, the test database migration and the tests run before that with the site up.

The page is static/maint.html in the project. It is also served when no backend is reachable, and while the app starts.

CDN

A CDN isn't required. Asset URLs are content-hashed and the LB serves them with Cache-Control: immutable, so the browser caches them indefinitely after the first fetch, and the origin serves asset traffic directly.

CDN (opens in a new tab) sets up CloudFront step by step. With any CDN (CloudFront, Cloudflare, Fastly, Bunny, etc.) the integration is one config setting:

  1. Create a distribution at the CDN. Point it at the LB's public IP or hostname as the origin. The CDN gives you a hostname back, e.g. d1234abcd.cloudfront.net.

  2. Set build.assetUrl in config.jsoc:

    config.jsoc
    { build: { assetUrl: env("ASSET_URL", ""), }, }
    config/env/production.env
    ASSET_URL=https://d1234abcd.cloudfront.net
  3. Deploy.

That's the entire integration. The build rewrites every emitted asset reference in your pages to use that base URL. Browsers fetch from the CDN; the CDN fetches from origin once on cache miss, then serves from edge.

In development, leave ASSET_URL empty. Elements emits relative URLs that hit the LB directly. There is nothing to switch on between development and production beyond the environment variable.

Configure the CDN to forward the Host header so the LB's host routing still works for any non-asset request that hits the same distribution.

Prev EnvironmentsNext Operations
Product
Manual Pricing Compare
Company
History Contact
Legal
Privacy Policy Acceptable Use Terms License Agreement
© Elements Dev Corporation 2026