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.
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
- Watch
- Try it
- Predict
- Capture
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.
Highlighted lines are the ones running in the diagram right now.
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
def keydir_ram_check(workload, config):per_key = 44.5 + workload.avg_key_len # bitcask-04total = workload.key_count * per_keyper_vnode = total / config.vnode_countif per_vnode <= RAM_BUDGET_PER_VNODE:return [] # fitsif 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')]
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')]
def recommend_engine(workload, config):if workload.requires_range_or_prefix:return 'LSM' # bitcask-01 ceilingper_key = 44.5 + workload.avg_key_lenneeded = workload.key_count * per_keybudget = RAM_BUDGET_PER_VNODE * MAX_VNODESif needed > budget:return 'LSM' # bitcask-04 ceilingif workload.deletes_and_recreates:config.delete_mode = 'keep' # bitcask-07return '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