Interview: profile lookups got 40× slower, writes are fine
A delete job floods an LSM with tombstones and compaction falls behind. Memtables, SSTables, bloom filters, leveled vs size-tiered compaction, and the…
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: 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: one table takes 50,000 writes a second, another feeds dashboards. Which engine for each?
- 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
One profile lookup · rough model Compaction strategy Bloom filter Bloom filter bits 10 bits/key L0 files L0 file count 4 · healthy 18 · backlog files a read may open disk reads write amplification space amplification This is the ticket. Overlapping files plus no bloom filter turn one key lookup into a stack of disk reads. Writes stay fast because they only append. The bloom filter skips almost every extra L0 file, so this lookup stays near one disk read. The backlog is still there: tombstones have not been merged away, and more L0 files will stall writes. A bloom filter skips files that cannot hold the key, and a small L0 means few overlapping files. The read touches about one table on disk. Size-tiered compaction rewrites less (lower write amp) and leaves more overlapping runs (higher read amp and more space used by old versions). Leveled compaction keeps runs inside a level from overlapping, which keeps reads cheap and rewrites data several times on the way down.
Profile lookups got 40× slower. Writes are fine.
A mass delete buried an LSM store in tombstones, and bloom filters were switched off. Point reads now open dozens of files. bloom filter read amplification Tombstones piled up and bloom filters were off. Turn blooms back on, then compact during quiet hours.
GET /profile p99 went from 2 ms to 80 ms
API on-call Started during last night’s job that deleted 40M inactive profiles. Writes are still fast. Disk is busy. The database is RocksDB. GET p99 PUT p99 L0 files live tombstones Restated: a point read is doing a lot of disk I/O, while an append-only write is not.
What did the delete job and the config change do?
Forty million tombstones, flushed into many L0 files. Compaction is what actually drops them. rocksdb options Bloom filters are off, so every candidate file is a disk read. Compaction is capped at 20 MB/s, so it cannot catch the delete job. 40M tombstones Each delete adds a “gone” marker. Nothing is freed yet. Bloom filters off Every candidate file now costs a disk read. Compaction capped 20 MB/s cannot keep up with the delete job. Three changes, one slow read path.
Writes append. Reads search.
Why are writes still fast? compare PUT and GET A write just appends to memory and a log. It never edits the old row. What did DELETE actually do? read purge_inactive.ts It wrote a tombstone (a “key is gone” marker). Old bytes stay until compaction. Why does one GET read so many files? L0 file count + bloom setting L0 files overlap, so a lookup checks all 18. No bloom filter means each check can hit disk. Why hasn’t compaction cleaned up? rate limiter vs delete volume It is capped at 20 MB/s, far below the delete volume. Many L0 files will soon stall writes too.
Restore the read path, then drain the tombstones
Restores bloom filters, which make extra files cheap to skip. Raises compaction only when the API can spare the I/O. Adds an alarm before the next backlog. Replaces 40 million single deletes with a range delete. Blooms on Stop the purge L0 stops growing Compact at night L0 files > 8 Cheap fix first, heavy rewrite later.
No AI from here
Walk through a write and a point read in an LSM. A write goes to the memtable (in-memory sorted table) and the write-ahead log. A full memtable is flushed as an SSTable (immutable sorted file). Old files are never edited. A tombstone counts as “found, and the value is gone.” memtable then immutable files newest version wins tombstone stops the search L0 files overlap: check each one file per level first hit wins Point-read search order. When is a tombstone actually removed? Only when compaction has merged it with every older file that may hold the key. Drop it earlier and an old copy comes back to life. Until then it wastes space and slows scans. That is why disk grew during a delete. A range tombstone hides a whole key range with one marker. cannot drop a tombstone early space amplification range delete Dropped too early An older file still has the key. Deleted data reappears. Dropped after full merge No older copy left. Safe to forget. What does a bloom filter promise, and what does it cost? A false positive (wrong “maybe”) costs one wasted disk read. At about 10 bits per key, false positives are near 1%. Turning it off to save RAM moves the cost onto every read. no false negatives false positives cost a read memory vs read I/O Key really there Key not there Filter says “maybe” read file ✓ ~1% wasted read Filter says “no” never happens skip file ✓ What is the RUM conjecture, in plain language? You cannot minimize read, update and memory/space cost all at once. An LSM appends updates, then pays rewrite cost in compaction. Leveled pays rewrites for cheap reads. Size-tiered pays reads and space to rewrite less. names all three Read cost Write cost random I/O LSM leveled high (≈30×) LSM size-tiered low (≈4×) Reads are slow but the cluster cannot take a compaction storm. What do you do this hour? Turn bloom filters back on first. No data rewrite needed. Stop the delete job so the L0 backlog stops growing. Schedule compaction for quiet hours. If L0 nears the stall threshold, warn that writes will slow next. cheap fix before the rewrite predicts the write stall
Disk is at 85%. Compaction wants the rest.
What do you run tonight? Blooms on now, compaction in the quiet window Files become cheap to skip at once. Tombstones drain overnight while the API keeps the disk. Read latency Write safety Disk risk Remove the rate limit and compact at full speed Fastest cleanup. But compaction fights the API for a busy disk, so reads get worse first. Switch to size-tiered compaction Less rewriting, but more overlap makes point reads worse. A strategy change, not a hotfix. Leave it. Tombstones will compact eventually. At 20 MB/s, “eventually” may be days. One more spike hits the L0 stop threshold and writes fail.
Have one ready
Tell me about a time reads got slow while writes still looked healthy. Files per lookup, and why. What you changed now vs scheduled. The metric that would page you first.
Did you show these?
Why LSM writes stay fast while reads slow What a tombstone is and when it drops L0 overlap → files per lookup Bloom: false positives, no false negatives Leveled vs size-tiered as a cost choice Named the RUM trade-off Fixed reads before a compaction storm
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.