# Real Databases, Simply (howdbswork.com) > How PostgreSQL, MySQL and MongoDB work in real systems: internals, side-by-side comparisons, measured lab > notebooks, and design docs that say which database each kind of application data belongs in, and why. Written by a database engineer. An MCP server for AI assistants: https://howdbswork.com/assistant/ ## Learn - [The course](https://howdbswork.com/course/): One order through the whole site: from one query to one server, to replicas, shards and whole system designs, with animated step-throughs, measured numbers and a quiz at the end of each lesson. Progress is saved in your browser. - [Short videos](https://howdbswork.com/videos/): Vertical videos of the step-throughs on this site, under a minute each: a query from app to disk, a missing index, random UUIDs, hash mod N, CAP, a failover, the dual write bug and more. - [Start here](https://howdbswork.com/start-here/): The basics: vocabulary, teams, runbook, one insert end to end, read, update, delete, crash, three scenarios, a quiz, and eight incident cards. - [Ten concepts](https://howdbswork.com/concepts/): Ten database concepts, one picture and one line each, told with books and shelves: index, normalization, join, transaction, ACID, deadlock, partitioning, sharding, replication, read replica. - [How a query travels](https://howdbswork.com/lessons/query-path/): Follow one UPDATE through a real database, step by step: the pooler, the backend process, the planner, the index, the buffer pool, the lock, the WAL flush at COMMIT, the replica and the checkpoint, with measured times. - [Database napkin math](https://howdbswork.com/lessons/napkin-math/): Estimate a table before you build it: row size, rows per page, table and index size, memory, WAL per day, commits per second and restore time, with rules of thumb measured on real PostgreSQL and MySQL. - [B-tree and LSM tree](https://howdbswork.com/lessons/storage-engines/): How the two storage engine designs handle the same insert: a B-tree changes the page where the key belongs, an LSM tree appends to memory and merges files later. Step-through animations, trade-offs, and which databases use which. - [Unique IDs at scale](https://howdbswork.com/lessons/unique-ids/): Sequences, UUIDv4, UUIDv7 and Snowflake IDs from the database side: what each does to a B-tree index, measured on one million rows in PostgreSQL 18 and MySQL 8.4. Random keys made MySQL inserts ten times slower. - [Consistent hashing](https://howdbswork.com/lessons/consistent-hashing/): How Cassandra, Redis Cluster, MongoDB and others decide which server holds a key, why hash mod N moves 75% of data when a server is added, and how token rings, virtual nodes and hash slots move only a share. - [CAP as settings](https://howdbswork.com/lessons/cap/): CAP from the database side: the same network split with MongoDB at w: majority and Cassandra at consistency ONE, step by step, and the setting in PostgreSQL, MySQL, MongoDB, Cassandra and Redis that makes the choice per write. - [Consensus and leaders](https://howdbswork.com/lessons/consensus/): How a database cluster agrees on one primary: Patroni and etcd step by step through a failover, the lease, the race, promotion and the old primary rejoining, and how MongoDB, MySQL InnoDB Cluster, Redis Sentinel and Cassandra do it. - [Sagas and the outbox](https://howdbswork.com/lessons/sagas-outbox/): How to keep data consistent across services without distributed transactions: why writing to the database and publishing an event separately loses events, how the transactional outbox fixes it, and how a saga undoes earlier steps with compensations. - [PostgreSQL](https://howdbswork.com/postgresql/): PostgreSQL internals: WAL, 8 KB pages, shared_buffers, MVCC and VACUUM. Files on disk, log files, outage parameters and commands. - [MySQL · InnoDB](https://howdbswork.com/mysql/): MySQL and InnoDB internals: .ibd files, redo log, binlog, buffer pool, undo and purge. Files on disk, log files, outage parameters and commands. - [MongoDB · WiredTiger](https://howdbswork.com/mongodb/): MongoDB and WiredTiger internals: .wt files, journal, oplog, cache and sharding. Files on disk, log files, outage parameters and commands. - [Redis](https://howdbswork.com/redis/): How Redis works: one thread, everything in memory, RDB snapshots and the AOF, asynchronous replication, and the big keys, hot keys and forks that break it. With measured numbers. - [Cassandra](https://howdbswork.com/cassandra/): How Cassandra works: a ring of equal nodes, the partition key, commit log, memtables and SSTables, consistency levels, tombstones, repair and compaction. With measured numbers. - [Vector databases](https://howdbswork.com/vector-databases/): How vector search works: embeddings, HNSW and IVF indexes, recall against speed, quantization, the filtered-search trap, and when pgvector is enough. With measured numbers. - [Engines side by side](https://howdbswork.com/compare/): Four everyday events, a write, a crash, a lagging replica and a long transaction, shown side by side for PostgreSQL, MySQL and MongoDB. - [Database families](https://howdbswork.com/families/): Ten families of databases, from B-tree row stores to LSM, column, in-memory, distributed SQL and vector search, and the traffic each one handles well. - [Queries that look fine and are not](https://howdbswork.com/queries/): Column order in an index, covering queries, OFFSET against keyset paging, and N+1, measured on PostgreSQL 18, MySQL 8.4 and MongoDB 8.0. - [Lost updates and write skew](https://howdbswork.com/isolation/): Two concurrency bugs, lost update and write skew, run as real interleaved sessions on PostgreSQL 18, MySQL 8.4 and MongoDB 8.0, with the fixes. - [Staff path, zero to architect](https://howdbswork.com/staff-path/): Zero to staff level in 6 levels: every concept as one problem plus one diagram, with labs on data pages, B+ trees and MVCC, and every idea on one card. ## Practice - [The daily](https://howdbswork.com/daily/): Three database questions a day, the same for everyone: guess a measured number, then two quiz questions from across the site. Keep a streak and share your result. - [Labs](https://howdbswork.com/labs/): Four small simulations: crash recovery, replica lag, a lock pile-up, and page counts for a scan against an index lookup. - [Watch an index grow](https://howdbswork.com/index-playground/): Insert rows into a B-tree and watch pages fill and split: sequential ids, random UUIDs and time-ordered UUIDs, in PostgreSQL, InnoDB and MongoDB. - [Guided tutorials](https://howdbswork.com/tutorials/): Three guided tutorials on a real PostgreSQL running in your browser: row versions, scan against index, and column order in an index. - [Lab notebooks](https://howdbswork.com/notebooks/): Ten experiments run on real PostgreSQL 18, MySQL 8.4, MongoDB 8.0, Redis, ClickHouse, Cassandra and pgvector, with the captured output: long transactions, commit cost, scans, concurrency anomalies, query shapes, design checks, other engines, agent memory, Redis and Cassandra under failure, and what the primary key costs on insert. - [Query coach](https://howdbswork.com/coach/): Paste a SQL query, and optionally the table definitions and an EXPLAIN plan. The coach lists what to look at, why, the fix, and the lesson that explains it. Runs in your browser. - [EXPLAIN reader](https://howdbswork.com/plan/): Paste a PostgreSQL, MySQL or MongoDB query plan and see it as a tree, with the slow step found and the usual causes named. Runs in your browser. - [Config checker](https://howdbswork.com/config/): Paste PostgreSQL, MySQL or MongoDB settings and see which are risky, which cost speed, and what to change. Runs in your browser. - [Health check](https://howdbswork.com/health/): Run a read-only script on PostgreSQL, MySQL or MongoDB, paste the output, and get a report: connections, cache, long transactions, bloat, unused indexes, replication, top queries and settings. ## Design - [Application designs](https://howdbswork.com/designs/): Fourteen design docs for common applications, with a picker: what kind of data goes in which database, and why. - [Design a URL shortener](https://howdbswork.com/lessons/url-shortener/): The classic system design exercise, from the database side: generating codes with a sequence and base 62, the links table, cache-aside reads from Redis and replicas, counting clicks without a hot row, napkin math for a billion links, and how it shards. - [System design, from one server](https://howdbswork.com/system-design/basics/): What system design means, the six things every design trades, one app growing from one database to many, four real failures, and what to choose for the problem you have. - [System design, at the database](https://howdbswork.com/system-design/): The 25 system design concepts every engineer hears, from the database side: load balancing, scaling, caching, replication, sharding, failover, disaster recovery and multi-region, with what breaks and the command to check. - [Data modeling basics](https://howdbswork.com/data-modeling/): Primary keys, types, constraints, normalizing and embedding, and deletes, for PostgreSQL, MySQL and MongoDB: the table design choices that are cheap on day one and expensive later. - [Store orders and inventory](https://howdbswork.com/designs/store-orders/): Orders, order lines, payments references and stock live in one relational database, PostgreSQL or MySQL. Carts can live in Redis. Product search goes to a. - [Payments and ledgers](https://howdbswork.com/designs/payments-ledger/): A relational database with a double-entry ledger that is append-only, with idempotency keys and synchronous replication. Correctness first, speed. - [Bookings and reservations](https://howdbswork.com/designs/booking-reservations/): A relational database with the rule enforced by the database itself: a unique constraint on (resource, slot), or an exclusion constraint on time ranges in. - [Accounts and sessions](https://howdbswork.com/designs/accounts-sessions/): Accounts in the main relational database. Sessions in Redis or Valkey with an expiry, or no server-side session at all if you use short-lived signed. - [Multi-tenant SaaS](https://howdbswork.com/designs/multi-tenant-saas/): Start with a shared schema and a tenant_id on every row, enforced by row-level security in PostgreSQL or by a mandatory filter in the data layer. Move. - [Product catalog](https://howdbswork.com/designs/product-catalog/): PostgreSQL with common columns plus a JSONB column for the varied attributes, or MongoDB with one document per product. A search engine on top for. - [Social feed](https://howdbswork.com/designs/social-feed/): Posts and the follow graph in a relational database. Timelines precomputed per user in Redis or a wide-column store (fan-out on write), except for. - [Search and AI retrieval](https://howdbswork.com/designs/search-ai-retrieval/): Start in PostgreSQL: full-text search and pgvector, next to the data. Move to a dedicated search engine or vector database when the size, the query rate,. - [Chat and messaging](https://howdbswork.com/designs/chat-messaging/): At small and medium scale, PostgreSQL with messages partitioned by time and indexed by (conversation_id, sent_at). At large scale, a wide-column store. - [IoT and telemetry](https://howdbswork.com/designs/iot-telemetry/): A time-series database (TimescaleDB, InfluxDB) or a column store (ClickHouse), with time partitioning, compression, downsampling and retention. Device. - [Audit and event logs](https://howdbswork.com/designs/audit-event-log/): An append-only table partitioned by time in the relational database, or a stream (Kafka) with a long retention plus a copy in object storage. Never. - [Leaderboards and counters](https://howdbswork.com/designs/leaderboards-counters/): Redis or Valkey: sorted sets for leaderboards, INCR with a TTL for counters and rate limits. Flush totals to the database in batches if they must be. - [Analytics and reporting](https://howdbswork.com/designs/analytics-reporting/): Not on the production primary. Copy data to a column store (ClickHouse, BigQuery, Redshift, Snowflake, DuckDB for small cases) through change data capture. - [Agent memory and state](https://howdbswork.com/designs/agent-memory/): Where an AI agent's conversations, checkpoints, tool calls and long-term memories go: PostgreSQL with pgvector for most of it, Redis for working memory, with measured recall and filter results. - [Anti-patterns](https://howdbswork.com/designs/anti-patterns/): Fifteen database anti-patterns: what you see, why it happens inside the engine, and what to do instead. - [Decisions](https://howdbswork.com/decisions/): Ten decisions a database engineer has to make, each with the price stated up front. PostgreSQL, MySQL and MongoDB, compared on the same decision. - [What a commit waits for](https://howdbswork.com/decisions/sync-replication-failover/): Synchronous replication and failover: what a commit waits for before it returns, and what that choice costs when a server dies. PostgreSQL, MySQL and MongoDB, compared. - [Design doc template](https://howdbswork.com/designs/template/): A copyable outline for a database design doc: workload, cost of a lost write, placement, model, durability, growth, failures, alternatives and cost. - [Submit a design for review](https://howdbswork.com/designs/review/): Send a database design for review, in public as a GitHub issue or in private, and the questions every review asks. ## Operate - [Something is slow or broken](https://howdbswork.com/symptoms/): On-call runbooks for databases: too many connections, CPU at 100%, disk filling, replica lag, lock waits, a query that got slow and more. Where to start, then each step with the commands for PostgreSQL, MySQL and MongoDB, plus Redis, Cassandra and pgvector. - [Where to run the database](https://howdbswork.com/designs/hosting/): On-prem, self-managed on VMs or EC2, managed cloud, serverless, vendor services or Kubernetes: who does what, the full cost, and where to run each kind of application. - [On-prem vs cloud, by engine](https://howdbswork.com/cloud/): On-prem vs cloud for PostgreSQL, MySQL and MongoDB: what RDS, Aurora, Cloud SQL and Atlas take over, what the DBA still owns, and the tradeoffs. - [Capacity calculator](https://howdbswork.com/designs/capacity/): Estimate data size, working set, memory, disk and log volume for a table, with every assumption stated. - [Why the bill is huge](https://howdbswork.com/decisions/cost-model/): Where a database bill comes from, six patterns that inflate it with a query to find each, and a safe order for cutting it. - [Connection pooling](https://howdbswork.com/decisions/connection-pooling/): How many database connections you need, what each costs in PostgreSQL, MySQL and MongoDB, where PgBouncer, ProxySQL or RDS Proxy fit, and the pool-size arithmetic. - [Backups and restore time](https://howdbswork.com/decisions/backup-restore/): How to back up PostgreSQL, MySQL and MongoDB so you can restore to any moment: physical backups, log archiving, PITR, restore-time arithmetic and what breaks. - [Security](https://howdbswork.com/security/): Database security in five layers for PostgreSQL, MySQL and MongoDB: network, encrypted and authenticated connections, least-privilege roles, backups and dev copies, and auditing, with the commands to check each. - [Migration playbooks](https://howdbswork.com/designs/migrations/): Four migration playbooks: add change data capture, split a database, move from MySQL to PostgreSQL, and add a cache, each with checks and a way back. - [Major version upgrades](https://howdbswork.com/decisions/major-upgrades/): How to upgrade PostgreSQL, MySQL and MongoDB major versions: pg_upgrade, logical replication, newer replicas, rolling upgrades, feature compatibility, and what breaks afterwards. - [What changed in the latest releases](https://howdbswork.com/releases/): What operators need to know in PostgreSQL 18, MySQL 8.4 LTS and MongoDB 8.0: changed defaults, upgrade breakers, and new features worth using. - [On call tonight](https://howdbswork.com/oncall/): Three branching database incidents: a disk filling up, checkout timing out, and a replica far behind. Pick what to check, and see why it was a good or bad call. - [Real failures](https://howdbswork.com/stories/): Nineteen real database incidents from Uber, GitHub, Notion, Slack, Shopify, Adyen, Figma, Dropbox, Epic Games, GitLab, Instacart, Discord and Instagram, each with the numbers, the fix, and the lesson. Plus a diagram per story. - [Cheat sheet](https://howdbswork.com/cheat-sheet/): Each engine in 8 rules: PostgreSQL, MySQL/InnoDB and MongoDB/WiredTiger: one rule, one plain line, one diagram, with deep-dive links. - [Reference: plans, logs, checklist](https://howdbswork.com/reference/): Quick lookup: side-by-side engine comparison, annotated EXPLAIN output, the log-file pattern and failure modes, and the DBA checklist. ## About - [About](https://howdbswork.com/about/): Who wrote this site and why: a production database engineer on PostgreSQL, MySQL, MongoDB and Aurora, and how to use the site from zero to staff level. - [Corrections](https://howdbswork.com/corrections/): Every correction that changed what a page on this site teaches, with the date, what it said and what it says now. - [Reading list](https://howdbswork.com/references/): Books, tools and posts this site leans on, with one line each on what each is best for and which pages it backs. - [Work with me](https://howdbswork.com/work-with-me/): A database health check for PostgreSQL and MySQL, and a review of the database side of AI agent systems: durability, performance, cost, safe access and memory, written up and ranked by risk. - [Use it from your AI assistant](https://howdbswork.com/assistant/): Use this site from Claude, Cursor or any MCP client: which database for an application, sizing estimates, and lessons, answered from the design docs. - [All pages](https://howdbswork.com/sitemap/): Every page on the site in seven sections, in reading order: Learn, Engines, Practice, Design, Get it right, Run it, About.