At One Million Records, SQLite’s Advantage Is Locality
A compressed SQLite file can cut storage and network costs, but its real advantage depends on read locality, write limits, and measured decompression.
For one million 2 KB documents, a 64 KB Zstandard dictionary at an assumed 5:1 ratio reduces payload storage from 2 GB to about 400 MB, before indexes and operational overhead. A $10 monthly single-node setup can beat a small distributed deployment when reads are local and writes are modest. It does not remove SQLite’s single-writer constraint, and compression does not reduce model tokens.
A million records sounds like a distributed-systems problem. Often it is a disk budget and a query-shape problem wearing a more expensive name.
Assume one million JSON or HTML documents averaging 2 KB each: 2 GB of uncompressed payload. A 64 KB Zstandard dictionary can improve compression when documents share field names, markup, and repeated phrases. Treat 5:1 as a benchmark target, not a guarantee: that yields roughly 400 MB of compressed payload, plus the dictionary, indexes, SQLite page overhead, and free space for writes.
The economic win comes from keeping those bytes on one machine, close to the process that reads them. The trade is operational: SQLite WAL permits readers alongside a writer, but it still serializes writes. This is a unit-economics choice, not a claim that one database is universally better.
Put the assumptions on the napkin
The comparison below uses illustrative prices, not vendor quotes. It assumes a $10-per-month VPS with a local SSD, a small three-node document-store deployment at $10 per node plus a $10 load balancer, and a managed-store budget of $150 per month. Backups, engineering labor, and provider-specific allowances can change the bill.
| Metric / Approach | SQLite WAL, one VPS | Three-node document store | Managed document store |
|---|---|---|---|
| Payload at rest | 400 MB compressed | 6 GB raw with 3 copies | 2 GB raw, service-dependent replicas |
| Useful hot payload, 10% of records | 40 MB compressed | 200 MB per replica | Service-dependent |
| Monthly compute and storage estimate | $10 | $40, before backups | $150 assumed floor |
| Read path | Local process to page cache | Network hop to a node | Network hop to service |
| Write scaling | One active writer | Distributed, configuration-dependent | Service-dependent |
| Main cost risk | Write contention or host failure | Replication and operations | Minimum bill and request charges |
For SQLite, 400 MB is only the compressed document payload. Allow another 100 to 300 MB for indexes, database structure, and working room, then verify the actual file with a representative import. If the VPS has 2 GB of RAM, a 40 MB compressed hot set fits easily. A process that expands and caches all hot documents needs closer to 200 MB, plus runtime overhead.
The byte arithmetic is simple. One million records times 2 KB is 2,000,000 KB, or about 2 GB in decimal units. At a measured 5:1 ratio, the payload is about 400 MB. Replicating the raw 2 GB payload three times is about 6 GB before indexes, logs, snapshots, and backups.
Compression moves bytes, not every bottleneck
A dictionary helps because short documents often repeat grammar. A JSON record may reuse keys such as title, created_at, and description. An HTML fragment may reuse tags and class names. Zstandard can encode those recurring patterns using a trained dictionary, but the benefit depends on representative training data and document boundaries.
SQLite does not automatically apply a custom Zstandard dictionary to arbitrary text columns. The application must compress on write and decompress after read, or use an appropriate extension or virtual file system. Keep the dictionary version with the data format, and store enough metadata to select it during reads.
write: document -> Zstd(dictionary v1) -> SQLite BLOB
read: SQLite BLOB -> Zstd(dictionary v1) -> application
index: separate SQLite columns, left uncompressed for lookup
That distinction matters for latency. A cache hit avoids storage I/O, but it still requires lookup, copying, and decompression. A sub-0.2 ms local read is plausible for a warm page-cache lookup on suitable hardware, but it is a benchmark result to reproduce, not a property guaranteed by WAL or Zstandard. Measure p50 and p99 with realistic document sizes, concurrency, and cold-start behavior.
Count the network and model bill separately
Suppose the service returns every document once over a month. At 2 KB each, that is 2 GB of payload. A more useful load case is 10 million reads, or 20 GB uncompressed. If the compressed representation is also used on the wire, payload traffic could approach 4 GB at the assumed ratio. At an illustrative marginal egress rate of $0.09 per GB, that is $1.80 versus $0.36. Many plans include some transfer, so the actual invoice may show no difference until the allowance is exceeded.
The compression ratio does not reduce embedding tokens. At an assumed 500 tokens per document, embedding one million documents processes 500 million input tokens. At $0.02 per million tokens, the one-time embedding estimate is $10. Text must be decoded into model input, and tokenization depends on the text, not its stored byte representation. Re-embedding after a data or model change can cost more than a month of the small VPS.
If each of 10 million retrieval requests also sends 500 input tokens to a model, that is 5 billion input tokens. At an illustrative model rate of $0.15 per million input tokens, the estimate is $750, before output tokens. That makes database selection a small part of the AI bill. Compression can reduce storage and transfer. It does not make a large prompt cheaper.
Pay for the boundary you actually cross
The $10 VPS estimate is attractive when reads are mostly local, the hot working set fits in memory, and write volume stays within one writer’s capacity. WAL lets readers continue while a writer appends changes, but checkpoints eventually move WAL pages back into the main database. Long-lived readers can delay that work and allow the WAL file to grow. Monitor checkpoint duration, WAL size, write latency, and disk headroom instead of treating “WAL enabled” as a reliability plan.
A distributed store earns its extra bill when the workload needs independent write capacity, failover across hosts, geographic placement, or operational isolation that a single machine cannot provide. Three nodes are not automatically more available: backups, repair procedures, network partitions, and tested failover still matter. Managed service pricing can buy reduced operational work, but it does not eliminate the need to test restore and measure request costs.
The practical decision rule is to benchmark the real workload before adding nodes. Load representative documents, train the dictionary on one sample and test it on another, then measure compressed size, decompression CPU, p99 reads, write stalls, and recovery time after a forced restart. If the local design meets those limits with at least 30% disk and memory headroom, it may be the cheaper production system. If writes queue or a host outage violates the service objective, the
Discussion (7)
Our log aggregation runs on SQLite with Zstandard; the 5:1 ratio holds for JSON logs. The complication is write amplification during high-ingestion bursts, where WAL checkpointing contends with reads. We added a small in-process buffer, which smoothed it out. For our volume, the $10 node still wins, but you must profile those write spikes.
The 5:1 compression ratio here echoes the old-school wisdom from the 1980s Unix tools: compress early, decompress late. Think of zcat piped into grep, if your data’s already in a tight, localized store like SQLite with WAL, you're not just saving bytes, you're reducing memory pressure and cache misses. It’s like using a shared dictionary in a real-time sensor fusion pipeline where every byte in DRAM costs a cycle.
This isn’t just storage, it’s about keeping the working set in CPU cache, not on the network. The lesson? Locality isn’t just a translation layer; it’s the compiler’s best friend.
You're absolutely right about locality being the compiler's best friend, but the real win here is that SQLite’s page cache and Zstandard’s dictionary both exploit type-level invariants. The 64 KB dictionary isn’t just a shared string table. It’s a compile-time constant that the compressor and query planner can assume is stable.
If you have a schema where keys are fixed (e.g., {"status": "active", "device_id": "d123"}), the compressor and index builder can collapse those into fixed offsets. That’s when 5:1 isn’t just a statistical fluke, it’s a predictable invariance. That’s where zero-copy decompression and query fusion emerge. Dropping the dictionary means dropping the invariant, and the whole thing degrades to just a faster zip.
You’re describing a specialized optimization, but Zstandard's dictionary is a runtime, not compile-time, constant. It's a static lookup table that helps compress repeated byte sequences, but the query planner doesn't see it. The predictability you cite comes from schema normalization, which SQLite's B-tree already exploits directly, the dictionary just adds another layer of byte-level redundancy elimination before storage.
That shared dictionary is basically doing the entropy-coding equivalent of spatial alignment. By shrinking the working set to fit L3, you trade CPU cycles for bus traffic. It is pure information density optimization, matching what we see when packing telemetry streams into circular buffers on constrained microcontrollers.
The analogy holds at the storage boundary, but fitting compressed bytes in L3 is not automatic: SQLite may cache compressed pages, while a query that materializes documents expands them into a much larger working set. The real trade is decompression CPU for fewer bytes read. Benchmark the access pattern, not just the compression ratio.
That compression dictionary will make your VACUUMs significantly more expensive. The CPU cost of rebuilding compressed pages during auto-vacuum will surprise you on a $10 VPS during a write-heavy period.