Interview: one table takes 50,000 writes a second, another feeds dashboards. Which engine for each?
Pick a storage engine per table. Compare read, write and space cost, the RUM idea, compaction styles and Bloom filters, and why “which has lower write…
More on Ticket interviews
- Database Interviews in the AI Era: The Ticket Format
- Interview: the same job runs twice
- Deadlock Interview Question: Find and Fix It in SQL
- Slow Query Interview: One Keyword Made It 40× Slower
- Interview: rate limit is 2/min, 30 requests get through
- Interview: “just add an index” slowed ingestion
- Interview: “I changed my name, refresh shows the old one”
- Interview: importing 10M rows takes six hours
- Interview: everything got slow and the disk keeps growing
- Lost Update Interview: Wallet Balance Wrong Under Load
- Interview: API p99 jumps 10× every night at 2 am
- Interview: profile lookups got 40× slower, writes are fine
- Interview: inserts stall, and only one page is hot
- Interview: the write succeeded, the next read shows an empty cart
- Interview: inventory stayed locked after the coordinator restarted
- Interview: for four minutes, both regions took orders
- Interview: shoes show a 0% discount, then the report crashes
- Interview: March gained $50 after the deploy, and the months don’t add up
- Interview: the new branch’s dashboard takes 38 seconds
- Interview: the index is right there, make Postgres use it
- Interview: warehouse and checkout overwrite the same order
- Interview: the bestsellers report now takes nine minutes
- Interview: an analyst query locked checkout
- Interview: the member is active and the email went out twice
- Interview: one shard is at 96% CPU and the other is idle
- Interview: the menu is slow, and the proposal is event sourcing
- Interview: four dashboards disagree about whether the database is slow
- Interview: checkout got slow the hour the warehouse job started
- Interview: the query is fast in staging and slow in production
- Interview: login looks up an email and reads the whole customers table
- Interview: the proposal splits one database into three shards
- Interview: the order page joins four tables on every view
- Interview: every page view is a read-write query on the leader
- Interview: Sarah and John both debit version 1
- Interview: the CTO read a blog post and wants to move Postgres to MySQL
- Interview: EU users wait on the ocean for every write, can both regions take writes?
- Interview: users search cars by color, but the table is sharded by car id
- Interview: we added a fourth node and most of the data moved
- Interview: two people book the same room at noon, both get a confirmation
- Interview: everything is on the strongest consistency and far requests crawl
- Interview: the order is saved, the message to search and email never left
- Interview: rename a column on a 600 GB table while 30 servers keep serving traffic
- Interview: orders go to 16 shards in 2 regions, what should the order id be?
- Interview: one celebrity posts, and every timeline in the app slows down
- Interview: 5,000 customers share one database, and one of them slows down everyone
Keep learning
Overview
In simple words, why are LSM writes so cheap? explain simply It goes to a log and a sorted in-memory table (the memtable). A full memtable is written out once as a new file, never edited again. The work is not skipped: it moves to background merging and to reads. log plus memtable immutable files cost moves to compaction and reads What breaks if compaction cannot keep up with the writes? what breaks if Writes stall, reads slow down, and disk use grows. Engines like RocksDB pause writers until the memtable flushes. Files pile up: more files per read, old versions waste disk. Fix: more disk bandwidth, bigger memtable, or slow writers. Alert on compaction debt. write stall read and space grow monitor compaction debt Numbers: how big is a Bloom filter, and what does a B-tree read cost? 10 bits per key gives about 1% false alarms. Every 5 extra bits per key cuts false alarms tenfold. One billion keys at 10 bits ≈ 1.25 GB of filters (our arithmetic). A B-tree is 3–4 levels deep, so one key costs 3–4 page reads. 10 bits per key false alarm vs miss B-tree depth is small Which has lower write amplification, a B-tree or an LSM tree? trap question Trap: they write extra bytes for different reasons, so one number misleads. B-tree: rewrites whole pages, again on every later update. LSM: compaction copies the same data from file to file. Measure bytes on disk per byte written, on your own workload. different sources measure bytes on disk You can only run one engine for the whole system. What do you pick, and what do you do about the other table? what would you do instead First challenge the premise: an engine per workload is common and sensible. Forced to one: pick by the biggest pain. Reads and ranges: B-tree or leveled LSM. Ingest: size-tiered or time-window LSM. Either way, benchmark with your own traffic. engine per workload pick by the dominant pain benchmark your own load SSDs make random writes cheap, so does LSM still matter? Yes. The gap is smaller on SSDs, not gone. Flash writes pages but erases whole blocks. Scattered writes force the drive to copy live pages before erasing: wear and bandwidth. Engine and drive both rewrite data. Measure total bytes written. gap smaller, not gone erase blocks and garbage collection log stacking Reads, writes, ranges, data lifetime. Three costs Read, write, space: can’t win all three. Reads: B-tree. Writes: LSM. Expiring: time-window. LSM: compaction debt. B-tree: page splits. Benchmark our own traffic. One write-amplification number for both engines. The sources differ. Forgetting ranges. Bloom filters help single keys, not ranges. Ignoring compaction. It needs bandwidth and space, and can stall writers. Why LSM writes are sequential Bloom filter and false-alarm cost Compaction strategy fits workload Dodged the write-amp trap Benchmark your own workload Left: a filing cabinet where every new paper goes into its exact folder, in order. Right: an inbox tray where papers are dropped on top, with sorted bundles below that get merged from time to time, and a sticky note on each bundle saying which names are inside. B-tree: the filing cabinet new paper find the exact folder, then file it LSM: the inbox tray tray (memory) one big sorted bundle drop papers fast, merge bundles later Filing is slow but finding is easy. Dropping is fast but finding means checking the tray and bundles. Write paths. B-tree: the change is appended to the write-ahead log, the engine finds the leaf page, and rewrites that whole page in place, at a random place on disk. LSM: the change is appended to the log and inserted into the memtable in memory. When the memtable is full it is flushed as a new sorted file that is never edited. Background compaction merges files into bigger ones. B-tree: find the page, change it in place log: append first root page read the page, change one cell, write the whole page back random places on disk · a full page splits in two LSM: add to memory, write sorted files later log: append memtable (RAM) full: flush new sorted files · never edited compaction in the background one bigger sorted file no need to find the old record first sequential writes · reads must check several files What to notice: the B-tree must locate and rewrite a page. The LSM only adds to memory and the log, and pays later in the background. Finds the page and edits it in place. Reads are fast and steady. Writes are scattered and rewrite whole pages. Pages keep spare room for later. LSM, leveled Sorted files in size-limited levels. Few files to check per read and little wasted space, but data is rewritten each time it moves down a level. LSM, size-tiered Merges files of similar size. Data is rewritten only a few times, so writes are cheap. Reads check more files and big merges need spare disk. Read cost Write cost Space cost One workload, three engines (toy model, ranks are illustrative) Account table Event firehose Share of writes Triangle with corners fast reads, fast writes, small space. Each engine is a dot. The B-tree sits near fast reads, leveled LSM near small space, size-tiered LSM near fast writes. No dot reaches the centre of all three corners. fast reads fast writes small space What to notice: move the slider. The best engine changes from B-tree to leveled to size-tiered. No dot sits in the middle of the triangle: improve two corners and the third gets worse (the RUM idea). L0 file A L0 file B L1 file L2 file in memory scan its slice not here cannot help scan a slice says maybe read, found it false alarm: read for nothing says no read, not here Look up a key in an LSM tree what are we looking for Lookup type one key, it exists one key, missing a range bloom filter on each file Bloom filter a filter answers "is this one key here?". A range has no single key to ask about, so every file must be scanned and merged. files that say no cost almost nothing. A "maybe" can be wrong (a false alarm) and costs one wasted read. A filter never says no when the key is there. with no filters the engine opens file after file, newest first. A missing key is the worst case: it must check all of them. A 16-bit Bloom filter. The key handbag set bits 2, 4 and 9. Looking up handheld checks bits 6, 11 and 2. Bit 2 is set but bits 6 and 11 are zero, so handheld is definitely not in this file. A tiny Bloom filter: 16 bits, one stored key Stored key "handbag" turned on bits 2, 4 and 9. Lookup "handheld" checks bits 2, 6 and 11 (red frames). Bit 2 is on, but bits 6 and 11 are off. One zero is enough: definitely not in this file. If every checked bit were 1 the answer is only "maybe": other keys may have set them. The same small record is written many times for different reasons. In a B-tree each update rewrites the whole page that holds it. In an LSM tree compaction copies the record from file to file as it moves down levels. B-tree: the whole page is written back, again for each later update page rewritten update 1, update 2, update 3 … LSM tree: compaction copies the record from file to file one record, moved down Different reasons for the same dot being written again. Count bytes on disk, not labels. Append to log sorted, in RAM Flush file once, never edited Compaction later background merge Writes outpace merges Files pile up more files per read Old versions linger disk grows Write stall engine pauses writers Reads + ranges B-tree or leveled LSM Heavy ingest Size-tiered LSM Data that expires Time-window LSM Scattered writes on SSD Blocks half dead. Drive copies live pages before erasing. Sequential writes on SSD Whole blocks die together. Little copying.
One table takes 50,000 writes a second. Another is read by dashboards. Which engine for each?
There is no single winner. You choose which cost to pay: reads, writes or space. read / write / space amplification RUM conjecture Bloom filters workload fit Two tables with opposite workloads need an engine Each engine trades read, write and space costs LSM for the firehose, B-tree for dashboards
A filing cabinet and an inbox tray
Filing cabinet (B-tree) Each paper in its exact folder. Quick to find, slower to file. Inbox tray (LSM) Drop on top, sort into bundles later. Quick to file, slower to find.
Two new tables, one storage engine decision
Table A: device events. Firehose of inserts, kept 30 days, rarely read. Table B: orders. Read all day by dashboards, in date ranges. Table B rows are updated a few times after creation. table A writes 50,000 / s (illustrative) table A life 30 days table B reads 95% of traffic table B access ranges + updates Table A · events Write-heavy, expires, rarely read. Table B · orders Read-heavy, ranges, some updates. Restated: one engine per workload, and a reason naming what each one pays.
How each engine writes, what it costs, how it reads
Start with the picture of the write paths. Then move the slider, then open the read path.
Four ways to store the same rows
Fast reads Fast writes Small on disk Cheap expiry LSM, leveled LSM, size-tiered LSM, time-window Four ways to store the same rows. No row is all ticks. Mostly reads, ranges, updates, steady latency. pick when Write-heavy, but reads still matter. Mostly writes, few reads, spare disk. Time series and logs with a TTL. Table A: 50,000 writes a second, rows expire after 30 days, rarely read. What engine? LSM tree with time-window compaction (size-tiered if that is not offered) Sequential writes absorb the firehose. Expired days drop as whole files, no rewrite. Write throughput Read speed, latest day Disk space used LSM tree with leveled compaction Works, but rewrites each record per level. You pay for reads you barely use. A B-tree engine with a big buffer pool
A model spoken answer
How do you choose between a B-tree and an LSM tree?
More courses
- Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
- Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
- React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
- System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
- NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
- Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
- Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
- AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
- Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
- TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
- CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
- Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
- Docker — What an image is, why layers cache, and how containers find each other on a network.
- Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
- Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
- AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
- Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.