MySQL
MySQL is an open-source relational database, owned by Oracle and also available in compatible forks like MariaDB and Percona Server. Like Postgres, it stores rows in tables, speaks SQL and supports ACID transactions. It has powered a huge share of the web for decades, and several of the largest consumer apps were built on heavily sharded MySQL.
The properties that matter most:
- Relational and transactional: tables, indexes, joins, constraints and transactions, through the InnoDB storage engine (the default since MySQL 5.5).
- Pluggable storage engines: MySQL separates the SQL layer (parsing, optimizing, replication) from the engine that stores data. InnoDB is what you'll use. MyISAM is a legacy, non-transactional engine, and MyRocks (an LSM-tree engine built on RocksDB) exists for write-heavy, space-sensitive workloads.
- Replication-first operations: MySQL's binary log and its simple, robust replication have made it a favorite for read-heavy web workloads, and they're the foundation of the ecosystem's tooling for failover, online schema changes, change data capture and sharding.
In interviews, MySQL and Postgres are mostly interchangeable as "the relational database." Interviewers care that you know what a relational database guarantees and how it scales. But if you name MySQL, you should know the things that make it different: rows are stored inside the primary key index, the default isolation level behaves differently, and the sharding story usually means Vitess.
The Data Model: Everything Is a Primary Key Index
The biggest structural difference between InnoDB and Postgres is how rows are stored.
In InnoDB, a table is a B+tree keyed by the primary key, called the clustered index. The leaf pages of that tree hold the full rows, sorted by primary key. There's no separate heap of rows. If you don't declare a primary key, InnoDB uses the first non-null unique key, or invents a hidden 6-byte row ID.
Secondary indexes don't point at a physical row location. Their leaf entries store the indexed columns plus the row's primary key value. So a lookup by a secondary index is two tree searches: find the primary key in the secondary index, then find the row in the clustered index.
That design has consequences you can use in an interview:
- Primary key lookups and range scans are very fast.
WHERE user_id = ? ORDER BY idover a primary key of(user_id, id)reads rows that are physically adjacent on disk. - The primary key's size matters. Every secondary index entry carries a copy of it. A 16-byte UUID primary key makes every secondary index bigger than an 8-byte
BIGINTwould. - Random primary keys hurt writes. Inserting random UUIDv4 keys lands each row in a random page of the clustered index, which causes page splits, half-empty pages and a working set that doesn't fit in memory. Sequential keys (auto-increment, Snowflake-style IDs, or time-ordered UUIDv7) append to the right edge of the tree instead.
- Covering indexes are powerful. If a secondary index contains every column the query needs (including the primary key, which it gets for free), InnoDB answers from the index alone, shown as "Using index" in
EXPLAIN.
CREATE TABLE messages (
channel_id BIGINT NOT NULL,
message_id BIGINT NOT NULL, -- time-ordered ID from an ID service
author_id BIGINT NOT NULL,
body TEXT NOT NULL,
created_at DATETIME(3) NOT NULL,
PRIMARY KEY (channel_id, message_id), -- rows for a channel are stored together, in order
KEY author_idx (author_id, created_at)
) ENGINE=InnoDB;
-- Latest 50 messages in a channel: one range scan over adjacent rows
SELECT * FROM messages WHERE channel_id = ? ORDER BY message_id DESC LIMIT 50;
A good, concrete detail to offer: "In InnoDB the primary key is the physical row order, so we'll use a composite key
(channel_id, message_id)with time-ordered IDs. That makes 'recent messages in a channel' a single sequential range read." It shows you're designing the schema around the access pattern, not just listing columns.