Interview: the CTO read a blog post and wants to move Postgres to MySQL

Decide whether to migrate Postgres to MySQL: heap vs clustered index, vacuum vs undo purge, what breaks, and when not to. The blog’s speed claim has no…

More on Ticket interviews

Keep learning

Overview

In simple words, where does a row live in Postgres and in MySQL? explain simply Postgres: a loose pile (heap). MySQL: a tree sorted by primary key. Postgres indexes store the row’s address (page and slot). One jump to the row. MySQL indexes store the primary key. A second tree walk finds the row. Neither is simply faster. Each puts the cost somewhere else. heap vs clustered secondary index holds the key a trade, not a winner What breaks if we copy our UUID primary keys and jsonb columns over as they are? what breaks if They load fine, but indexes bloat and JSON queries change. InnoDB copies the primary key into every index. VARCHAR(36) is over twice BINARY(16). Random UUIDs split pages all over the tree. Time-ordered ids append at the end. MySQL has JSON, not jsonb. Re-test every JSON query. key copied into every index random keys split pages test every query The post says MySQL is typically more performant. How do you check that for us? Replay our own traffic on both engines, against a pass mark set first. The article has no numbers. Treat it as a hunch. Compare p50 and p99 latency, peak throughput and replica lag, not one average. Add cost: servers, disk, engineer-weeks. Small wins rarely pay for a move. hunch vs evidence our own workload tail latency pass mark first We hate vacuum bloat. Does MySQL make that go away? No. It moves the chore from VACUUM to undo purge. Postgres keeps old versions in the table. InnoDB keeps them in undo (old-version log). Both stall behind the oldest open transaction. Same fix: short transactions, idle-in-transaction timeouts, reports on a replica. the chore moves oldest transaction blocks both same fix: short transactions What would you try before changing engines? what would you do instead Name the pain, then try the cheap fixes for that pain. Bloat: tune autovacuum, set fillfactor for in-page (HOT) updates, drop unused indexes. Load: move reports to a replica, or buy a bigger machine. Need sharding? Compare layers on both sides (e.g. Vitess for MySQL). diagnose first cheap fixes migrate with evidence You decided to go. How do you cut over 800 GB with an escape hatch? Copy, stream, compare, flip, and keep syncing backwards. First list the work: types, triggers, functions, extensions, names, TRUNCATE. Shadow-read both engines. Fix date, order and NULL differences. Retire Postgres only after a clean month-end. snapshot plus stream compare reads reverse sync for rollback wait before decommission You gain It costs Pick when Avoid when Stay on PostgreSQL and fix the pain No data move. Everything keeps working. You must find the real cause. No proof the engine is the problem. You tuned it already and measured a ceiling. Big-bang move (stop, copy, switch) Simple plan, one cutover. Downtime grows with data. No way back. Small data, outage is fine. Large data, uptime promise, Postgres-only features. Phased move (copy, sync, compare, flip) Tested on real traffic. You can flip back. Weeks of work, two systems to run. Large data, no outage allowed. Tiny team, no time for sync tooling. New service on MySQL, old one stays Low risk. Learn MySQL on something small. Two databases, two skill sets, joins in app code. A real reason: team skill or MySQL sharding. You want one database for everything. What can we measure? A blog post is not data. Types, triggers, views, functions, extensions. Replay real traffic. Pass mark first. Cheaper first Vacuum, indexes, replicas. If yes Phased move with a way back. Blog as benchmark The article shows no numbers. One-to-one type mapping VARCHAR(36) UUIDs bloat every index. Forgot in-database code Triggers, functions, materialized views. No way back Cutover planned, rollback not. Heap vs clustered in two sentences Named three things that break VACUUM ≈ purge, same long-txn trap Cheaper fixes before migrating Phased cutover with a way back Left: a warehouse where boxes sit on shelves in arrival order and a card catalogue says which shelf holds each box. Right: a cabinet whose drawers are sorted by box number. In the middle a truck carries the boxes, with the note that moving means repacking, relabelling and retraining. Postgres: the warehouse boxes where there was room the truck repack every box relabel · retrain staff MySQL: the sorted cabinet the box itself sits in its sorted drawer Is the new building better for your shop? Only your own measurements can say. Read a row by email Update a column nobody indexed Change the email itself Walk the email index. It stores an address: page and slot. Jump straight to that heap page and read the row. Walk the email index. It stores the primary key, not an address. Walk the primary key tree. The row sits in the leaf. Same job, different shape. A direct address saves a lookup but must change when the row moves. Going through the primary key adds a lookup but survives moves. Write a new version of the row. Best case it lands on the same page (a HOT update). No index changes. The old version stays as a dead row until page pruning or VACUUM removes it. Change the row in place in the primary key tree. Copy the previous version into undo. Purge deletes it later. Both keep the old version for readers who still need it, and both clean up later. Postgres cleans the table (VACUUM). InnoDB cleans undo (purge). Write a new row version in the heap. It cannot be HOT. Every index gets a new entry pointing at the new version. The old version waits for VACUUM. Change the row in place. The previous version goes to undo. Only the email index changes: old entry delete-marked, new entry added. Other secondary indexes stay as they are. They hold the primary key. Postgres loses its HOT shortcut and touches every index. InnoDB touches only the index on the changed column. That is why dropping an unused index helps update-heavy Postgres tables. index on email key → (page, slot) rows in arrival order dead rows wait for VACUUM other indexes also (page, slot) MySQL (InnoDB) key → primary key primary key tree rows live in the leaves older versions, purged later also hold the key One row, one operation, two engines jsonb columns MySQL has JSON, not jsonb. You can still index JSON values and update parts of a document. Re-test every JSON query. UUID primary keys The article maps UUID to VARCHAR(36). Better a short binary or time-ordered key: InnoDB copies the primary key into every index. Postgres extensions Audit each one. Some types have no equal. Spatial data (POINT) uses a MySQL binary format and needs ST_AsText() to read. Materialized views MySQL has none. Rebuild each as a table that a job refreshes. INSTEAD OF triggers MySQL has only BEFORE and AFTER triggers. Move that logic. Functions in Python or JS MySQL routines are written in SQL. Rewrite them. SERIAL ids, VARCHAR with no length SERIAL becomes BIGINT UNSIGNED AUTO_INCREMENT. VARCHAR needs a length (or TEXT). Check both against real row counts. Quoted mixed-case names Postgres treats "Name" and name as different. MySQL names are not case-sensitive, so look for clashes. Tests that TRUNCATE inside a transaction MySQL TRUNCATE cannot be rolled back and has no CASCADE or RESTART IDENTITY. We measured a problem tuning could not fix The only reason that counts alone. We need a sharding layer built for MySQL The article points to Vitess and PlanetScale. Our team already runs MySQL well Real, but about people, not speed. Vacuum bloat hurts and we already tuned it MySQL has the same chore: undo purge. A blog post said MySQL is faster The article shows no data. Worth nothing. Do not migrate yet. Nothing here is a measured problem. Find the pain first and try the cheaper fixes. The proof outweighs the work. Plan a phased migration with a way back. Close call. Prototype the hardest item on the list, then decide. The work is bigger than the proven gain. Fix Postgres first. Tick what is true for you (scores are illustrative) What does our app use? Why do we want to move? Proof of pain Work to move What to notice: the blog post adds no points. Only a measured problem opens the door, and then the work list decides how wide. Bar chart of primary key size copied into each InnoDB secondary index entry: a 36 character text uuid is about 36 bytes, a binary uuid is 16 bytes, a bigint is 8 bytes. Bytes of primary key repeated in every secondary index entry Plain ASCII text assumed. Three secondary indexes means the key is stored four times: once in the tree, three times in indexes. v1 dead can go v2 dead v3 live Two lanes. PostgreSQL keeps old row versions in the heap and VACUUM removes them. InnoDB keeps old versions in undo and purge removes them. In both lanes, cleanup stops at the oldest open transaction, so versions newer than that point are kept. PostgreSQL: old versions in the table, VACUUM removes InnoDB: newest row in the tree, older ones in undo, purge removes row (newest) undo v2 undo v1 oldest open transaction started at the dashed line cleanup cannot pass it Work list types · code · names keep in sync shadow reads quiet window Way back sync in reverse Cutover steps in order Postgres heap Index → (page, slot) → row. One jump, but moves update every index. InnoDB clustered Index → primary key → PK tree → row. Two walks, survives moves. a real day Set pass mark before testing both engines p99 · lag · cost Autovacuum, fillfactor, drop unused indexes, pg_repack. Report load Send reports to a read replica. Long transactions Idle-in-transaction timeout. Bigger box, or compare sharding layers.

The CTO read a blog post and wants to move Postgres to MySQL

A blog post says MySQL is usually faster, with no numbers. Turn that hunch into a real decision. heap vs clustered index vacuum vs purge type mapping phased cutover when not to migrate The CTO wants a migration date based on a blog post. Measure our own workload, try cheap fixes, then decide.

A shop that might move

Your shop works from a warehouse. Boxes sit wherever there was room, and a catalogue says which shelf holds each one. A friend says the shop across town, with a cabinet sorted by box number, is usually faster. They show no proof. Moving means repacking every box, relabelling every shelf, and teaching the staff new habits. Move only if the old warehouse hurts for a reason you can measure.

Move the main database from PostgreSQL to MySQL?

A blog post says MySQL is usually faster. No benchmark. Nobody has named a slow query, cost problem or missing feature. The CTO wants a date for the move. 800 GB (illustrative) jsonb tables measured problem none yet Restated: this is a decision, not a task. The answer is a plan to find out, not a date.

What each engine does, and what the move costs

Play with both. The first shows why the engines are not simply faster or slower. The second shows how a decision should be weighed.

Four ways to answer the CTO

Four ways to answer the CTO, with gain, cost and fit. The CTO wants a date. What do you bring to the meeting? A plan to measure first: replay our real queries on both engines and list what breaks A blog post becomes an experiment. You migrate with proof, or save months. Chance of regret Time before a decision Approve a phased migration now, with a way back The safe way to move, but you pay weeks before learning if it helps. Trust the post and cut over on a weekend No data says it is faster. Breakage is found live, with no quick way back.

More courses

  • Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
  • Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
  • React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
  • System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
  • NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
  • Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
  • Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
  • AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
  • Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
  • TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
  • CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
  • Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
  • Docker — What an image is, why layers cache, and how containers find each other on a network.
  • Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
  • Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
  • AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
  • Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.