TodayILearned
Databases lessons
One fullstack engineering concept every day โ taught deeply, then compressed into a public post.
Why does an index speed up a query?
And the part nobody mentions: when it actually makes things worse.
Reading EXPLAIN output
How to see what the database is actually doing โ and whether your index is being used.
Composite indexes โ the leftmost prefix rule
When you index multiple columns, order matters. Here's why โ with a real benchmark.
Connection pooling โ sharing database connections
Every database connection is expensive. A pool keeps a few warm and reuses them โ the load balancer's cousin, one layer deeper.
Transactions and ACID โ when all or nothing is the point
A connection pool gives you a connection. A transaction is what you do inside it โ a unit of work that either fully succeeds or fully fails.
Database normalization โ 1NF, 2NF, 3NF
Three normal forms, three problems they solve. Normalization prevents anomalies; denormalization trades safety for speed.
JOINs โ when two tables become one
Normalization split your data into honest tables. JOINs stitch it back together โ at a cost. The planner picks the algorithm, but you control the indexes that make it fast.
Keyset Pagination โ Why OFFSET Breaks at Scale
Your API returns page 500 in 50ms. Page 5000 takes half a second. Page 10000 takes two seconds. The user is just clicking 'next page' โ so why does each page get slower? The answer is OFFSET, and the fix is a cursor.
Covering indexes โ when the index is enough
An index finds rows fast. A covering index returns the data too โ PostgreSQL skips the table entirely. Heap Fetches: 0 is the magic line in EXPLAIN.