Architecture¶
The rules that keep pqbench's commands decoupled, third-party code isolated,
and the dependency tree small. AGENTS.md covers naming and
tidyings; this page covers structure.
Layers¶
crates/pqbench-model-v1— the wire model: the resources, their name grammar (v1::name), and their JSON.serdeonly; it reads no file and speaks to no service, so it compiles in under a second.pqbenchre-exports it aspqbench::v1.crates/pqbench-parquet— the local work: a footer's byte masses, page compression, and the lint rules. No network, no object store, no Delta, no Iceberg, so a change to a lint rule rebuilds one small crate.pqbenchre-exports its modules at the same paths.crates/pqbench— the library's remote half: command implementations that read object storage, Delta, Iceberg, or Unity, their domain types, and the network third-party adapters.crates/pqbench-cli— a thin wrapper: argument parsing, the JSON documents, and output formatting. No command logic.pqbench proxyis the one command that serves instead of walking: a local caching, pacing reverse proxy in front of the configured endpoint.crates/pqbench-driver— a stateless runner (pqbench-driver) that writes two plain bash scripts into a store and runs them with bounded concurrency:walk.shlists partitions, andprocess-partition.shprocesses one. The version directories are the state; the CLI reads each partition's newest version throughPQB_DRIVER_STORE, andpqbench prunedeletes the older ones. A run that reaches a catalog starts onepqbench proxyfrom the same pinned image and points both scripts at it.
Commands¶
The walk's resource commands (metastore, catalog, schema, table,
file) are folders — one per resource, with a subcommand folder per verb. The
credentials folder is the vending implementation a storage level calls, not a
walk stage. The measurement commands (bytemass, compression, lz) keep an
api.rs and split the implementation across named modules; skill is a
single module, and summarize is a small folder;
the CLI renders tables and one file's HTML treemap, and summarize folds
partitions. The shared support (report, stats, time, config,
dialect, http, capability, codecs) sits at the crate root. The
CLI adds the credential resolution (credentials.rs) and the proxy
(proxy.rs); the library opens no socket and starts no thread, and a
Workspace is a plain HTTP client. Every command is stateless: it asks the
catalog for a table's vended lease when it reads that table, and pqbench
proxy is the one place that caches.
crates/pqbench/src/
<resource>/
<verb>/{api.rs, impl.rs, mod.rs}
bytemass/{api.rs, collection.rs, remote.rs}
third_party/
<crate>/{api.rs, impl.rs, mod.rs}
<crate>/impl/<module>.rs
crates/pqbench-parquet/src/
lint/, compression/, codecs.rs
footer.rs, pages.rs, bytemass/
api.rs— the command's public entry point and the few helpers a caller needs. It is the whole public surface.impl.rs— the internals, private and free to change.
Rules:
- Every command stands on its own and is architected from above: its design starts at the public surface and shapes the implementation beneath it, never by lifting structure out of another command.
- A command is self-contained. It never imports another command and shares no implementation with one; repetition between commands is the accepted price of decoupling.
- A command folder never grows a utility module for other commands.
- Command code is always compiled. A missing capability is a runtime error, not a reason to remove code, so command code has no dead-code allowances.
Resource hierarchy¶
Commands mirror the resource hierarchy of the data model — metastore, catalog,
schema, table, file. Each level's list module lists that level's resources
(the parent rides the argument, or parent refs on standard input); get reads
one resource.
The proxy¶
One process's rate limit is not a catalog's: Unity caps REST calls per
endpoint, and a pipeline of stages — or a fan-out of pqbench-driver
workers — is many processes. pqbench proxy is the one place that turns those
processes into one client: it serves the configured endpoint on a local port,
caches the 200 answers it may cache, and spaces the rest through one pacer.
It is a reverse proxy and nothing else. The cache key is the method, the path,
the Authorization header, and the body, so one caller's bearer never answers
another's request; concurrent misses for one key coalesce onto one upstream
call. The core stays a plain HTTP client with no rate limiter and no
cross-process state, which is what keeps it testable and dependency-light; a
caller that wants pacing or sharing points PQB_ENDPOINT at the proxy's URL.
The driver's scripts¶
pqbench-driver run writes {store}/walk.sh and
{store}/process-partition.sh, runs the walk, and runs the processor once per
partition with --jobs at a time. There is no socket, map, state machine,
retry, or checkpoint: a version's _etag and _last_processed_time are the
state, and the script is the transition. The driver runs on one thread: it
starts child processes, polls them, and sleeps briefly between polls. A run is
append-only: an older version stays on disk, and pqbench prune is the one
command that deletes it.
flowchart TD
A[pqbench-driver run] --> B[store/walk.sh]
B --> C[partitions.ndjson.zst]
C --> D{_etag matches and<br/>_last_processed_time exists?}
D -- yes --> E[instant no-op]
D -- no --> F[store/process-partition.sh<br/>DIR PARTITION SAMPLE ETAG]
F --> G[DIR.stage.pid]
G --> H[get partition-price<br/>download / bytemass / lint]
H --> I[write _etag and _last_processed_time]
I --> J[atomic mv DIR.stage.pid to DIR]
J --> K[catalog/schema/table/partition/etag]
F -- fails --> L[ETAG.failed/partition.ndjson<br/>ETAG.failed/sample.ndjson]
L --> M[bash -x process-partition.sh ...]
M --> F
A walk that names an etag already done spawns nothing. A changed etag is a new
directory; the old one stays until pqbench prune deletes it past
retained-version-count. A failed partition keeps its inputs in
{dir}.failed/ and names the exact bash -x command that fixes it; running
that script by hand writes {dir} and removes {dir}.failed/, so the next
driver run is a no-op. A step that outlives step-timeout kills the script's
whole process group. Prune also removes a .failed directory once a newer
finished version superseded it, and keeps one that is newer than every
finished version for inspection.
Interfaces¶
- The public surface is the command's entry point, and the less surface the better.
- Inputs are plain values the caller has. Configuration, pagination, and dialect state belong to the implementation, never to the signature.
- No abstractions in the public surface: no traits, no generic helpers, no shared protocol layer. Simple and readable beats clever and reusable.
- Where two implementations serve the same operation they keep the same shape, so dispatch stays flat.
third_party¶
- One folder per third-party crate:
api.rsis the isolated surface;impl.rsand itsimpl/submodules are the only code that names the crate. Feature flags live only underimpl, enforced byscripts/check_isolation.sh. - Only
crates/pqbench— the network half — has such folders. The local Parquet crate depends onparquetand its codecs directly, with no feature flag to isolate. - An adapter wraps a third-party crate and nothing else: no domain types, no other modules of the crate.
- Protocol code we speak ourselves is not third-party code, even when it runs over a third-party transport.
- The adapter mirrors only the minimal part of the dependency's interface that is needed.
Features¶
- A command never adds a feature. Features map to third-party dependencies; a command reuses the feature that gates the dependency it needs.
- Code that does not name a third-party crate never sees a feature flag.
- CI builds one test leg per feature, and none for features with no distinct compilation behavior.
Serialization¶
- The documents commands exchange are the CLI's communication language: the
resource types live in
pqbench::v1, and the CLI renders them. - Library commands take and return those resources; presentation stays in the CLI.
- The CLI parses an input document, calls one command function, and formats the result.
Why¶
- Self-contained commands change, test, and ship independently.
- Duplication over coupling: a copied loop is cheaper than a shared module two commands must change together.
- A minimal public surface keeps signatures readable and internals free.
- One feature per dependency keeps the default build and the CI matrix small.
- Serialization in the CLI keeps the library independent of a presentation format.