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...
Build a Crash-Proof Storage Engine in Pure Python: Append-Only Log, B+Tree, WAL, LSM Tree, Bloom Filters, MVCC, and SQL
Build a crash-proof database from scratch in pure Python: append-only log, B+tree, WAL, LSM tree, Bloom filters, MVCC, and SQL, tested against a seeded crash disk with 85 passing tests.
Minimum price
$19.99
$29.99
About the Book
You use PostgreSQL, SQLite or Redis every day. You have heard "write-ahead log", "B-tree" and "MVCC" in interviews and incident reviews. This book builds each one, in plain Python, on a simulated disk that loses unsynced writes and tears the last one when the power is cut.
Because the power cuts are seeded, a lost row that once took a real outage to find becomes a failing seed you can paste into a test. You build an append-only log, a hash index, fixed-size pages, a B+tree, a write-ahead log, copy-on-write pages, an LSM tree, Bloom filters, transactions, MVCC with snapshot isolation, and a small SQL engine. Every chapter ends with a Pull the Plug sweep over seeds and crash points, and a deliberate bug the sweep catches.
Every listing is printed in full and was run and tested on Python 3.14 and 3.15 (85 tests, also passing on 3.12 and 3.13). The SQL chapters are checked against the sqlite3 module in Python's standard library. It is a teaching engine, not a fast one, and the book says so.
What you'll builddisk.py) with durable and pending bytes, torn writes, durable names and replayable power cutsWorking Python developers with 3 to 15 years of experience who want to understand where data really lives, for a system design interview or the next "where did my data go" incident. No hype, no frameworks, no diagrams without code.
Table of contentsPart I. Pull the Plug
Part II. Trees on Disk
Part III. Fast Writes, Clever Reads
Part IV. Transactions
Part V. Speaking SQL
All 34 Python files are printed in full in the book and included as downloadable Leanpub Extras. Standard library only, plus pytest.
How this book was madeThis book was drafted with AI assistance from an outline, a fixed simulated disk and a source list chosen by the author, then edited. Every listing was extracted from the manuscript and run and tested on CPython 3.14.10 and 3.15.2, and the suite also passes on 3.12.15 and 3.13.5. Every measured number comes from those runs. Every paper and document named was checked against its primary source in December 2026. The incidents are invented and labeled as such.
Also by A. C. WeishauptIf you enjoy building core systems from scratch in Python, check out Kill the Leader (distributed consensus, Raft, gossip, and CRDTs in pure Python) and Promoted to Babysitter.
Bundles that include this book
About the Author
A. C. Weishaupt writes from Europe with a humble devotion to the long craft of publishing many books - some reached international Amazon Top 100 placements.
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
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
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
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.