Skip to content

Load balancers and certificates

A load balancer takes traffic on one address and spreads it across Droplets, sending each request only to Droplets that pass its health check. It can pick its Droplets by tag, so new ones join as they’re created. A certificate lets it terminate HTTPS: DigitalOcean obtains and renews one from Let’s Encrypt for domains it hosts, or you upload your own.

const cert = yield* DigitalOcean.Certificate("Www", {
type: "lets_encrypt",
dnsNames: ["www.example.com"],
});

Let’s Encrypt certificates need the domain on DigitalOcean DNS, because DigitalOcean answers the challenge with DNS records. type: "custom" uploads your own certificate and key instead.

yield* DigitalOcean.LoadBalancer("Web", {
region: "nyc3",
tag: "web",
forwardingRules: [
{
entryProtocol: "https",
entryPort: 443,
targetProtocol: "http",
targetPort: 8080,
certificateId: cert.certificateId,
},
],
healthCheck: { protocol: "http", port: 8080, path: "/health" },
redirectHttpToHttps: true,
});

tag sends traffic to every Droplet with that tag; dropletIds names them instead. lb.ip is its public address.

sizeUnit adds capacity, stickySessions keeps a client on one Droplet, and network: "INTERNAL" makes it reachable only inside its VPC.

  • A load balancer serves Droplets in its own region.
  • A Let’s Encrypt certificate covers names in domains hosted on DigitalOcean DNS only.