Skip to main content

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:

LayerEngineWhat It StoresReplication Model
Shared Control & Relay StateMariaDB 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 StorageLocal SQLite WAL + Content StorePer-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 place live SQLite WAL mailboxes on shared network filesystems

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) |
+---------------------------------------------+
Front-door routing & signed inter-pod HTTP bridge
  • Transparent front-door routing: Gateway HTTPS (X-Hermex-Internal-Auth HMAC hop guard), IMAP (X-HERMEX-PROXY), POP3, ManageSieve, and MTA SMTP/LMTP automatically forward client sessions and deliveries to the owning pod resolved from MariaDB users.homeserver and domains.homeserver.
  • Cross-mailbox & Admin pod bridge: Under /_internal/cluster/pod/ (authenticated via HMAC timestamp and single-use nonce using internal_pod_secret), pods transparently delegate cross-mailbox Send-As/Sent-Copy, Webmail/EWS/ActiveSync/CalDAV/CardDAV/NSPI lookups, public folders, Outlook RopLogon ecWrongServer redirects, remote Admin store/quarantine/export/import ops, cluster BayesModel.Merge, and streaming pod-<node>.tar.gz backups. Background IMAP migrations, wake events, and retention sweeps filter strictly to each pod's local node_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:

  1. 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 lightweight corosync-qnetd quorum witness (QDevice) and hardware fencing (STONITH via IPMI/iDRAC/Redfish).
  2. 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 14 hermex-* units.
Prevent split-brain with fencing and strict ordering

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, and internal_pod_secret. An identical key_secret is mandatory so both nodes decrypt DKIM private keys, TLS certificates, and SRS tokens from MariaDB, and internal_pod_secret authorizes inter-pod HTTP bridge and proxy hops across the cluster.
  • Point database_dsn (and optional relay_database_dsn) to the shared MariaDB cluster VIP or HA proxy.
  • Keep identical data_dir and data_partitions settings on both nodes because users.maildir stores the resolved mailbox directory path chosen at account creation.
  • Install identical release binaries under /opt/hermex/current on 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:

SchemaTracking MechanismEngine
directoryschema_migrations (version, applied_at, min_compatible)MariaDB
relayrelay_schema_migrations (version, applied_at, min_compatible)MariaDB
objectsSQLite PRAGMA user_version (version | (min_compatible << 16) + PRAGMA application_id)SQLite per mailbox
indexSQLite 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_compatible value 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 NULL rules without defaults. Contract SQL files must contain a -- migrate:contract (or explicit -- migrate:min_compatible=N) directive at the top of the .sql file. When applied, min_compatible advances 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)​

  1. Create a pre-upgrade safety backup once per cluster:
    sudo hermex-admin backup-db
    sudo cp /etc/hermex/config.json /root/config.json.pre-update
  2. 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, and install.sh. Inspect the SCHEMA file inside the archive to verify whether the release is Expand-only (min_compatible <= previous_version):
    tar -xOzf hermex-linux-amd64.tar.gz hermex/SCHEMA
  3. 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/current symlink update). Do not start MariaDB migrations manually on a passive node without stopping or coordinating writers unless the migration is Expand-only; running hermex-admin ensure-schema on an Expand release is safe while Node A runs.
  4. Apply Expand MariaDB migrations and trigger a planned Pacemaker switchover from Node A to Node B:
    # 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 B
    sudo pcs resource move pod0-group node-b
    Node A cleanly stops its 14 hermex-* units, demotes/detaches storage, Node B mounts /var/lib/hermex/mail, claims VIP_0, and starts the upgraded 14 daemons within seconds.
  5. Verify the newly active Node B:
    sudo hermex-admin status
    sudo hermex-admin mailq
    sudo hermex-admin audit-verify
    All targets must report Up on the new version.
  6. 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 with sudo pcs resource clear pod0-group).
  7. 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):

  1. 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.
  2. 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.
  3. Verify every node reports Up via hermex-admin status before 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 (directory or relay): Pass --restore-db to stop daemons, restore the pre-upgrade snapshot created automatically by install.sh update under /var/lib/hermex/backup/, and restart the previous binaries:
    sudo /root/install.sh rollback --restore-db
  • SQLite mailbox store contracted (objects or index): install.sh rollback aborts 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 with hermex-admin backup-mail prior to the Contract upgrade.
Always check mail queue and DRBD sync before failback

After an unplanned failover where Node A crashed and Node B took ownership:

  1. Repair Node A and verify all 14 binaries on Node A match Node B (/opt/hermex/current build ID).
  2. Confirm block storage replication is UpToDate on both nodes (for DRBD: sudo drbdadm status) so zero mailbox writes are dropped on return.
  3. Configure non-preemptive Pacemaker resource-stickiness on 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"
}
Automatic one-time migration and multi-node delivery
  • Legacy upgrade migration: On startup, hermex-mta checks {data_dir}/relay.sqlite3. If a legacy SQLite spool exists, hermex-mta copies queued items, TLS-RPT/DMARC counters, and cached MTA-STS policies into MariaDB in a single transaction, then renames relay.sqlite3 (plus -wal, -shm, .init-lock) to *.migrated.
  • Multi-node worker locking: Multiple hermex-mta instances connected to the same MariaDB relay database claim outbound recipients concurrently using SELECT ... FOR UPDATE SKIP LOCKED and atomic TryMarkStarted row transitions without duplicate deliveries or SQLite file locking.
  • Unified database backups: Because all relay_* tables reside in MariaDB, hermex-admin backup-db backs up queued messages and reporting state alongside directory and audit data. If you use a separate relay_database_dsn database, include that target schema in your mariadb-dump / cluster snapshot schedule.