KatInterview

Should We Move Off MySQL? Assessing a Document Database Migration

System DesignModel answer
MediumModel answerSystem Designdatabasesmigrationmongodb

Last updated

Decide whether replacing MySQL with MongoDB makes sense for a live service by analyzing workload evidence, correctness needs, and a safe dual-run cutover plan with measurable proof.

You lead the backend of a customer-facing service that has run on MySQL for several years with no major incidents. Another engineer proposes rewriting the storage layer on MongoDB, arguing it will "scale better" and that the flexible document model fits the service's JSON-heavy API responses.

You are skeptical but open-minded. Your task:

  1. Frame the decision. What evidence would you gather about the current workload before taking the proposal seriously? What specific pain points (if any) would actually justify a storage change?
  2. Compare the two options. Contrast the relational and document data models against this service's access patterns, covering joins, multi-record transactions, uniqueness and integrity constraints, schema flexibility, and indexing.
  3. Design the migration, assuming you decide to proceed: keep the service available throughout, move historical data, keep both stores consistent during transition, cut over safely, and be able to roll back.
  4. Prove the improvement. Define quantitative success criteria and how you'd measure them. Note explicitly why "we migrated" is not itself a result.

Constraints

  • Zero-downtime is expected; the service cannot stop for a maintenance window.
  • Correctness guarantees that MySQL currently provides (e.g., transactional updates across multiple rows, unique keys, foreign-key-style integrity) must not silently weaken.
  • If the evidence does not support migrating, recommending "stay on MySQL" (possibly with tuning or sharding) is a fully valid answer.

Be concrete: name the artifacts you'd produce (dashboards, traces, benchmarks, runbooks) and the failure modes you'd guard against.

Hints

Hint 1

Start from access patterns, not from the database feature list: log the top queries, their fan-out joins, write/read ratio, p99 latencies, and transaction shapes before comparing engines.

Hint 2

MongoDB multi-document transactions exist but carry costs (snapshot isolation limits, retry logic, no FK enforcement) — map each MySQL guarantee to a concrete replacement or an explicit acceptance of weaker semantics.

Hint 3

Avoid naive dual-writes: application-level writes to two stores can diverge silently. Consider CDC (change data capture / binlog tailing) for the replication leg instead.

Hint 4

Define success numerically before cutover (p99 latency, throughput, error rate, cost per request) measured against a pre-migration baseline captured under representative traffic.