← Build Your Own Database
Stage 1: The Memtable
stage 1 of 4 · ~15 min · runs in your browser
Every LSM-tree engine starts with a memtable — an in-memory map that absorbs all writes at RAM speed. Reads check it first; deletes are just another kind of write.
Implement createStore() returning an object with:
set(key, value)— store a valueget(key)— return the value, orundefinedif absentdel(key)— remove the keyhas(key)— boolean
Sounds trivial — it is, deliberately. Real engines are layers on exactly
this core, and every later stage builds on yours. Get the semantics right:
overwrites replace, deleted keys read as undefined, and has reflects
deletes.
tests (5)
○ stores and retrieves a value
○ missing keys return undefined
○ overwrites replace the value
○ delete removes the key
○ has() reports presence
createStore.js