03 · Concurrency
Status: Implemented (rules T6, execution T7, runs and sharding T13) · Owner: Platform ·
Code: engine/crates/flux-core/src/validate.rs (partition, sharding)
Three levels
Section titled “Three levels”
flowchart TB
subgraph run[One run]
direction LR
subgraph s0[shard 0 · pod]
p00[partition 0] --- p01[partition 1] --- p0n[partition n]
end
subgraph s1[shard 1 · pod]
p10[partition 0] --- p11[partition 1] --- p1n[partition n]
end
end
s0 & s1 --> commit[(one DuckLake commit)]
| Level | Configured by | What it does |
|---|---|---|
| Pod | compute profile | DataFusion runs each operator on target_partitions = CPUs threads, streaming batches |
| Node | partition on a node, or a repartition node |
Controls how rows are distributed before that node: by key (hash), by ranges, evenly, or all together |
| Run | compute.shards + shard_key |
Runs K pods (Indexed Job). Shard i gets the rows where hash(shard_key) % K == i |
Most pipelines need nothing: the engine picks partitioning automatically (hash on group/join keys). Set it explicitly when you know the data, e.g. a skewed key, or a downstream consumer that benefits from bucketed output.
Per-node partitioning
Section titled “Per-node partitioning”"partition": { "mode": "hash", "fields": ["customer_id"], "buckets": 16 }"partition": { "mode": "range", "field": "order_date", "boundaries": ["2026-04-01", "2026-07-01"] }"partition": { "mode": "round_robin", "buckets": 8 }"partition": { "mode": "single" }buckets is 1–1024. A bucket is a unit of parallel work. More buckets than CPUs is fine
and helps with skew; the engine schedules them over the pod’s threads.
Compatibility rules (validated)
Section titled “Compatibility rules (validated)”Operators that depend on keys must see every row of a key in one partition:
| Node | Allowed partitioning |
|---|---|
| Aggregate | hash on a subset of group_by, range on a group-by column, single. Not round-robin |
| Dedupe (keys) | hash on a subset of keys, range on a key, single |
| Dedupe (whole row) | anything except round-robin |
| Window | hash on a subset of partition_by; single when there’s no partition_by |
| Join / Lookup | hash on a subset of the left join keys (the engine co-partitions the right side) |
| Sort | single, or range on the first sort column |
| Limit | single (other modes give a per-partition limit; warning) |
| Row-level nodes (map, calculate, filter, route, validate, union) | anything |
Hash on a subset of the keys is valid: equal full keys always have equal subsets. Choosing fewer fields gives coarser buckets and can help when one combination is rare.
Sharded runs
Section titled “Sharded runs”"compute": { "profile": "medium", "shards": 8, "shard_key": "customer_id" }- The orchestrator runs 8 runner processes (an Indexed Job with 8 pods in the cluster;
each pod’s
JOB_COMPLETION_INDEXis its shard). - Every shard reads each source and keeps the rows whose
flux_shard(shard_key, 8)equals its index (a stable FNV-1a hash of the value’s text). The hash is applied in the engine after the read, for every connector type; it isn’t pushed down to databases yet, so each shard reads the full source (see Open questions). Sources marked"broadcast": trueskip the filter. Use that for small reference data (customers, FX rates) feeding lookups and joins. - Every shard writes its own Parquet files to staging. Only when every shard has staged does the orchestrator start one commit process. One failed shard fails the run, and the staged files are discarded.
- The commit registers each dataset target’s files in DuckLake. Each dataset commit is atomic and idempotent (tagged with the run id), so a retried commit finishes the job without duplicating data. A run with several dataset targets commits them one after another, not in one transaction.
Sharding rules (validated)
Section titled “Sharding rules (validated)”The validator follows which nodes carry split versus broadcast rows:
- Aggregate
group_by, Dedupekeys, and Windowpartition_byon split data must include the shard key. Otherwise each shard would produce partial results (shard.key). - A Join where both inputs are split must join on
shard_key = shard_key. A split right side with a broadcast left side is refused (shard.join). - A Lookup whose lookup input is split must match on the shard key, or the lookup source
must be broadcast (
shard.lookup). - A Union can’t mix split and broadcast inputs, because the broadcast rows would be
duplicated (
shard.union). - Targets must receive split data (
shard.target). - Sort and Limit apply per shard (warning
shard.order).
POST /api/pipelines/{key}/runs queues a run of the active version (or an explicit
version that passes the activation checks). The orchestrator in the API process moves it
through:
queued → running (all shards stage in parallel) → committing (one process) → succeeded └─ a shard fails / cancel / timeout → abort staged files → failed | cancelled- Compute.
compute.profilesets CPU and memory per shard:tiny0.5 CPU / 1 GiB,small1 / 2,medium2 / 4,large4 / 8,xlarge8 / 16, orcustomwithcompute.cpuin steps of 0.5 (andmemory_gi, default 2 GiB per CPU). Admins can override or add sizes ascompute-profileconfig items. The engine gets one partition per whole CPU and a memory pool of 80 % of the shard’s memory; Kubernetes requests and limits match the profile. - Concurrency. At most
FLUX_MAX_CONCURRENT_RUNSruns at once, and one run per pipeline at a time: the next run of the same pipeline waits in the queue, so two runs never commit the same datasets concurrently. Inside a run, concurrency comes from shards, partitions and extract splits (above). - Manifest. Each runner gets a manifest with the pipeline version, the decrypted connections it references, connector catalog pins, watermarks, and lake settings. It goes over stdin (local) or a per-run Secret mounted read-only (Kubernetes, deleted when the phase ends); it’s never stored or logged.
- Results. Each runner prints one
FLUX-RESULT {json}line and exits 0 (done), 1 (pipeline failure, naming the node and field) or 2 (system failure). The orchestrator reads it from stdout or the pod log; a process that dies without it is a system failure with the log tail attached. No retries happen inside Kubernetes (backoffLimit: 0): failures are loud and final. - Timeouts and cancel.
compute.timeout_s(default 1 hour, at most 24) bounds each phase (activeDeadlineSecondsin Kubernetes). Cancelling a queued or running run kills its processes (deletes its Job) and aborts staged files. A committing run can’t be cancelled. - Watermarks. Incremental extracts read rows after the last committed watermark. Shards report the maximum they read; the control plane stores it only after the commit succeeds, so a failed run is simply re-read next time.
- Finalize. After the commit, the same process lets connectors act on what the shards consumed (moving processed drop files). A failure there leaves the run succeeded with a warning, because the data is committed.
- Restarts. The orchestrator runs in the API (one replica). When it starts, runs left
runningorcommittingare marked failed and their staged files aborted. - Events. Runners publish shard status, per-node row counts and progress every 2 s (design 08); the orchestrator publishes run status. The run page follows them live.
Before activation, a pipeline must also reference only connections that exist with an active version, and connection targets must be types that can be written to.
Tested: runner binary with two shards staging and one commit, idempotent re-commit, node errors, abort (Rust); and through the API with the local backend: sharded runs, watermarks advancing only after commit, runtime failures naming the node, cancel of running and queued runs, one run per pipeline (Python). The Kubernetes backend is tested by the Job and Secret it generates; running it against the cluster is part of T19.
Choosing settings
Section titled “Choosing settings”| Situation | Suggestion |
|---|---|
| Up to a few million rows | Default profile, no shards, no explicit partitioning |
| CPU-heavy formulas | Bigger profile (more CPUs = more partitions) |
| Aggregating by a high-cardinality key | Hash on that key, buckets 2–4× CPUs |
| One customer has 50% of the rows | Hash on (customer, month) instead of customer |
| Source read is the bottleneck | split on the extract (key_range or native) |
| More data than one pod handles in time | Shards on the main entity key, broadcast reference data |
Open questions
Section titled “Open questions”- Push the shard filter down to SQL sources so each shard reads only its share.
- Reattach to Kubernetes Jobs after an API restart instead of failing the runs.
- Skew detection: report per-bucket row counts in run stats and suggest better keys.
- Adaptive shard count from the previous run’s volume.