Scale-out and elasticity
An embedded engine is fast and bounded by one machine. The scale-out layer is what makes it a distributed database, and it is the part of FluxDB that is genuinely ours rather than inherited.
The shape is simple to state and detailed to implement: a shard is a full engine, shards are placed across cells by topology, and a query planner decides which shards to touch and how much work to push into each.
Sharding
| Strategy | When it fits |
|---|---|
| Hash | Even distribution when there is no natural range |
| Range | Ordered data where range scans should stay local |
| Composite | A resolver combining more than one key dimension |
| Directory | An explicit lookup, when placement is a decision rather than a function of the key |
Around the strategies sits a full shard lifecycle: split, merge, migration, recovery, and a file manager and data mover that physically relocate a shard's contents.
Placement is topology-aware
Shards are not scattered. A placement engine resolves where a shard and its replicas live against the real region, zone, rack and cell topology, with failure-domain awareness, so a replica set can be required to span things that do not fail together.
Placement consults the same topology that data residency is pinned on, which is why a residency constraint is a constraint on placement rather than a filter applied afterward, and why a required residency constraint no live cell can satisfy refuses rather than quietly degrading.
Query distribution
Figure: a query is routed by workload class and shard resolution, planned against a cost model with predicates and projections pushed down, executed in parallel as per-shard fragments, and gathered. Cross-cell fragment results are signature-verified before being merged.
Table equivalent
| Stage | What happens |
|---|---|
| Route | Workload-classified between the transactional and analytical engines, and resolved to the shards that hold the data |
| Plan | A cost model drives the plan, with predicate and projection pushdown so a shard returns the smallest useful result rather than raw rows |
| Execute | A parallel executor runs per-shard fragments concurrently |
| Gather | Results merge, and cross-cell fragments are signature-verified rather than trusted because they arrived |
Around that core: a join planner and cross-shard traversal for work that spans shards, recursive CTE coordination, a scatter-gather federation path, a result cache, a buffer pool, and materialized views with incremental refresh.
It gets faster without you tuning it
Three components close the loop between what the workload does and how it is executed:
- An adaptive optimizer and query optimizer that adjust plans against observed behavior.
- An auto index manager and an index advisor, so indexing is recommended and maintained rather than guessed at during an incident.
- Cache warming, so a cold shard is not cold on first use.
Transactions across shards and cells
A multi-shard write is a two-phase commit with a coordinator on the initiating cell and participants on the others.
- Begin. The coordinator assigns a transaction id and identifies participants.
- Prepare. Each participant writes a prepare record, acquires locks, validates, and votes prepared or abort.
- Commit or abort. All-or-nothing on the vote.
- Cleanup. Final state recorded, resources released.
Crash recovery is specified rather than hoped for. A coordinator that dies after prepare but before commit reads its own log on restart and aborts stale preparing transactions, and a participant that dies after voting prepared resolves against the coordinator's recorded outcome.
For long-running work that cannot hold locks, a saga orchestrator provides the compensating-transaction path instead.
Alongside both: a lock manager, optimistic locking, a transaction manager, and consistency levels so a caller can choose its guarantee rather than taking one setting for the whole system.
Resiliency and failure handling
A distributed engine is defined less by its happy path than by what it does when a cell is gone, isolated, or lying. FluxDB's SQL plane has a specified answer at each of those points rather than an emergent one.
The CAP posture
Under a partition, a system must choose. The SQL write path chooses consistency. That choice is not a slogan; it is three concrete behaviors:
- A multi-shard write commits through two-phase commit, and a synchronous protection policy holds a write until a quorum of replicas acknowledges, so an acknowledged write is on a majority rather than one cell.
- A partitioned primary is fenced before its stale writes can be served (below), rather than allowed to diverge.
- Automatic failover refuses a replica whose freshness it cannot prove, so availability is never bought with acknowledged-write loss.
Availability under partition is then an opt-in on the read side, through the consistency levels: a read that can tolerate staleness asks for it explicitly and is served from a replica, while the default write path stays consistent.
The consistency levels
The four levels are a per-read choice of how much staleness is acceptable in exchange for reading a replica instead of the primary:
| Level | What it reads | Guarantee |
|---|---|---|
| Strong | The primary, always | No staleness; every read sees the latest committed write |
| Bounded | The least-stale replica, if it is within the caller's staleness bound, else the primary | Reads are no older than the bound; a replica that drifts past it falls back to the primary |
| Session | A replica at or beyond the versions this session has written, else the primary | Read-your-writes within a session, while still spreading reads to replicas |
| Eventual | Any replica, preferring the least stale | Lowest-latency reads, with staleness exposed rather than hidden |
Staleness is measured honestly: a replica's freshness clock advances only when it makes real forward progress, so a replica stuck behind the primary that keeps heartbeating does not look perpetually fresh, and a bounded read falls back to the primary rather than serving old data.
The failover sequence
Failover is a defined order of operations, each step of which refuses rather than guesses when it lacks the evidence to act safely:
- Detect. A failure detector tracks per-cell heartbeats and flags a cell that misses its timeout, with a cascade guard that caps how many new failures one pass may declare, so a detector pause does not manufacture a storm of false positives.
- Reconcile. The surviving cells rebuild the shard's primary-and-replica registry from converged placement, so the survivor can act on a shard whose placement row was written by the dead primary.
- Measure. Each candidate replica's true staleness is computed from converged watermarks, comparing the primary's last-known head against each standby's applied position. A replica whose watermark is missing or unverifiable is marked infinitely stale and refused, never treated as fresh.
- Promote. The best healthy candidate wins on highest version, then lowest lag, among cells that are still in the group. A candidate whose lag exceeds the bound is rejected so failover does not silently promote a badly stale replica. An operator can force a promotion when availability must win over currency, as an explicit override.
- Fence. Promotion bumps the split-brain epoch before it is reported successful, so the demoted primary's token is stale from that instant. A promotion that mutated state but failed to bump the fence is logged loudly rather than reported clean.
A recovered old primary does not reclaim its role automatically. It comes back as a standby, catches up from the current primary through WAL shipping, and failback is a deliberate, lag-gated operation rather than an automatic flip.
Partition and split-brain
The real test of a distributed store is a primary that is isolated but still running. FluxDB reuses the platform's epoch fence on the SQL shard: a promotion monotonically bumps the epoch, so any token held by a now-isolated old primary becomes stale, and a write validates its epoch before it is served. That is an explicit rejection layer on top of the quorum, which already prevents a partitioned primary's writes from reaching a durable acknowledgment. Two independent mechanisms, because split-brain is the failure mode where one is not enough.
The fence fails closed. When cross-process fencing is requested but the platform cannot provide the file locking it depends on, the fence refuses to run unlocked rather than silently dropping the split-brain guard; a single-process deployment that knowingly accepts no cross-process guard has to opt into the degraded mode explicitly.
The degraded modes are defined, not emergent
Rather than failing hard when a dependency is unavailable, the engine maps each failure scenario to a declared fallback, so behavior under pressure is a decision on record:
| Scenario | Defined behavior |
|---|---|
| Analytical engine unavailable | Route analytical queries to the transactional engine; error only if that is not possible |
| Object store unavailable | Continue transactional work; the flush retries with backoff |
| Shard primary down | Promote a replica; error if there is none |
| Quota exceeded | Reject writes while reads continue |
| Flush behind | Keep serving, and expose the staleness as a metric rather than hiding it |
A background pass auto-resolves a degradation once its underlying health check clears, so a degraded mode does not persist after the cause is fixed.
Elastic in and out
Scaling is predictive, not reactive. A scaler runs trend analysis over observed shard statistics to forecast when a threshold will be breached, and triggers split or merge preemptively rather than after the shard is already hot.
That matters because a split is a data movement operation. Starting one at the moment a shard becomes overloaded means moving data while it is under maximum pressure, which is the worst possible time. Forecasting the breach moves the work earlier, into headroom.
Supporting it:
- A rebalancer driven by observability feedback, including hot-shard detection and load distribution.
- Shard migration with a verifier and a finalizer, so a move is checked rather than assumed.
- Replica promotion and routing, so reads spread and a failed primary is replaced.
- A failure detector.
- A resource governor and quota enforcer, so elasticity has bounds.
- Graceful degradation, so the system has a defined behavior under pressure rather than an undefined one.
- Spill backends, so work that exceeds memory spills to disk rather than failing.
What this means for capacity
The scaling argument is architectural, and it is the reason the building-block choice is a strength rather than a compromise.
A shard is a full embedded engine running in-process against local storage. So per-shard capability is the capability of SQLite or DuckDB on your hardware, and both are independently benchmarked by people with no stake in this platform. The starting point is not a vendor claim; it is a number you can look up and then verify yourself.
Capacity is then a function of shard count and placement, not of one server's ceiling. A conventional deployment inherits its engine's single-node limit. Adding a shard here adds an entire execution core, and adding a cell adds its compute, its networking and its storage to the pool.
That is the whole argument in one line:
We did not pick engines that are fast enough. We picked engines that are already fast, and then removed the ceiling.
The placement engine, router and rebalancer are what make adding capacity an operation rather than a migration project, and pushdown is what keeps a scatter-gather from spending the gain on moving rows.
Characterize one shard on your hardware for your workload, which is an ordinary SQLite or DuckDB measurement with published third-party work already available. Multiply by the shard plan. Then subtract only the coordination you actually need: none for a single-shard query, and only the rows that survive pushdown for a fan-out.
That model tells you what a headline benchmark never does, which is what changes when you add hardware.
Related
- Storage and performance, where shards live and how they flush.
- Scale-out & distribution, the Data Platform view of the same plane.
- Deployment topology, the topology placement resolves against.
- Data residency, the constraint that can refuse a placement.