Skip to content

PATTERN Cited by 1 source

RocksDB compaction tuning for TTL

Pattern

Override RocksDB's default compaction parameters to ensure background compaction runs frequently enough (and processes enough data per run) to exercise the TTL filter and prevent unbounded state growth in streaming workloads.

Problem

Default RocksDB settings are tuned for general-purpose workloads. In streaming systems with high write rates and bounded retention (e.g., 15-minute event windows), the defaults cause: - Compaction runs too infrequently → expired keys accumulate - Each compaction processes too little data → TTL filter has limited opportunity - State grows without bound despite all entries being logically expired

Configuration recipe (from Zalando production)

# Larger, more frequent compaction runs that exercise TTL filter
state.backend.rocksdb.writebuffer.count: "16"                           # default: 2
state.backend.rocksdb.writebuffer.size: "512MB"                         # default: 64MB
state.backend.rocksdb.compaction.level.target-file-size-base: "256MB"   # default: 64MB
state.backend.rocksdb.compaction.level.max-size-level-base: "1GB"       # default: 256MB

# Post-rescale cleanup (orphaned keys from previous parallelism)
state.backend.rocksdb.incremental-restore-async-compact-after-rescale: "true"
state.backend.rocksdb.rescaling.use-delete-files-in-range: "true"

# Reduce on-disk footprint
state.backend.rocksdb.compression.per.level: "LZ4_COMPRESSION"         # default: SNAPPY
state.backend.rocksdb.predefined-options: "FLASH_SSD_OPTIMIZED"         # default: DEFAULT

Seen in

When to use

  • Flink jobs using KeyedCoProcessFunction (or similar) with RocksDB TTL for state expiry
  • High-throughput streaming with bounded retention windows
  • Any Flink job where state size grows unexpectedly despite logical TTLs

Trade-offs

  • Larger write buffers → higher memory usage per TaskManager
  • More aggressive compaction → higher write amplification and CPU usage
  • LZ4 over Snappy → slightly more CPU for compression, smaller on-disk size
Last updated · 595 distilled / 1,807 read