Writing
Notes on systems, databases, and things I've had to fix at 2am.
My database lost every committed write, and one test found it
PyDB had a write-ahead log, fsync on every commit, and a README promising crash recovery. The first time I killed it mid-workload, 50 committed rows came back as zero.
ReadRow-level security: the tenant check you can't forget
Cross-tenant leaks come from one missing WHERE clause. PostgreSQL can enforce the check for you, if you avoid the quiet ways row-level security switches itself off.
ReadAlerting on something that didn't happen
An AI camera can tell you someone climbed a fence. It can't tell you the guard never walked past. Timers over missing events: late messages, restarts, one alert per lapse.
ReadAdd one server, move 90% of your keys
hash(key) % N falls apart the moment N changes. Measured numbers from a consistent-hash ring, virtual nodes, and why the hash function matters more than you'd expect.
ReadBuilding a B-Tree Storage Engine From Scratch
Why I built a database instead of using one: pages, a pager, a B-Tree, splits, and a Write-Ahead Log, all from first principles.
ReadWe were polling our own database to death
Every dashboard hit the API every three seconds asking 'anything new?'. Swapping polling for WebSockets and Redis Pub/Sub cut backend traffic by 80%.
ReadExactly-once is mostly a marketing slide
A deploy blipped and some tax records got processed twice. Here's how I stopped chasing 'exactly-once' and built consumers that just don't care about duplicates.
Read53 endpoints, one lazy loop, 15.6 seconds
One page took 15.6 seconds to load. It wasn't a slow query. It was 101 fast ones. A short story about the N+1 problem and counting your round trips.
ReadTwo requests, one row, and a lost update
Two people saved the same record a second apart and one edit silently vanished. On the lost-update race, optimistic concurrency, and when to reach for a distributed lock.
ReadYour retry logic is a small DDoS you wrote yourself
A downstream service hiccuped for thirty seconds. Our retries turned it into a four-minute outage. On backoff, jitter, knowing when to quit, and the dead-letter queue.
Read