Skip to main content
Databases

Databases Tutorial with Examples.

Database tutorial for developers: design, query and operate modern databases, from schema design and indexing to transactions and performance.

Intermediate

For developers with core concepts down

2 lessons

Advanced

Production-grade patterns for experienced engineers

4 lessons

Also part of Databases

Taught in other topics. Each link opens the lesson in its home topic.

12 lessons
sql intermediate
5 min read

Design relational schemas with real PostgreSQL output: an update anomaly and its fix, junction tables, soft deletes, and UUID vs BIGINT keys.

postgresql intermediate
5 min read

Indexing a low-selectivity column barely moves the needle — 13ms to 13ms — while indexing a high-selectivity one drops a query from 14ms to 1ms. Selectivity, not the presence of an index, is what determines the payoff.

mysql intermediate
5 min read

Filtering by genre and sorting by year: a single-column index still needs a manual sort afterward (2.87ms). A composite index on both columns delivers pre-sorted results — measured 21x faster, and the Sort step vanishes from the plan entirely.

sqlserver intermediate
5 min read

Forcing SQL Server to use a nonclustered index costs 217 logical reads -- worse than the 40-read scan it was supposed to beat -- because every matching row needs a separate key lookup. INCLUDE fixes it at 4 reads.

postgresql intermediate
5 min read

One error inside a transaction poisons every statement after it until ROLLBACK — and two transactions locking the same two rows in opposite order produces a real 'deadlock detected' error, not a hang.

mysql intermediate
5 min read

Under MySQL's default REPEATABLE READ, a transaction reads the same value twice even after another session commits a change in between. Switch to READ COMMITTED and the second read sees the new value — a real, measured non-repeatable read.

sqlserver intermediate
5 min read

READ UNCOMMITTED reads an uncommitted price change mid-transaction -- then the transaction rolls back, and the value never really existed. The default READ COMMITTED blocks instead, confirmed with a real timeout.

mysql advanced
5 min read

A real primary-replica setup, checked with SHOW REPLICA STATUS instead of assumed — plus a genuine surprise: read_only alone does not stop root from writing to a replica.

mongodb advanced
5 min read

docker kill the primary node of a real 3-node replica set and time exactly how long the cluster takes to elect a new one from container logs and MongoDB's own timestamps — 9.01 seconds, closely matching the documented default election timeout.

postgresql advanced
5 min read

A base backup plus archived WAL segments can restore a database to the exact second before a mistake — but only if the WAL covering that second was actually archived first, which is the real failure this lesson walks through.

mysql intermediate
5 min read

A real mysqldump, a real DELETE with no WHERE clause, and a real restore — which undoes the mistake but also erases legitimate work done after the backup, exposing exactly what a full logical restore can't do alone.

system-design advanced
5 min read

A write acked by W replicas and a read from R only guarantee overlap when W plus R exceeds the replica count -- otherwise a read can miss the latest write.