— Writing —

All writing

Database · 9 articles
DatabasePicking the Right DB·15 min read

How Redis Actually Deletes Expired Keys — The Lazy + Active Hybrid You Didn't Know About

A senior-engineer walkthrough of how Redis really handles TTLs. Why TTL=0 doesn't free memory. The two strategies — lazy (on-access) and active (the random-sample-and-25%-threshold sampler). The hz parameter, active-expire-effort, lazyfree-lazy-expire. DEL vs UNLINK and why big-key expiry used to pause the event loop. How replicas handle expiration via the replication stream. maxmemory + eviction policies as the actual safety net. The metrics from INFO that tell you when the sampler is falling behind.

DatabaseRedisCachingTTLRead →
Database·Picking the Right DB

LSM Trees, the Deep Cut — MemTable, WAL, SSTables, Compaction and Why Your Writes Are So Fast

A senior-engineer walkthrough of Log-Structured Merge Trees: MemTable + WAL durability, SSTable layout with sparse index and bloom filters, the L0→Ln level hierarchy, leveled vs tiered vs FIFO compaction, the three amplifications (write/read/space), bloom filter math, and the RocksDB and Cassandra tuning knobs that actually matter. Why RocksDB, LevelDB, Cassandra, HBase, ScyllaDB, ClickHouse and TiKV all picked it — and when you should not.

DatabaseStorage EngineLSM Tree22 min read·
Database·Query Optimization

"Push It All on the Database" — The Lie That Works Until It Doesn't

Every team ships with the same lie: throw everything on the database and it'll handle correctness. Works at 50 writes/sec. At 5,000 writes/sec, every FK is a lock queue, every cascade synchronously deletes thousands, fsync becomes the clock. Why staging never catches it, ten places where the bill shows up, the cost curve of a hot FK, why cascades are dangerous, how to diagnose your bottleneck, and the enforcer+checker pattern senior teams use to move constraints off the database without losing correctness.

DatabasePerformanceMySQL18 min read·
Database·Schema Design

UUID v4 vs UUID v7 vs Snowflake — Pick the Right Primary Key

A plain-English walkthrough: how B-tree inserts actually work, what a page split costs, why random UUID v4 keys bloat the index by 2× and blow the buffer pool. For each ID — UUID v4, Snowflake, UUID v7, AUTO_INCREMENT — what it is, why people pick it, what breaks. Real MySQL benchmark at 10M rows, Postgres differences, and a dual-write migration that works.

DatabaseMySQLPostgreSQL14 min read·
Database·Performance

Connection Pool Sizing: The Math Behind Why Your App Is Slow

Why your connection pool config is probably wrong — and how to fix it with Little's Law, Kingman's Formula, and the process-to-core ratio. Includes a real-world banking system that had 640 connections but only needed 5.

DatabasePerformanceConnection Pooling14 min read·
Database·Schema Design

Stop Using DELETE in Production: Hard Delete vs Soft Delete in High-Concurrency Systems

Why DELETE is the most expensive DML operation in a relational database — and why a simple UPDATE SET deleted_at = NOW() is 4-8x faster under concurrent load. With InnoDB internals, B-tree diagrams, and benchmark numbers.

MySQLPostgreSQLPerformance12 min read·
Database·Query Optimization

Why Your Indexes Aren't Working: Non-SARGable Queries Explained

A deep-dive into non-SARGable SQL with B-tree diagrams, real EXPLAIN output, and the exact rewrites — told through a gaming dashboard that went from 4,200ms to 2ms without touching the schema.

MySQLPostgreSQLNode.js18 min read·
Database·Query Optimization

Vector Search Explained: From KNN to HNSW — A Complete Guide

How similarity search works under the hood — and why naive brute-force collapses at scale.

SearchML13 min read·
Database·Query Optimization

MySQL Query Optimization: Real Lessons from a 36GB Index Disaster

What happens when your index outgrows your data — and how we fixed it without downtime in production.

MySQLProduction5 min read·
Writing — realproblem.me