Design your KV — and feel its limits

Every Bitcask choice — sync_strategy, max_file_size, merge thresholds, key cardinality — is a deliberate trade against the hash-index-in-RAM aesthetic, and the absence of range/prefix iteration is the ceiling that bridges to LSM.

Previously

Every Bitcask choice is a trade against the same hash-in-RAM aesthetic. Sync, file size, merge cadence, sharding, key cardinality — they all push back on the same wall. One trade has no good answer at all.

Scene 08

Design your KV — and feel its limits

  1. Watch
  2. Try it
  3. Predict
  4. Capture
Workload SLO — Photo blobs · 10M × 2 MB10M photo URLs → 2 MB blobs. Bursty writes; reads must be sub-5ms. Lose at most 1 s of writes on crash. RAM ~ 760 MB across vnodes.CLUSTERRF=4 · partitions=9768vnode 1 (~2,442 files)6Pv1.000.datav1.001.datav1.002.datav1.003.datav1.004.datav1.005.datavnode 2 (~2,442 files)6Pv2.000.datav2.001.datav2.002.datav2.003.datav2.004.datav2.005.datavnode 3 (~2,442 files)6Pv3.000.datav3.001.datav3.002.datav3.003.datav3.004.datav3.005.datavnode 4 (~2,442 files)6Pv4.000.datav4.001.datav4.002.datav4.003.datav4.004.datav4.005.datamerge fires @ ≥ 60% dead bytesWORKLOAD: PHOTO BLOBS · 10M × 2 MBclient (GET/PUT)owns v1.000.data, v2.000.data,…merge workerowns v1.000.data, v2.000.datarestart (hints)owns v1.000.data, v2.000.data,…FEATURE FLAGSONhint files.hint siblingmerge windowoff-peakdelete_mode=keeptombstone guardTRADE-OFFSThroughput3/5Durability3/5Complexity2/5WARNINGSkeydir RAM 730 MB total · 182 MB/vnode — fits 256 MB budget(bitcask-04).
What to watch for

One workload card on the canvas: photo blobs, 10M × 2 MB, p99 < 5 ms reads, lose < 1 s on crash. Watch the verifier walk the four checks — RAM math, sync trilemma, merge cadence, hint files — and name the earlier scene behind each.

Continue unlocks when the animation finishes.
Implementation

Highlighted lines are the ones running in the diagram right now.

verify_workload(workload, config)
top-level verifier — runs the checks in dependency order
def verify_workload(workload, config):
violations = []
# bitcask-04: RAM ceiling — most decisive.
violations += keydir_ram_check(workload, config)
# bitcask-01: hash index has no order.
violations += range_query_check(workload)
# bitcask-06a: sync_strategy vs crash-loss SLO.
violations += sync_strategy_check(workload, config)
# bitcask-07: delete-then-recreate trap.
violations += tombstone_check(workload, config)
return violations
keydir_ram_check(workload, config)
the decisive verdict — bitcask-04 ceiling
def keydir_ram_check(workload, config):
per_key = 44.5 + workload.avg_key_len # bitcask-04
total = workload.key_count * per_key
per_vnode = total / config.vnode_count
if per_vnode <= RAM_BUDGET_PER_VNODE:
return [] # fits
if total / MAX_VNODES > RAM_BUDGET_PER_VNODE:
return [reject('use LSM (LevelDB/RocksDB):'
' keydir blows budget at any'
' vnode count')]
return [warn('add vnodes — per-vnode keydir'
' over 256 MB budget')]
range_query_check(workload)
no Bitcask config can satisfy ordered access — bitcask-01
def range_query_check(workload):
if not workload.requires_range_or_prefix:
return []
# keydir is a hash table; hash tables have no order.
# list_keys + filter is O(N) — produces the answer,
# not efficiently. No knob fixes this.
return [reject('use LSM: ordered access requires'
' a sorted index (SSTables /'
' B-tree), not a hash')]
recommend_engine(workload, config)
closing function — when to switch storage engines
def recommend_engine(workload, config):
if workload.requires_range_or_prefix:
return 'LSM' # bitcask-01 ceiling
per_key = 44.5 + workload.avg_key_len
needed = workload.key_count * per_key
budget = RAM_BUDGET_PER_VNODE * MAX_VNODES
if needed > budget:
return 'LSM' # bitcask-04 ceiling
if workload.deletes_and_recreates:
config.delete_mode = 'keep' # bitcask-07
return 'Bitcask' # honest fit

Where this sits in Build a Bitcask-style KV store

Scene 08 of 9, in the Sharp edges act — Tombstone resurrection and the design ceiling.. Capstone: every choice is a trade against the hash-in-RAM aesthetic. The absence of range/prefix iteration is the ceiling that bridges to LSM.

All 9 scenes in Build a Bitcask-style KV store · Every curriculum

Built with Arqly
Every scene in Build a Bitcask-style KV store builds on the one before it.All 9 Build a Bitcask-style KV store scenes