Leanpub Header

Skip to main content

Deterministic Storage Engines in C++

Building Crash-Consistent LSM Trees with Write-Ahead Logging and io_uring

Deterministic Storage Engines in C++
This book is 100% completeLast updated on 2026-12-01

Your storage engine passed every kill -9 test.

Then the power failed, and acknowledged writes were gone.

The file's contents had reached the disk. The record of where to find them never did.

Deterministic Storage Engines in C++ shows how to build an engine that proves otherwise.

Minimum price

$29.00

$39.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
About

About

About the Book

Your engine passed every kill -9 test. Then the power failed, and acknowledged writes were gone.

Book description

Most storage engines don't lose data because of a recovery bug. They lose it because of a missing barrier. The new manifest was written and synced, then renamed into place, and nobody synced the directory. The contents reached the disk. The record of where to find them never did.

Deterministic Storage Engines in C++ is a build-it-yourself guide to an LSM tree where every durability promise names the barrier that provides it, the failure it survives, and the test that proves it.

You build a complete reference engine in modern C++23 on Linux:

  • A write-ahead log with framing, group commit, segment recycling, and torn-tail recovery
  • io_uring paths that keep durability ordering intact, with the minimum kernel version named for every feature
  • Memtables, SSTables, Bloom and Ribbon filters, compression with dictionaries, and leveled, tiered, and hybrid compaction
  • A B+ tree on the same log and crash harness, so the two designs are compared by measurement and not by opinion
  • MVCC, snapshots, optimistic and pessimistic transactions, and the isolation anomalies each one permits
  • Deterministic simulation, fuzzing, and crash testing from simulated disks up to physical power-cut rigs

This is not a survey of database papers. Each chapter opens with a concrete failure and works through the mechanism that prevents it:

  • Why O_DIRECT is not durability
  • Why a failed fsync can never be retried
  • Why a valid frame after a damaged one can be the correct thing to discard
  • Why leveled compaction quietly consumes a drive's endurance
  • Why a latency spike that matches compaction is a device cache flush

Every chapter closes with a Durability and Throughput Ledger covering throughput and latency ranges, read, write, and space amplification, and exactly how durability was verified.

Who it's for
  • Engineers building or maintaining embedded key-value stores, metadata services, message-queue persistence, time-series ingestion, or order journals
  • Teams that already have an engine and need it to stop losing data
  • Developers who know C++ and Linux systems programming and want the missing layer between fsync and a correct database
What you will be able to do
  • Specify durability per operation: process crash, kernel crash, or power loss
  • Order flush, compaction, and manifest installs so a crash at any point recovers to a valid prefix
  • Choose a compaction strategy from write-amplification and endurance arithmetic
  • Find tail-latency interference with stage timers, not flame graphs
  • Prove your crash tests can fail, using broken builds that must be caught
  • Run, back up, upgrade, and troubleshoot the engine in production
Inside the book
  • 15 chapters in 6 parts, plus 4 reference appendices
  • Complete C++23 listings with real syscalls and liburing, built to compile
  • On-disk format tables with offsets, versions, and checksums
  • A crash-consistency release checklist you can adopt as a gate

Share this book

Bundle

Bundles that include this book

Author

About the Author

Weston Ashgrove

Weston Ashgrove is a C++ systems engineer who builds software where being wrong or slow has a cost. He came up through quantitative trading, building order books, matching logic and the low-latency infrastructure underneath them and now brings the same discipline to performance engineering, concurrency, storage, networking, GPUs, and AI inference.

His rule for performance-critical code is simple: nothing is true until it has been profiled, fuzzed, and replayed. Every technique in his books comes with the measurement that proves it, the trade-off it costs, and the failure it prevents. He writes for working engineers who ship and debug production C++, and he leaves out anything that only works on a slide.

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub