Datastore (rqlite)¶
Nexus GSLB stores all data-plane objects — pools, members, services, health checks, geo rules, redirects, TSIG keys, TXT records, users, tenants, roles, settings — in rqlite, a Raft-replicated SQLite cluster. rqlite handles cross-node replication; there is no NATS DB sync and no file-copy replication.
This is distinct from the other two config layers:
- Configuration (YAML) is owned by git, applied per-node via GitOps self-restart.
- Ephemeral cluster state (health, heartbeats, RTTs, sessions) flows over NATS with TTLs.
Two processes per node¶
Each node runs two services:
| Process | Role |
|---|---|
rqlited |
The rqlite datastore. Holds the SQLite store + Raft log; replicates across nodes. A third-party binary, not built from this repo. |
gslbd |
The GSLB daemon. Connects to the local rqlited over its HTTP API (localhost:4001). |
systemd ties them together: gslbd.service has Requires= + After=rqlited.service,
and gslbd waits for a Raft leader on startup before serving.
gslbd talks to rqlite via the gorqlite client through a custom database/sql
driver (internal/storage/rqlite_driver.go). The driver normalises rqlite's JSON
number encoding (float64) back to int64 so timestamp/integer scans are exact. The
whole stack is CGO-free (CGO_ENABLED=0).
Foreign keys are required¶
rqlited must run with the -fk flag. The schema relies on
ON DELETE CASCADE (members/health_checks/geo_rules → pools, users → tenants);
without -fk those cascades silently no-op. The shipped deploy/rqlited.service
sets -fk.
Configuration¶
gslbd's rqlite config block tells it how to reach the local rqlited:
rqlite:
httpAddr: "localhost:4001" # matches rqlited -http-addr
connectTimeout: "10s" # startup connect + leader-wait budget
dataDir: "/var/lib/gslbd/rqlite"
joinAddrs: [] # peers for a joining node (empty = standalone)
# tls: # HTTPS to rqlited (optional)
# enabled: true
# caFile: /etc/gslb/rqlite-ca.pem
# certFile: /etc/gslb/rqlite-client.pem
# keyFile: /etc/gslb/rqlite-client-key.pem
# auth:
# username: gslbd
# password: change-me
Cluster membership (node id, bind/advertised addresses, join targets) is configured
on rqlited, not here — see deploy/rqlited.env.
Cluster bootstrap and join¶
rqlited node settings live in /etc/gslb/rqlited.env (read by rqlited.service).
Nodes form one Raft cluster over the private network (e.g. WireGuard).
First node (bootstrap) — no join target; bind/advertise on the address peers reach it on:
Additional nodes (join) — point at an existing peer's Raft address (port
4002, bare host:port; v8+/v10 reject http:// URLs and the HTTP port for -join).
A joining node wipes its own local data and adopts the leader's, so bootstrap the
node holding the data you want to keep and join the rest to it.
RQLITE_NODE_ID=eu-01
RQLITE_HTTP_ADDR=10.100.0.2:4001
RQLITE_RAFT_ADDR=10.100.0.2:4002
RQLITE_EXTRA_FLAGS=-join 10.100.0.1:4002 # peer RAFT addr, not http://, not :4001
Firewall: ports 4001 (HTTP) and 4002 (Raft) must be reachable between peers on the cluster interface. With ufw active, allow them from the mesh subnet only — ICMP reachability is not sufficient, the Raft TCP port must be open both ways or the leader loses quorum:
ufw allow from 10.100.0.0/24 to any port 4001 proto tcp
ufw allow from 10.100.0.0/24 to any port 4002 proto tcp
Apply with systemctl restart rqlited. Verify membership (expect all nodes
reachable: true, one leader: true):
A single-node install needs nothing beyond the defaults — rqlited bootstraps a
one-node Raft cluster on localhost.
Raft timeouts on a WAN cluster¶
rqlite's Raft defaults are LAN-grade: 1s heartbeat, 1s election, 500ms leader lease. If your nodes are in different datacentres — or one is a homelab behind a domestic line — leave them alone at your peril. Two slow heartbeats in a row and the leader concludes it has lost quorum:
[WARN] failed to contact: server-id=vps1.rbnsn.uk time=574.883875ms
[WARN] failed to contact: server-id=nexus-gslb time=562.256978ms
[WARN] failed to contact quorum of nodes, stepping down
The cluster re-elects a second later and carries on, so nothing appears broken.
That is what makes it easy to miss: it flaps rather than fails. The only
symptoms are in the gslbd log, once per event:
rollout: list active failed could not determine leader from /nodes call
changegate: list open failed could not determine leader from /nodes call
zones: failed to refresh from DB could not determine leader …
soa: failed to refresh zone state version …
During the window every write, and every read at leader consistency (gorqlite's default), fails. Background controllers skip a tick and recover on the next one.
Sizing¶
Measure the worst peer, not the average — ping -c 20 <peer-wg-address> and read
max and mdev, since it is the jitter that eats the lease.
| Worst peer RTT | -raft-heartbeat-timeout / -raft-election-timeout |
-raft-leader-lease-timeout |
|---|---|---|
| < 1ms (LAN, same rack) | leave unset (1s) | leave unset (500ms) |
| ~20ms (same region) | 2s |
1s |
| ~120ms (cross-continent, homelab) | 3s |
2s |
| > 250ms | 5s |
3s |
The leader lease must be ≤ the heartbeat timeout or rqlited refuses to
start.
Set them in RQLITE_EXTRA_FLAGS, alongside -join on nodes that have one:
# bootstrap node
RQLITE_EXTRA_FLAGS=-raft-heartbeat-timeout=3s -raft-election-timeout=3s -raft-leader-lease-timeout=2s
# joining node
RQLITE_EXTRA_FLAGS=-join 10.100.0.1:4002 -raft-heartbeat-timeout=3s -raft-election-timeout=3s -raft-leader-lease-timeout=2s
The trade-off¶
Longer timeouts mean a genuinely dead leader takes seconds rather than ~1s to be
noticed. For Nexus that is the right trade: every node answers DNS from its own
local rqlited and its own cached snapshots, so a leaderless window delays
configuration changes — it does not stop resolution. Frequent flapping, by
contrast, costs a write outage every time.
Applying it to a live cluster¶
Roll one node at a time, followers first and the leader last, so you never
drop below quorum. Check curl -s http://<wg-addr>:4001/nodes between each and
wait for all peers to read reachable: true before moving on:
Restarting the leader hands leadership to another node. That is a normal controlled failover, not a fault.
Read consistency: the DNS path reads locally¶
gslbd holds two handles onto the same cluster.
| Handle | Used by | rqlite read level | Where the read is answered |
|---|---|---|---|
| default | API, controllers, anything that reads back its own write | weak |
the Raft leader |
| local-read | the DNS query path only | none, cluster discovery off |
this node's own copy |
The default client resolves the leader on connect and sends every query there, so on a WAN cluster a follower's read costs a full round trip to the leader — measured at 370–700 ms between eu-01 and lab-01, against a DNS query budget of 200 ms. Every uncached lookup on a follower therefore timed out, and the node answered as though the name did not exist. Both halves of the local-read handle matter: the read level alone changes nothing while cluster discovery still points the connection at the leader.
The trade-off is replication lag: the DNS path can serve data a few
milliseconds older than the leader holds. That is already true of everything
around it — the zone engine refreshes on a 5 s tick and answers sit behind a
30 s database.cacheTTL — and it is the difference between answering from a
local replica and not answering at all.
Writes are unaffected at either level: rqlited forwards every write to the
leader itself. Control-plane reads keep leader consistency, so an API key
revocation or a config change still takes effect on the next request on every
node.
storage.DB.LocalReadClone builds the second handle; cmd/gslbd/setup_database.go
wires it, and the DNS cache wraps it, not the default handle.
Backups¶
gslbd backs up the database by calling rqlite's /db/backup endpoint, which
streams the full SQLite database from the cluster leader to the local gslbd host
(written atomically: temp + rename). This replaces the old file-copy/VACUUM INTO
backup, which is meaningless in a clustered deployment. Configure under backup:
(see Configuration).
Local development / testing¶
rqlite ships no macOS binaries — use Docker for local/CI work:
docker run -d -p 4001:4001 -p 4002:4002 rqlite/rqlite \
-fk -http-adv-addr localhost:4001 -raft-adv-addr localhost:4002
The -*-adv-addr localhost flags are required for a container: without them
rqlite advertises its internal container hostname, which the gorqlite client
(following leader redirects) cannot resolve from the host. Storage/API/DNS
integration tests connect to RQLITE_TEST_ADDR (default localhost:4001) via
internal/storage/storagetest and skip when no server is reachable.
Code references¶
internal/storage/rqlite.go—DB,Open(Options), schema migration, leader-wait.internal/storage/rqlite_driver.go— thedatabase/sqldriver overgorqlite.internal/storage/testsupport.go,internal/storage/storagetest/— test helpers.deploy/rqlited.service,deploy/rqlited.env— the datastore unit + node config.