Compression

Opt-in zlib compression for entity values, transparent at the read/write boundary. Off by default.

Enable

new RedisGraphCache(schema, {
  cache: {
    enableCompression: true,
    compressionThreshold: 4096, // bytes
  },
});

What gets compressed

Only entity values written by the normalization path. Plain list JSON-array values, indexedList ZSETs, and the membership back-index are notcompressed (their shape is consumed by Lua scripts on the Redis side, which can't inflate compressed payloads).

On-wire format

Magic prefix

Compressed values are stored as a string with the prefix \x00z1: followed by base64-encoded deflateRaw output. Plain JSON values (which always start with { or [) are stored unchanged.

Backward compatibility

Safe to enable on a populated cache

  • Reads detect the prefix and only decompress tagged values.
  • Disabling compression later is also safe — uncompressed writers can still read previously compressed values, and vice versa.

Threshold

Payloads smaller than compressionThreshold bytes are not compressed because the base64 envelope overhead would be a net loss. The minimum threshold is clamped at 64 bytes.

When to enable it

Typical posts with comments are 2–10 KB. At that size, compression saves ~50% of memory and bandwidth, which matters once you have ≥100k entities or run on a paid Redis with a memory cap. Enable it after the rest of your setup is stable, with a generous threshold (e.g. 4 KB).

Not a correctness or scaling fix

Compression is a storage cost optimization, not a path to higher throughput or stronger consistency. CPU cost on the Node side is small but not zero.