High Availability, Active-Passive Pods & Rolling Updates
This guide explains how hermEX separates shared database state from local mailbox storage, how to build fault-tolerant Active-Passive backend pods inside a horizontally scaled multi-pod topology, and how Expand-and-Contract schema migrations support rolling updates and safe rollbacks. For step-by-step cluster provisioning from scratch, start with Multi-Node Cluster Installation; to convert an existing single-node host, see Single-to-Multi Migration; for database Galera setup and front-door ingress architectures, see Shared MariaDB 11.8 Cluster and L4 TCP Load Balancer.
1. Storage Architecture
hermEX uses two distinct persistence layers so each layer meets its consistency and locking requirements:
| Layer | Engine | What It Stores | Replication Model |
|---|---|---|---|
| Shared Control & Relay State | MariaDB 11.8 (directory + relay) | Domains, organizations, users, aliases, permissions, audit chain, centralized system_logs, outbound relay queue (relay_messages, relay_recipients), TLS-RPT/DMARC aggregation counters, and MTA-STS policy cache (relay_mtasts_cache). | Synchronous / multi-node DB cluster (for example MariaDB Galera or Managed HA MariaDB) |
| Mailbox Storage | Local SQLite WAL + Content Store | Per-mailbox objects.sqlite3, imapindex.sqlite3, binary attachment blobs (cid/), and cached RFC 5322 bodies (eml/). | Local NVMe/SSD or replicated block device (DRBD / cloud attach-detach volume) under single-writer lock |
Do not mount /var/lib/hermex/mail over NFS, SMB/CIFS, GlusterFS, or CephFS. Distributed filesystems do not provide reliable byte-range locking or atomic fsync ordering for SQLite WAL files across concurrent writers and can corrupt mailbox databases on network stalls. Always expose each mailbox store to a single active writer on a local filesystem or a synchronous block device.
2. Multi-Pod Horizontal Scale-Out Architecture
In a multi-pod deployment, edge proxies accept inbound client and SMTP traffic without local mailbox affinity constraints, all control and queue state lives in a highly available MariaDB cluster, and mailbox data is partitioned across independent backend pods keyed by users.homeserver and domains.homeserver against the servers registry table.
Internet / Corporate Clients
SMTP(25/465/587) IMAP(993) POP3(995) HTTPS(443)
|
+---------------+---------------+
| Edge Load Balancer / Proxy |
| (HAProxy / Envoy / Keepalived|
| stateless front endpoints) |
+---------------+---------------+
|
+--------------------------+--------------------------+
| | |
v v v
+------------------+ +------------------+ +------------------+
| Pod 0 (hs=0) | <--> | Pod 1 (hs=1) | <--> | Pod N (hs=N) |
| Active + Passive | HTTP | Active + Passive | HTTP | Active + Passive |
| Local SQLite WAL |Bridge| Local SQLite WAL |Bridge| Local SQLite WAL |
| VIP_0 + BlockVol | | VIP_1 + BlockVol | | VIP_N + BlockVol |
+--------+---------+ +--------+---------+ +--------+---------+
| | |
+--------------------------+--------------------------+
|
v
+---------------------------------------------+
| Shared MariaDB Cluster (3-Node Galera / HA) |
| - Directory, Servers, Audit, System Logs |
| - Outbound Relay Spool (FOR UPDATE SKIP |
| LOCKED across multiple MTA workers) |
+---------------------------------------------+
- Transparent front-door routing: Gateway HTTPS (
X-Hermex-Internal-AuthHMAC hop guard), IMAP (X-HERMEX-PROXY), POP3, ManageSieve, and MTA SMTP/LMTP automatically forward client sessions and deliveries to the owning pod resolved from MariaDBusers.homeserveranddomains.homeserver. - Cross-mailbox & Admin pod bridge: Under
/_internal/cluster/pod/(authenticated via HMAC timestamp and single-use nonce usinginternal_pod_secret), pods transparently delegate cross-mailbox Send-As/Sent-Copy, Webmail/EWS/ActiveSync/CalDAV/CardDAV/NSPI lookups, public folders, OutlookRopLogonecWrongServerredirects, remote Admin store/quarantine/export/import ops, clusterBayesModel.Merge, and streamingpod-<node>.tar.gzbackups. Background IMAP migrations, wake events, and retention sweeps filter strictly to each pod's localnode_id.
3. Active-Passive Backend Failover Pods
Horizontal sharding limits blast radius to one pod, yet a hardware failure on an un-replicated pod still interrupts mailboxes assigned to that pod. Pair each backend pod into an Active + Passive pair so any hardware failure or maintenance switchover restores mailbox access on the standby node within seconds.
Pod 0 Virtual IP (VIP_0)
|
+---------------------+---------------------+
| |
v v
+-------------------+ DRBD Protocol C / Sync +-------------------+
| Pod 0 Node A | -------------------------> | Pod 0 Node B |
| (ACTIVE Primary) | Corosync + Pacemaker | (PASSIVE Standby) |
| Mounted Volume | QDevice / Witness Vote | Unmounted Volume |
| 14 hermex-* Units | | hermex-* Stopped |
+-------------------+ +-------------------+
| |
+---------------------+---------------------+
|
v
Shared MariaDB Cluster (HA)
Replication Options for Pod Storage
Choose one single-writer block replication layer per Active-Passive pair:
- Bare-Metal / Colocation (
DRBD 9 Protocol C+Pacemaker/Corosync): Run DRBD in synchronous Protocol C mode so every write completes on both nodes before acknowledgment. Combine two nodes with a third lightweightcorosync-qnetdquorum witness (QDevice) and hardware fencing (STONITHvia IPMI/iDRAC/Redfish). - Cloud IaaS (Shared Attachable Block Volume + Pacemaker / Cloud Fence Agent): Attach one high-durability block volume (NVMe EBS Multi-Attach off, Hetzner Volume, or Ceph RBD single-writer) to Node A only. On failover, Pacemaker fences Node A, detaches the volume, attaches it to Node B, checks the XFS/ext4 journal, mounts
/var/lib/hermex/mail, moves the floating IP (VIP), and starts all 14hermex-*units.
Never allow two nodes to mount the same mailbox filesystem (objects.sqlite3, imapindex.sqlite3) simultaneously. Configure hardware or cloud-API fencing (STONITH), configure a quorum witness (QDevice) for two-node pairs, and enforce Pacemaker colocation and order constraints so the cluster runs steps in this exact sequence:
Promote / Attach Block Volume -> Mount /var/lib/hermex/mail -> Assign Floating VIP -> Start hermex-* Services
Reverse the sequence on stop: stop all 14 hermex-* units before releasing the VIP and demoting or detaching the storage volume.
Configuration Parity Between Active and Passive Nodes
Keep /etc/hermex/config.json identical on Node A and Node B (except optional node-local logging or NIC bindings if any):
- Copy all six cluster secrets identically:
webmail_secret,admin_secret,key_secret,digest_secret,notify_secret, andinternal_pod_secret. An identicalkey_secretis mandatory so both nodes decrypt DKIM private keys, TLS certificates, and SRS tokens from MariaDB, andinternal_pod_secretauthorizes inter-pod HTTP bridge and proxy hops across the cluster. - Point
database_dsn(and optionalrelay_database_dsn) to the shared MariaDB cluster VIP or HA proxy. - Keep identical
data_diranddata_partitionssettings on both nodes becauseusers.maildirstores the resolved mailbox directory path chosen at account creation. - Install identical release binaries under
/opt/hermex/currenton both nodes before failing over (or follow the Rolling Update Runbook below).
4. Expand-and-Contract Schema Compatibility
Every hermEX database enforces forward and backward version checks through a two-number compatibility contract across four independent schemas:
| Schema | Tracking Mechanism | Engine |
|---|---|---|
directory | schema_migrations (version, applied_at, min_compatible) | MariaDB |
relay | relay_schema_migrations (version, applied_at, min_compatible) | MariaDB |
objects | SQLite PRAGMA user_version (version | (min_compatible << 16) + PRAGMA application_id) | SQLite per mailbox |
index | SQLite PRAGMA user_version (version | (min_compatible << 16) + PRAGMA application_id) | SQLite per mailbox |
Expand vs. Contract Rules
- Expand migration (backward-compatible): Adds new tables, nullable or defaulted columns, additive indexes, or new data without removing or breaking columns read by the previous release. The schema's
min_compatiblevalue remains equal to the older version, so older and newer hermEX binaries can access the same MariaDB database concurrently during a rolling update. - Contract migration (breaking DDL): Drops tables or columns, renames identifiers, or tightens
NOT NULLrules without defaults. Contract SQL files must contain a-- migrate:contract(or explicit-- migrate:min_compatible=N) directive at the top of the.sqlfile. When applied,min_compatibleadvances to the Contract version, and older binaries immediately refuse to start rather than corrupting or misreading data (ErrDowngrade).
The 3-Column SCHEMA Manifest
Every release tarball (hermex-linux-amd64.tar.gz and hermex-linux-arm64.tar.gz) ships a hermex/SCHEMA file listing <database> <target_version> <min_compatible>:
directory 84 71
relay 1 1
objects 29 25
index 8 5
install.sh reads this manifest during update and rollback to distinguish safe Expand upgrades from Contract boundaries automatically.
5. Step-by-Step Rolling Update Runbook
Use this sequence to upgrade a multi-pod cluster and each Active-Passive pod without extended downtime.
Case A: Expand Release (Safe Zero/Low-Downtime Rolling Update)
- Create a pre-upgrade safety backup once per cluster:
sudo hermex-admin backup-dbsudo cp /etc/hermex/config.json /root/config.json.pre-update
- Stage the new release on the Passive node first (Node B) while the Active node (Node A) serves live traffic. Download and verify
hermex-linux-<arch>.tar.gz,SHA256SUMS, andinstall.sh. Inspect theSCHEMAfile inside the archive to verify whether the release is Expand-only (min_compatible <= previous_version):tar -xOzf hermex-linux-amd64.tar.gz hermex/SCHEMA - Unpack the new binaries on Node B while
hermex-*units remain stopped on Node B (only/opt/hermex/releases/<build-id>and the/opt/hermex/currentsymlink update). Do not start MariaDB migrations manually on a passive node without stopping or coordinating writers unless the migration is Expand-only; runninghermex-admin ensure-schemaon an Expand release is safe while Node A runs. - Apply Expand MariaDB migrations and trigger a planned Pacemaker switchover from Node A to Node B:
Node A cleanly stops its 14# On Node B before taking ownership (applies Expand DDL safely)sudo /opt/hermex/current/bin/hermex-admin ensure-schema# Move the pod resource group from Node A -> Node Bsudo pcs resource move pod0-group node-b
hermex-*units, demotes/detaches storage, Node B mounts/var/lib/hermex/mail, claimsVIP_0, and starts the upgraded 14 daemons within seconds. - Verify the newly active Node B:
All targets must reportsudo hermex-admin statussudo hermex-admin mailqsudo hermex-admin audit-verify
Upon the new version. - Upgrade the now-passive Node A via
/root/install.sh update --from /path/to/hermex-linux-amd64.tar.gz(or extract + switch symlink and clear any Pacemaker move constraints withsudo pcs resource clear pod0-group). - Repeat pod by pod (
Pod 1,Pod 2, ...Pod N) and finish with stateless Edge Load Balancers / Proxies.
Case B: Contract Release (Two-Phase Upgrade)
When a release introduces -- migrate:contract (shown by min_compatible == target_version in hermex/SCHEMA):
- Drain or pause older nodes before running the Contract binary, because older binaries intentionally exit with a schema compatibility error once the Contract migration advances
min_compatible. - Update all binaries across the Active and Passive nodes of all pods sharing that MariaDB database during a brief coordinated maintenance window so no down-level process reconnects to the contracted schema.
- Verify every node reports
Upviahermex-admin statusbefore reopening external SMTP/client traffic on the edge load balancer.
6. Rollback & Failback
Rolling Back After an Expand Release
If you detect a regression after an Expand-compatible upgrade:
sudo /root/install.sh rollback
install.sh rollback compares the active database version and min_compatible against the previous release's SCHEMA file (directory, relay, objects, index). Because min_compatible did not cross past the previous release, install.sh rollback keeps your live MariaDB database and live mailboxes intact (zero mail loss during the window since upgrade) and reverts the binaries cleanly to /opt/hermex/current.
Rolling Back After a Contract Release
If a release contracted any schema (min_compatible > previous_version), install.sh rollback refuses to revert binaries against the contracted database unless --restore-db is passed:
- MariaDB contracted (
directoryorrelay): Pass--restore-dbto stop daemons, restore the pre-upgrade snapshot created automatically byinstall.sh updateunder/var/lib/hermex/backup/, and restart the previous binaries:sudo /root/install.sh rollback --restore-db - SQLite mailbox store contracted (
objectsorindex):install.sh rollbackaborts rather than corrupting mailbox files and reports the exact schema/min_compatible mismatch. Restoring SQLite stores across a Contract boundary requires restoring mailbox backups taken withhermex-admin backup-mailprior to the Contract upgrade.
After an unplanned failover where Node A crashed and Node B took ownership:
- Repair Node A and verify all 14 binaries on Node A match Node B (
/opt/hermex/currentbuild ID). - Confirm block storage replication is
UpToDateon both nodes (for DRBD:sudo drbdadm status) so zero mailbox writes are dropped on return. - Configure non-preemptive Pacemaker
resource-stickinesson active pod groups in production so a recovered node rejoins passively as standby instead of causing a second surprise switchover during peak traffic. Schedule failback during a quiet maintenance window if preferred.
7. Shared MariaDB Outbound Relay Spool Configuration
The outbound SMTP relay queue, TLS-RPT counters, DMARC aggregation tables, and MTA-STS policy cache live in MariaDB (relay_messages, relay_recipients, relay_tlsrpt_counters, relay_tlsrpt_reports_sent, relay_dmarc_counters, relay_dmarc_reports_sent, relay_mtasts_cache, and relay_schema_migrations).
Configuring relay_database_dsn in /etc/hermex/config.json
By default, leaving relay_database_dsn empty ("") shares the primary database_dsn MariaDB connection:
{
"database_dsn": "hermex:SECRET@tcp(db-vip.internal:3306)/email?parseTime=true&multiStatements=true",
"relay_database_dsn": ""
}
If you want to isolate high-volume outbound relay queue I/O onto a dedicated MariaDB database or cluster while sharing directory state on database_dsn, set relay_database_dsn explicitly in /etc/hermex/config.json:
{
"database_dsn": "hermex:SECRET@tcp(dir-db.internal:3306)/email?parseTime=true&multiStatements=true",
"relay_database_dsn": "hermex:SECRET@tcp(relay-db.internal:3306)/email_relay?parseTime=true&multiStatements=true"
}
- Legacy upgrade migration: On startup,
hermex-mtachecks{data_dir}/relay.sqlite3. If a legacy SQLite spool exists,hermex-mtacopies queued items, TLS-RPT/DMARC counters, and cached MTA-STS policies into MariaDB in a single transaction, then renamesrelay.sqlite3(plus-wal,-shm,.init-lock) to*.migrated. - Multi-node worker locking: Multiple
hermex-mtainstances connected to the same MariaDB relay database claim outbound recipients concurrently usingSELECT ... FOR UPDATE SKIP LOCKEDand atomicTryMarkStartedrow transitions without duplicate deliveries or SQLite file locking. - Unified database backups: Because all
relay_*tables reside in MariaDB,hermex-admin backup-dbbacks up queued messages and reporting state alongside directory and audit data. If you use a separaterelay_database_dsndatabase, include that target schema in yourmariadb-dump/ cluster snapshot schedule.