1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Offline collection-index disk comparison
This experiment compares the real Zlay zkv and RocksDB adapters on identical,
locally generated membership operations. It measures the collection index, not
PostgreSQL, replay files, container images, or the relay's total disk usage.
## Results
For identical two-million-membership contents, zkv retained **1.77 times as much
index disk** as RocksDB after ingestion and maintenance. This is a real storage
density gap, rather than an inference from differently aged production databases.
| Measurement | zkv | RocksDB |
|---|---:|---:|
| Settled after ingestion | 269.9 MiB | 152.5 MiB |
| Bytes per logical membership | 141.5 | 80.0 |
| Settled after duplicate pass | 269.9 MiB | 152.7 MiB |
| Settled after three churn cycles | 270.2 MiB | 153.5 MiB |
| Largest sampled temporary footprint | 553.3 MiB | 365.9 MiB |
Both engines passed complete forward scans and reverse-membership presence checks
for every generated DID after reopening.
The same 1,000-account cohort was deleted and restored three times. zkv's small
retained increase mostly plateaued after the first cycle. This does not establish
steady state under a larger or changing deletion cohort.
At the final checkpoint, zkv's SSTs occupied 283,281,190 bytes versus RocksDB's
159,216,515 bytes. RocksDB also retained about 1.7 MB of diagnostic logs from
repeated reopening. Therefore the density gap persists when diagnostic files
are excluded.

The first graph shows capacity consumed by genuinely new memberships. The second
holds final logical contents fixed while varying duplicate and deletion history.
The third distinguishes lifecycle writes from explicit settling, because physical
maintenance operations differ between engines. All byte totals include actual
filesystem accounting rather than just encoded input size.
| OS-accounted writes | zkv | RocksDB |
|---|---:|---:|
| Ingestion lifecycle | 1,699.6 MiB | 590.3 MiB |
| Duplicate pass | 0.012 MiB | 376.1 MiB |
| Churn lifecycle | 137.8 MiB | 38.0 MiB |
| Explicit settling across the run | 0.7 MiB | 1,245.3 MiB |
Lifecycle categories include reopening and associated verification, so background
maintenance during verification is counted. Ingestion includes ordinary automatic
maintenance; explicit settling is a separate category. These results show both
zkv's duplicate-elision benefit and its more expensive initial storage writes.
RocksDB's large explicit-settling total reflects this harness repeatedly requesting
full-range compaction. It is **not** a measurement of normal relay write amplification
and must not be used to claim a production write-I/O win for zkv.
RocksDB's persisted options show `compression=kNoCompression` and
`block_restart_interval=16`. zkv's `entry.append` writes the entire key with a
nine-byte header; `block.Writer` adds a four-byte offset per entry. RocksDB's
prefix-compressed table keys are a concrete encoding difference to investigate.
This run does not isolate what fraction of the gap comes from that difference,
as opposed to other encoding and maintenance choices.
Operationally, this workload needs about 77% more retained **index** disk with
zkv. That does not translate into 77% more total relay cost: PostgreSQL, replay,
CPU, memory, storage provisioning, and maintenance headroom remain separate.
The sampled peaks also show why provisioning only the settled index size is
insufficient. The canary's different asynchronous maintenance schedule needs
its own peak-space qualification.
Raw [stage measurements](zkv-load/index-space/results.jsonl),
[environment and file breakdown](zkv-load/index-space/metadata.json), and
[plot summary](zkv-load/index-space/comparison.json) accompany the graph. The
[measured harness source](zkv-load/index-space/measured-harness.zig.gz) matches
the SHA in the metadata; the maintained harness subsequently adds `crash-add`
without changing the measured workload phases.
## Workload and controls
- 1,000,000 deterministic pseudorandom 32-byte DIDs, each in two collections:
`app.bsky.feed.post` and one of 31 secondary collections. This produces
2,000,000 logical memberships and 4,000,000 forward/reverse index entries.
- Ten growth checkpoints, one complete duplicate pass, then three cycles that
remove every thousandth DID and restore it. Each cycle changes 1,000 accounts
and 2,000 memberships: a small deletion cohort, not a heavy deletion workload.
- Identical `addCollectionPage` calls: up to 4,096 DIDs for the common collection,
followed by the corresponding secondary-collection groups. Deletion uses the
real `removeAll` adapter method; restoration uses `addCollection`.
- RocksDB has `sync_writes=true`; zkv's directory store syncs files and parent
directories. This matches the intended acknowledged durability boundary;
it does not prove identical behavior under power loss.
- ReleaseSafe, Zig 0.17.0, C allocator, native Linux on heavypad. All input is
generated there. No PDS, firehose, R2, or production database participates.
- Each stage opens and closes the database. Reopened verification scans all
collections, checks counts and 64-bit membership checksums, and checks reverse
membership for every generated DID, including deleted accounts.
The default synchronous zkv adapter maintenance runs throughout ingestion:
256-segment / 4 MiB flush triggers and ordinary compaction/collection. The live
canary instead uses bounded asynchronous maintenance. Consequently, this run
isolates adapter storage efficiency but its transient peaks are not a direct
measurement of the canary's maintenance schedule.
Explicit settling flushes and drains zkv's eligible compactions and collection;
for RocksDB it flushes both column families and runs full-range compaction.
These engines expose different maintenance controls. Settled results retain
that policy difference; zkv settling does not promise a forced rewrite of every
level or removal of every tombstone.
Both adapters receive the same duplicate requests. zkv deliberately elides
existing memberships; RocksDB rewrites them. That is an adapter design difference
being measured, not an omission from the generated workload.
## Measurements
The runner records total database-file lengths, allocated file blocks, file
counts, and sampled temporary peaks every 250 ms. Peaks are observed lower
bounds, not guaranteed maximum disk requirements. Directory metadata is excluded.
Linux child-process block-I/O accounting records reads and writes, including
maintenance and filesystem effects; these are not NAND-level device writes.
Read accounting from this warm-cache experiment is not a cold-read benchmark.
Timing includes opening/closing and polling overhead in the JSON records; the
per-stage logs separately report the timed adapter operations. Other work runs
on heavypad, so this experiment's primary conclusions concern space and I/O,
not a production throughput ceiling.
The initial calibration used 64-DID chunks and was stopped after discovering
excessive synchronous-operation overhead. Its partial database is excluded.
Both measured engines use the same corrected 4,096-DID workload.
## Crash recovery check
After the space measurements, each million-DID database received another 4,096
DIDs (8,192 memberships) with the same synchronous write guarantees. The harness
printed acknowledgement only after all writes completed, then raised SIGKILL
before database deinitialization. Both engines reopened and passed full forward
scans plus reverse-presence checks for all 1,004,096 DIDs / 2,008,192 memberships.
This checks abrupt process death after acknowledgement, not power loss or every
possible crash point during compaction. These extra memberships are excluded
from the space graphs above.
Raw [zkv](zkv-load/index-space/crash-zkv.json) and
[RocksDB](zkv-load/index-space/crash-rocks.json) recovery results are retained.
Reproduce with `scripts/zkv/space_crash.py BINARY DATABASE EXISTING_DID_COUNT`;
it deliberately kills the child and adds data to the supplied experiment database.
## Reproduction
Build `zig build index-space -Doptimize=ReleaseSafe` on the zkv canary and RocksDB
control branches, then run:
```sh
uv run --no-project python scripts/zkv/space_compare.py OUTPUT ZKV_BINARY ROCKS_BINARY --count 1000000
```
The runner refuses to reuse an engine database directory. `--engine zkv` and
`--engine rocks` permit sequential runs into the same output directory. Database
files remain available for inspection; JSONL records and stage logs are retained.
## Validation
Both ReleaseSafe harness builds, all 30 measured stages per engine, and both
post-SIGKILL recovery checks passed. The existing `zig build test -j2` suite
also exited successfully in both source mirrors on heavypad, run through
`git rebase -x` for each new harness commit. No production or Zeldi code changed.