07 · Dataset serving & OLTP
Status: Implemented (read path T15, write path T16) · Owner: Platform
flux-dataset serves the datasets pipelines write, straight from the same Parquet files the lake holds. There’s no second copy and no load step: when a run commits, the new snapshot is readable. Reads are the main use; the optional write path (WAL + memtable + merge-on-read + flush) is opt-in per dataset.
Routing and auth
Section titled “Routing and auth”On flux.nasterra.com, ingress sends /api/datasets to flux-dataset directly, not
through the Python API. That saves a hop on every read.
- flux-dataset verifies the control plane’s session JWT itself (HS256, shared
FLUX_SECRET_KEY, issuerflux.nasterra.com,expchecked). It takes eitherAuthorization: Bearer …or theflux_sessioncookie, so the app and scripts both work. - Any signed-in role (viewer and up) can read. Unknown roles are rejected.
- API keys work too, limited to their datasets when scoped. Revoked keys, disabled users and old sessions are refused using a revocation list from the control plane (design 11), refreshed in the background.
- No database or API call is made per request to authorise a read.
Endpoints
Section titled “Endpoints”| Endpoint | Purpose |
|---|---|
GET /api/datasets |
Datasets in the current snapshot |
GET /api/datasets/{name}?snapshot= |
Schema, key, file count, snapshot |
GET /api/datasets/{name}/get?<key>=<v>&columns=&snapshot= |
Point lookup by key |
GET /api/datasets/{name}/range?column=&from=&to=&limit= |
Key range [from, to), in key order |
GET /api/datasets/{name}/sample?limit= |
First rows |
POST /api/datasets/query {sql, limit} |
Read-only SQL |
POST /api/datasets/{name}/rows {put, delete} |
Write rows (write path) |
POST /api/datasets/{name}/flush |
Fold pending writes into a snapshot now |
GET / PUT /api/datasets/{name}/writes |
Write policy and status (PUT: admin) |
GET /healthz |
Liveness |
- Every read response carries
snapshotand astatsblock (files and row groups pruned, bloom rejections, pages read, rows decoded, server micros), plus aserver-timingheader, so latency is explainable per request. snapshot=pins a read to an older snapshot (time travel); otherwise the latest.- Request values are cast to the column type (
?id=42against anInt64key). - Errors: 401 no/invalid token, 404 unknown dataset, 422 bad input, 409 point/range on a
dataset with delete files (use
/query), 413 SQL over the size limit, 504 timeout. - Row limits default to 100 (sample, range) and 1,000 (query), capped at 10,000. Query
responses say
truncated: truewhen the cap cut the result.
How a point get works
Section titled “How a point get works”The runner writes Parquet tuned for this (design 06): sorted
by key, 65,536-row row groups, 4,096-row pages, page index, bloom filters on key
columns, ZSTD. The key is recorded as Parquet sorting_columns, and that’s where
flux-dataset reads it back from.
Per data file in the snapshot:
- Row-group statistics — skip row groups whose key min/max can’t hold the value.
- Bloom filter — skip row groups whose filter says “definitely not here”.
- Page index — inside surviving row groups, select only pages whose min/max cover
the value (a
RowSelection). - Decode just those pages for the requested columns.
- Exact filter on the decoded rows.
Range reads use the same row-group and page pruning with >= from and < to, then
merge results across files in key order and stop at limit.
Caches
Section titled “Caches”- Footers (with page indexes) per file, weighted by memory size, in a moka cache. Data files are immutable, so entries never go stale.
- Bloom filters per (file, row group, column), also immutable.
- File list per dataset (the snapshot view). Cached for a staleness window
(
FLUX_DATASET_STALENESS_MS, default 2,000 ms) and dropped early whenflux.dataset.<name>.committedarrives on NATS. In practice a new snapshot is visible within milliseconds of the commit; the window bounds staleness if NATS is down.
FLUX_DATASET_CACHE_MB sizes the footer and bloom caches together. A warm point get is
a few small ranged reads against object storage and no catalog round trip.
POST /api/datasets/query runs DataFusion over the lake catalog with the default
catalog flux.main, so select * from customers works.
- Read-only:
SQLOptionsrefuses DDL, DML and statements (SET, etc.). - Per-query memory limit (
FLUX_DATASET_QUERY_MEMORY_MB) and timeout (FLUX_DATASET_QUERY_TIMEOUT_S); SQL text is capped at 100,000 characters and request bodies at 256 KB. - For big extracts use a pipeline with a file target, not this endpoint.
Measured latency
Section titled “Measured latency”From engine/crates/flux-dataset/tests/serve.rs (200,000 rows over 2 shard files,
local files, release build, warm caches):
| p50 | p99 | |
|---|---|---|
| Point get, server time | 1.1 ms | 1.5 ms |
| Point get, HTTP round trip | 1.3 ms | 1.8 ms |
The test also checks pruning (one row group and at most one page decoded, bloom
rejections counted), out-of-range lookups reading nothing, range order across files,
type casting, auth failures (missing and forged tokens), 404s and read-only SQL. A
second commit then checks that the cached view keeps serving the old snapshot until the
NATS commit event arrives, and that the old snapshot stays readable with snapshot=.
It runs in CI with the rest of the engine tests (Postgres and NATS required).
Configuration
Section titled “Configuration”| Variable | Default | |
|---|---|---|
FLUX_DATASET_LISTEN |
0.0.0.0:8130 |
|
FLUX_SECRET_KEY |
— | Same as the API; at least 32 chars |
FLUX_LAKE_CATALOG_URL, FLUX_LAKE_DATA_PATH, FLUX_S3_* |
— | Same lake as the runner |
FLUX_NATS_URL |
unset | Commit invalidation; without it only the window applies |
FLUX_DATASET_STALENESS_MS |
2000 | |
FLUX_DATASET_CACHE_MB |
512 | |
FLUX_DATASET_QUERY_MEMORY_MB |
1024 | |
FLUX_DATASET_QUERY_TIMEOUT_S |
30 |
flux-dataset is stateless; run as many replicas as needed behind the Service.
Write path
Section titled “Write path”Read-only is the default and the main use. An admin can make a dataset writable so an application can put and delete rows by key. Pipelines keep writing the dataset as before.
flowchart LR app[Application] -- "POST /rows" --> ds1[flux-dataset replica] ds1 -- "row lock, seq" --> wal[(flux_wal<br/>Postgres)] ds1 -. "flux.serving.‹name›.written" .-> ds2[other replicas] wal -- tail --> ds1 wal -- tail --> ds2 ds1 -- "flush (advisory lock)" --> lake[(Parquet snapshot)] lake --> ds1 lake --> ds2
Turning it on
Section titled “Turning it on”PUT /api/datasets/{name}/writes (admin):
{"enabled": true, "writer_role": "editor", "flush_rows": 50000, "flush_interval_s": 300}- The dataset needs a key (the pipeline target’s
key, recorded as the Parquet sort order). Writes address rows by that key. writer_roleiseditor(default) oradmin; viewers can never write.- Switching writes off is refused while writes are pending; flush first (or discard
them with
"discard_pending": true). - The policy lives in
flux_write_policy, next to the lake catalog. Changes record who made them (updated_by,updated_at).
Writing
Section titled “Writing”POST /api/datasets/customers/rows{"put": [{"id": 42, "name": "Acme", "tier": "gold"}], "delete": [{"id": 7}]}→ {"seq": 1031, "put": 1, "deleted": 1, "pending": 12}- put is an upsert of a full row: every non-null column must be given; unknown columns are rejected. Values are checked against the dataset’s types.
- delete gives the key columns only.
- Up to 1,000 operations per request, applied atomically. The same key twice in one request is rejected (order would be ambiguous).
- Key columns can’t be null.
- When a request returns, its operations are durable (committed to Postgres).
Single writer per dataset. Each request locks the dataset’s policy row, assigns the next sequence numbers and commits. So WAL order is commit order, there are no gaps a reader could skip over, and the last write to a key wins. Any replica can take writes; they serialize in Postgres. Throughput per dataset is bounded by that lock (one Postgres transaction per request); batch operations into one request for bulk loads.
Backpressure. When a dataset has more than FLUX_DATASET_MAX_PENDING (default
200,000) unflushed operations, writes get 429 until a flush catches up.
Reading your writes
Section titled “Reading your writes”Each replica keeps a memtable per writable dataset: the latest state of every key
written since the last flush (a row, or a tombstone). It’s built by tailing flux_wal
in sequence order and is applied to every read of the current snapshot:
- Point get: Parquet lookup as usual, rows whose key is in the memtable are dropped, then the memtable’s row for the key (if a put) is added.
- Range: the Parquet range reads
limit + pending keysrows so hidden rows can’t leave the page short, then merges memtable puts in range, sorts, and cuts tolimit. - Sample and SQL: the dataset’s table becomes a view,
snapshot ANTI JOIN pending keys UNION ALL pending puts, so every query sees the same data as point reads. - Pinned snapshots (
snapshot=) are time travel and show committed data only.
Freshness:
| Where you read | Sees a write |
|---|---|
| The replica that took it | Immediately |
Any replica, with after=<seq> |
Immediately (the replica tails the WAL up to seq first; 422 if seq doesn’t exist) |
Any replica, without after |
After the flux.serving.<name>.written hint (milliseconds), at most the staleness window |
Point and range responses on a writable dataset include write_seq, the WAL position
the read reflects. SQL takes "after": {"customers": 1031} in the body.
Pending writes are folded into the Parquet files when either threshold passes:
flush_rows pending operations or the oldest pending one is flush_interval_s old.
Every replica checks every FLUX_DATASET_FLUSH_CHECK_S (default 5 s); a per-dataset
advisory lock makes sure only one flushes. POST /flush (writer role) flushes now.
A flush:
- Records its intent (
flush_run,flush_seq) on the policy. - Reads the merged view up to sequence S, sorts it by key and writes new files with the same layout as pipeline output (bloom filters, page index, small pages).
- Commits them as a replace only if the dataset’s files are still the ones it read
(
Lake::commit_checked; commits of a dataset are serialized by an advisory lock, so the check and the commit can’t interleave with a pipeline run). If a pipeline committed meanwhile, the flush is discarded and retried on the next check. - Marks S flushed and deletes WAL rows up to S in one transaction, then publishes
flux.dataset.<name>.committedlike a pipeline commit (so triggers and caches react).
If a flush dies after step 3, the next one finds the commit by its run id and finishes step 4. Replicas drop memtable entries up to S once they’re reading a snapshot at or after the flush, so a flush is invisible to readers apart from the new snapshot number.
The flush rewrites the dataset, which is also its compaction: files stay sorted with
no delete files, so point reads keep their pruning. The cost is proportional to the
dataset’s size, not to the number of writes; for large datasets with steady writes,
raise flush_rows / flush_interval_s so rewrites are infrequent (pending writes cost
reads little, see below).
Pipelines and writes together
Section titled “Pipelines and writes together”- A pipeline run writing a writable dataset commits as usual. Pending writes stay pending and still apply on top of the new snapshot, then the next flush folds them in. In other words, API writes since the last flush win over the pipeline’s rows for the same keys. Rows the pipeline adds or removes for other keys are unaffected.
- If a pipeline changes the dataset’s schema, pending writes are re-read with the new
schema; if they don’t fit, reads and flushes fail with 409. Either restore the column
or have an admin discard the pending writes (
"discard_pending": trueon the policy PUT, logged with who did it). Flushing before changing a writable dataset’s schema avoids this. - Deleting every row through the API and flushing is refused (the same guard that stops a failed run from emptying a dataset).
Measured
Section titled “Measured”Same test as above (tests/serve.rs, write_path), release build, local Postgres:
| p50 | p99 | |
|---|---|---|
| Write, one row, HTTP round trip | 0.38 ms | 0.72 ms |
| Point get with 200 pending writes, HTTP round trip | 1.2 ms | 1.7 ms |
Flushing the 200,000-row test dataset takes well under a second locally. The test covers
policy and role checks, validation, merge-on-read for point, range and SQL, read-your-writes
on a second replica with after=, flush, time travel to the pre-flush snapshot, and the
disable guard; tests/lake.rs covers the checked commit.
Write path configuration
Section titled “Write path configuration”| Variable | Default | |
|---|---|---|
FLUX_DATASET_MAX_PENDING |
200000 | Unflushed operations per dataset before 429 |
FLUX_DATASET_FLUSH_CHECK_S |
5 | How often to look for datasets due a flush; 0 turns flushing off on that replica |
FLUX_API_URL |
unset | Control plane, for the revocation list; without it API keys are refused |
FLUX_DATASET_REVOCATION_REFRESH_S |
15 | How often the list is refreshed |
The WAL and policy tables are created in the lake catalog database on startup.
Decided
Section titled “Decided”- Read path: file pruning → bloom filter → page index → page-range read; footer and bloom caches.
- Local JWT verification, no proxy through the control plane.
- Write path is opt-in per dataset and serialized per dataset by a Postgres row lock;
read-your-writes on the writing replica, and on any replica with
after=. - WAL in Postgres rather than on replica disks: replicas stay stateless and every replica can build the memtable. Rejected: a local WAL with a single writer pod (needs a volume and failover) and JetStream as the WAL (a second source of truth to reconcile).
- Flush is a sorted rewrite with optimistic concurrency against pipeline commits.
Limits and open questions
Section titled “Limits and open questions”- Point and range reads refuse datasets with DuckLake delete files;
/queryhandles them. (Flux never writes delete files.) - Flush cost grows with dataset size. A delta level (flush pending writes to small sorted files, compact into the base less often) is the next step if that matters.
- Partial updates (patch a few columns) aren’t supported; put the full row.
See the architecture overview.