Shared Databases & Auto-Replication
Deploy databases on Flux with persistent storage — MongoDB, PostgreSQL, Redis replication strategies and backup patterns.
Since October 2026 you no longer have to solve this from scratch. Two open-source cluster operators deploy on Flux today, as components of your own app. Managed databases — where you pick PostgreSQL or MongoDB as a step in the deployment flow and Flux runs the cluster for you — are on the roadmap, not yet shipped. The building blocks below are.
flux-pg-cluster — PostgreSQL with real high availability
flux-pg-cluster turns three or more Flux instances into a standard Patroni-managed PostgreSQL cluster, with etcd electing the primary — the same high-availability stack used across the industry. What Flux adds is the glue a decentralized network needs:
- •Automatic discovery — the cluster finds its own members through the FluxOS location API, wherever the network happened to place them.
- •A primary-routing proxy — your app connects to one port,
5433, and every write reaches the current primary across failovers, with no change to your connection string. The proxy re-checks each node every 3 seconds. - •Read replicas on port 5432 — available directly when you want to spread read traffic.
- •Durability you choose — replication is asynchronous by default for speed; switch on synchronous mode and every commit waits for a replica to confirm, so a failover loses nothing.
- •Careful recovery — after a total outage the cluster agrees which node holds the authoritative data before anything restarts, and never wipes data unless you explicitly allow it.
A clustered MySQL and MariaDB operator exists on the same model. Both are open source: add the cluster image as a component of your app from cloud.runonflux.com and follow the README in each repository.
What FluxOS v9 changes
The v9 application specification adds the pieces a database has always wanted on this network: persistent storage with sized volumes, replicas with active-standby and active-active placement, and sync-before-start ordering for apps that need their data in place before they run. Graceful shutdown — draining and pre-stop hooks before a node stops an app — lets a database checkpoint cleanly whenever it moves.
Deploying databases on a decentralized network introduces unique challenges: each instance runs on a different node, data must stay consistent across instances, and node changes can happen at any time. Flux provides mechanisms for persistent storage and supports databases with built-in replication to handle these challenges.
The Decentralized Database Challenge
When you deploy a Flux app with 3 instances, each instance runs on a different node. Each node has its own local storage. Unlike centralized cloud providers where you can attach a shared network volume, Flux uses local persistent volumes per instance. This means:
- •Each instance has its own separate data copy
- •Data written on Instance A is not automatically visible to Instance B
- •If a node goes offline and the instance migrates, local data on the old node is lost
- •Database replication must be handled at the application level, not the infrastructure level
Using containerData for Persistence
The containerData field in your Flux app spec mounts a persistent volume at the specified path. For databases, this is where data files are stored. Data persists across container restarts on the same node.
Flux provides official database images optimized for decentralized deployments: runonflux/shared-db (426K+ pulls), runonflux/flux-pg-cluster (PostgreSQL), and runonflux/flux-mongodb-cluster (MongoDB). These images include built-in replication and are recommended over generic database images.
MongoDB component with persistent storage
{
"name": "mongodb",
"repotag": "mongo:7",
"ports": [],
"containerPorts": [27017],
"domains": [],
"environmentParameters": [
"MONGO_INITDB_ROOT_USERNAME=admin",
"MONGO_INITDB_ROOT_PASSWORD=secretpassword"
],
"commands": [],
"containerData": "/data/db",
"cpu": 1,
"ram": 1024,
"hdd": 10
}Replication Strategies
- 1
MongoDB Replica Set
MongoDB natively supports replica sets for automatic data synchronization across instances. Configure the MONGODB_REPLICA_SET environment variable and use a replica set connection string. MongoDB handles election of primary/secondary nodes and data sync.
- 2
PostgreSQL with Streaming Replication
PostgreSQL supports primary-standby replication with Write-Ahead Log (WAL) streaming. The primary instance handles writes; standbys replicate asynchronously. Use environment variables to configure replication settings.
- 3
Redis with Sentinel
Redis Sentinel provides automatic failover for Redis instances. Configure one instance as master with others as replicas. Sentinel monitors and promotes replicas on master failure.
- 4
Application-level sync
For simpler setups, use one instance as the primary (handling all writes) and implement read-only replicas that sync via application logic or periodic data dumps.
Primary/Standby Pattern
The most common pattern on Flux is primary/standby: one instance is designated as the primary (handling all writes), while other instances run in standby mode for redundancy. When the primary goes down, a standby can be promoted. This pattern works for databases, game servers (like the Minecraft example), and any stateful application.
Never expose database ports to the public internet. Use empty ports arrays [] in your spec and access the database only via internal DNS from your application components. Always set strong authentication credentials.
Backup Strategies
- •Scheduled dumps: Use cron jobs inside the container to run mongodump, pg_dump, or equivalent tools on a schedule
- •External backup: Push backup files to an external S3-compatible storage service
- •Application-level export: Build export functionality into your application that can serialize data to an external service
- •Volume snapshots: If your data fits in containerData, periodic snapshots provide point-in-time recovery
Sources & Further Reading
What to read next, and why
Read the Flux app cost calculator for what a given specification costs per term.
Read troubleshooting a deployed app for logs, restarts, and instances that will not come up.
Read what Flux actually is for the network’s own numbers rather than the ones on the brochure.
Read Flux node tiers for the 2/28, 7/28 and 18/28 split of every block, and the hardware each tier really runs.
Read Flux node collateral for 1,000 / 12,500 / 40,000 FLUX, locked as one unspent output, with no unbonding period.
Other articles in FluxCloud Advanced Deployment
Docker Prerequisites & Best Practices for Flux
Install Docker, create optimized Dockerfiles, multi-stage builds, image registries, containerData volumes, and common mistakes.
Compose v4: Multi-Component Applications
Deploy up to 10 components in one Flux application — internal DNS, inter-component communication, ports and environment variables.
Enterprise Deployments (Private Images, Secrets & Static IP)
Enterprise mode features — private Docker registries, secrets management, static IPs, node targeting, and pricing.
Deploy with Git (CI/CD & Auto-Deploy)
Auto-deploy from GitHub/GitLab/Bitbucket — webhooks, polling, zero-downtime updates, rollback, and CI/CD integration.
Flux-Orbit: Zero-Config Universal Deployment
Deploy any project without a Dockerfile — auto-detection for Node.js, Python, Rust, Go, Java, Bun, Ruby, and static sites.
Tiered Resources, Spec Builder & Cost Calculator
Basic/Super/BAMF resource tiers, Visual Spec Builder, Cost Calculator, pricing model, and cloud cost comparison.
App Troubleshooting & Post-Deployment Management
Diagnose deployment failures, domain issues, DB connection problems — plus updating specs, monitoring, and app lifecycle management.