Generate a follow-up sub-lesson on any aspect of this topic
Guide complete
InnoDB B+Tree Vs RocksDB LSM-Tree Tradeoffs
Generate a follow-up sub-lesson on any aspect of this topic
InnoDB B+Tree Vs RocksDB LSM-Tree Tradeoffs
TLDR;
- A 5k writes per second catalog can fail its latency target for completely different reasons in each engine.
- The fastest way to sound credible in interviews is to quantify amplification on one concrete row update.
- Public MyRocks results give you defensible claims about SSD bytes written and storage footprint, with clear caveats.
A write heavy product catalog update stream is easiest to reason about when the database is one MySQL node on one SSD, because every tradeoff becomes a storage engine behavior, not a distributed system mystery. We will use a single workload throughout, catalog item upserts at 5,000 writes per second, plus reads for item pages and search filters, and we care about a write latency target because slow updates surface as stale inventory and price glitches. Let’s pin the baseline components before we change the engine:
The baseline has an app tier that issues INSERT ... ON DUPLICATE KEY UPDATE style writes, a MySQL server that exposes transactions and secondary indexes, a memory buffer that absorbs hot data, and an SSD that ultimately receives durable bytes. With 5,000 writes per second, small per write inefficiencies compound into steady state SSD bandwidth pressure and background work that pushes up even when average latency looks fine.
Amplification is the habit of measuring how much extra work the engine does beyond the logical request, and it is what turns B+Tree versus LSM tree into a quantitative discussion. Write amplification is bytes written to storage per logical bytes written, read amplification is extra data pages or files touched per logical read, and space amplification is bytes stored on disk per logical bytes of live data. We can see how one row update shifts these three knobs when we change from update in place to append only, so we can tune the intuition:
In the update in place path, one logical row change dirties an existing on disk structure, so the engine tends to rewrite whole pages that contain the row and its index entries. In the append only path, the engine writes the new version sequentially and cleans up old versions later, so write amplification usually drops at ingest time while read amplification and space amplification depend on how quickly background cleanup keeps up.
InnoDB makes a B+Tree fast by grouping many rows and index entries into fixed size pages that it can cache and rewrite as a unit, which is great for point lookups but creates random I O when many pages become dirty. A buffer pool is the in memory cache of those pages, and with 5,000 writes per second it fills with dirty pages that must eventually be flushed to the SSD in page sized writes that are not naturally sequential.
Durability in InnoDB starts with the write ahead log in files like ib_logfile*, which records changes before dirty pages are flushed so crash recovery can replay them. InnoDB also uses a doublewrite buffer that writes pages twice in a safer pattern to avoid torn page corruption on partial writes, which adds more bytes written even when the logical update is tiny. Here is the page write path including the page split case, which is where B+Trees pay extra under random insert patterns:
The diagram’s key moving parts are the WAL append, the dirty page in the buffer pool, the extra doublewrite step, and the final page flush to the tablespace. A page split happens when an insert or update needs space in a full page, so the engine allocates a new page and rewrites structure metadata, which increases write amplification and can also increase contention in hot indexes.
Design rule When the workload is many small updates across many keys, page sized rewrites dominate before CPU does.
RocksDB makes writes cheap by treating storage like an append only log and postponing reorganization, which turns many small random updates into mostly sequential I O at ingest time. The engine first appends to its WAL for durability, then inserts into a memtable which is an in memory sorted structure, and later flushes it as an immutable on disk file called an SSTable.
A background process called compaction exists because flushes create many overlapping SSTables, and point reads would otherwise need to check too many files while old overwritten versions accumulate. Compaction rewrites data into fewer, larger SSTables, dropping overwritten keys and tombstones, and arranging files so that most levels have non overlapping key ranges. This write path shows what stays sequential and what turns into rewrite work later:
The write path’s front half is WAL plus memtable inserts, then a sequential flush to create an SSTable, and the back half is background compaction that reads and rewrites SSTables. The important state change is that the engine trades immediate random page updates for deferred rewrite work, so steady state performance depends on compaction keeping up with the 5,000 writes per second ingest rate.
Compaction strategy is the lever that decides whether the engine pays more in background rewrites or more during reads, and it is the point where many interview answers get specific. Leveled compaction keeps levels mostly non overlapping, which reduces files checked per point lookup but rewrites data more times, while tiered compaction keeps more overlap to reduce rewrite work but usually increases read amplification and space usage. The tradeoffs are easier to argue when they are side by side:
The comparison usually breaks along five axes, write amplification, read amplification, space amplification, tail latency risk from compaction bursts, and operational tuning complexity. The state you want for our catalog is that compaction debt stays bounded, because once compaction falls behind, the engine stalls writers or inflates read work until it catches up.
RocksDB point reads stay competitive by using probabilistic and cached structures so it can avoid touching most SSTables. A Bloom filter is a compact in memory structure that can say a key is definitely not in an SSTable, index blocks guide the file search, and the block cache keeps frequently accessed data blocks in memory to avoid SSD reads.
Range scans behave differently from point lookups because the engine may have to merge results from multiple SSTables and levels, especially when there is overlap or many tombstones. This is why LSM engines often look great for key value access patterns but can be slower on wide secondary index scans, and why MyRocks calls out range query performance challenges. Here is the point lookup flow with and without Bloom filters, contrasted with scans:
The scan widget highlights how a Bloom filter can remove whole file reads for point lookups, while range scans still have to stream through blocks and reconcile versions across files. The practical implication is that LSM tuning spends DRAM on filters and cache to buy back read amplification, which is a valid trade when SSD capacity is the binding constraint.
Interview claims land better when they are anchored in reported metrics instead of generic B+Tree versus LSM folklore. Facebook reported that migrating their User Database workload from InnoDB to MyRocks reduced instance size by 62.3 percent and reduced bytes written to storage by 75 percent, while staying within acceptable CPU and latency targets for their workload shape.
Long running Linkbench comparisons also reported that InnoDB wrote about 8x to 14x more data to SSD per transaction than RocksDB and that RocksDB sustained about 1.5x more throughput on that IO bound workload, with additional amplification when SSD flash garbage collection is considered. Those numbers are not universal because they depend on compression, device fullness, durability settings, and the read pattern mix, so the credible interview move is to cite the direction and then name the caveat. The evidence and caveats can be stated cleanly like this:
The revealed takeaways connect to our mental model, lower write amplification and tighter space usage come from append only ingestion plus compaction, while read and CPU costs show up in scans, key comparisons, and filter and cache overhead. The caveats matter because a workload with heavy range scans, strict synchronous commit settings, or insufficient DRAM for filters can shift the balance back toward InnoDB even if raw SSD bytes written look better under MyRocks.
For the 5,000 writes per second catalog, the defensible first choice is driven by what is scarce on the node, SSD capacity and endurance versus CPU and predictable range query latency. If storage footprint and SSD write rate are the limiting constraints, an LSM based engine like MyRocks with leveled compaction and provisioned DRAM for Bloom filters and block cache is usually easier to justify, while if the workload is dominated by secondary index range scans and needs stable tail latency without compaction tuning, InnoDB is often the safer baseline.
A redesign becomes necessary when the workload violates the engine’s steady state assumptions, not when one microbenchmark looks bad. Examples include sustained write bursts that exceed compaction throughput and cause stalls in LSM, or a growth in random updates across many secondary indexes that turns InnoDB into constant page splits and flush pressure, and both cases push you toward reshaping the data model, isolating hot keys, or adding a write buffer such as a queue to smooth ingestion before it hits the primary store.