KatInterview

Live Move of a 2TB SQL Server Database to PostgreSQL

System DesignModel answer
HardModel answerSystem Designdatabase-migrationcdczero-downtime

Last updated

Plan a no-downtime move of a busy 2TB SQL Server database to PostgreSQL, covering sync, type mapping, verification, cutover and rollback, with a read-only vendor client you cannot change.

Scenario

Your team runs a core production database on Microsoft SQL Server and wants to move it to PostgreSQL. The database holds roughly 2 TB and takes heavy write traffic during business hours.

Two clients depend on it:

  1. An internal service that writes transactions continuously. You own its code, but you want to avoid large changes to its business logic.
  2. A third-party analytics tool that only reads. Its vendor cannot realistically change its code or make it query more than one database. You may only influence where it connects.

Goals

  • No user-visible downtime during the move.
  • Strict consistency: no lost, duplicated or reordered transactions.
  • A tested way to go back if PostgreSQL misbehaves after the switch.
  • Both databases stay in sync for the duration of the migration.
  • The vendor's tool ends up reading from PostgreSQL without any vendor-side code change.

What to deliver

  1. A high-level architecture and migration path. Compare options such as change data capture, application-level dual writes and logical replication, and justify your choice.
  2. A strategy for mapping data types and handling logic differences between the engines, including stored procedures, triggers, identity columns and collation.
  3. A way to continuously verify that the two databases hold the same data, and to keep replication lag small.
  4. A step-by-step cutover plan with preconditions, and a rollback plan for failures after the cutover.

State any assumptions you make, such as peak transaction rate and what "zero downtime" means in practice.

Hints

Hint 1

Size the problem first: at a realistic copy speed, how long does moving 2 TB take, and what happens to writes in the meantime? That tells you a one-off copy is not enough.

Hint 2

Dual writes from the application cannot be atomic across two engines. Consider reading the source's transaction log instead, and make the applier on the target idempotent.

Hint 3

The vendor can't change code, but it can change a connection string or DNS name. Think about a stable endpoint you control, and about which protocol the vendor speaks.

Hint 4

A rollback is only real if data keeps flowing in the opposite direction after cutover. Plan reverse replication and rehearse it.