Skip to content

Compression and Security

TaiDB can compress values with zstd and encrypt records with XChaCha20-Poly1305. These features are optional and should be selected per workload.

The CLI exposes common modes:

Terminal window
taidb --compression zstd-fast put ./app.taidb key value
taidb --compression zstd put ./app.taidb key value
taidb --compression zstd-dense put ./app.taidb key value
taidb --compression zstd-max put ./app.taidb key value

The Rust API exposes explicit settings:

use taidb::{Compression, EngineConfig, Options};
let options = Options {
compression: Compression::Zstd {
level: 3,
min_bytes: 256,
},
..Options::default()
};
let db = EngineConfig::new("./compressed.taidb")
.options(options)
.open()?;
ModeBest forTradeoff
nonetiny values or already-compressed datalargest files
zstd-fastdefault practical compressionsmall CPU cost
zstdcustom level tuningrequires measurement
zstd-densearchival or local caches with large valuesslower writes
zstd-maxone-time repack or archival workflowshighest CPU cost

Use stats to inspect savings:

Terminal window
taidb stats ./app.taidb --json

Generate a key:

Terminal window
taidb keygen ./taidb.key

Write encrypted records:

Terminal window
taidb --key-file ./taidb.key put ./secure.taidb secret:1 "private value"

Read encrypted records:

Terminal window
taidb --key-file ./taidb.key get ./secure.taidb secret:1

Do not commit key files. The repository ignore rules already exclude common key and environment file patterns, but application repositories should also enforce their own secret policy.

Recommended practices:

  • Store local keys outside the project directory.
  • Use OS keychain or secret manager integration in production apps.
  • Keep database backups and key backups under separate access controls.
  • Rotate keys by exporting/importing or rewriting data into a new encrypted database when application policy requires it.

Run:

Terminal window
taidb verify ./secure.taidb --key-file ./taidb.key

For encrypted databases, verification checks that encrypted records can be authenticated and decoded with the provided key.