← Questions

Design a migration from a relational database to NoSQL

0
GoogleSystem designLast asked Sep 2025

A system design interview question asked in Google's first round (coding), last asked Sep 2025. It tests data migration, change data capture and consistency.

A live service must move its data from a relational database to a NoSQL key-value store. Design the pipeline: a one-time consistent snapshot that turns each row into a {primary_key: value} JSON document, followed by change data capture (CDC) from the write-ahead log so updates keep flowing until cut-over. Explain snapshot consistency, how the snapshot and CDC are ordered together, idempotency, exactly-once results across replays, schema changes during the migration, catch-up after the backfill, and failure recovery, with the queueing, partitioning and monitoring.

Requirements

  • Functional: copy every table's rows into the target as documents keyed by primary key; apply inserts, updates and deletes from the log in order per key; verify the copies match; switch reads, then writes, to the new store; roll back if needed.
  • Non-functional: no downtime and no lost or reordered updates per key; minimal extra load on the production database; the pipeline can be stopped and resumed at any point.

Clarifying questions

  • How much data, how many tables and how high is the write rate?
  • Does the target model one row per document, or should related rows be denormalised into one document?
  • Which database and log format (Postgres logical replication, MySQL binlog)?
  • How long may the migration take, and can writes be paused for a moment at cut-over?
  • Will the schema change while the migration runs?

What a strong answer covers

  • Snapshot consistency: start a CDC slot first and record its log position, then take the snapshot in one repeatable-read transaction (or per-chunk with watermarks), so every change after the snapshot is in the log.
  • Ordering: CDC events partitioned by primary key into a queue (for example Kafka), so per-key order is kept while different keys run in parallel.
  • Idempotency and exactly-once results: each document stores the log position (LSN) of its last applied change, and writes are conditional ("apply only if newer"), so replays and overlap between snapshot and CDC are harmless. Deletes as tombstones with positions.
  • Catch-up: the snapshot loads in parallel chunks while CDC buffers; then CDC drains the backlog; lag is the metric that tells when cut-over is possible.
  • Schema evolution: versioned transforms, a schema registry, and handling added or renamed columns mid-stream.
  • Verification: row counts and checksums per key range, sampled deep comparisons, and shadow reads that compare old and new answers in production.
  • Cut-over: dual reads, then switch reads; for writes, a brief freeze or a dual-write period with the old store as source of truth; a reverse CDC pipeline for rollback.
  • Failure recovery: consumers commit offsets after applying; restart from the last committed position; dead-letter queue for bad records; monitoring of lag, error rate and mismatch counts.

Follow-ups

  • Related tables must be merged into one document (an order with its line items). How do you keep that consistent when the parts change separately?
  • The log retention runs out before the snapshot finishes.
  • How would you migrate with zero write freeze at all?

Where it's asked

  • Google · First round: coding · Last asked Sep 202545 min · Coding in a Google Doc, no syntax highlighting or autocomplete · No AI

What it tests

data migration · change data capture · consistency

Your canvas
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing