AIFeed

The Database Pin: Zero-Downtime Database Migrations with Strong Read-After-Write Consistency

Original text(via Lobsters)

The Database Pin: Zero-Downtime Database Migrations with Strong Read-After-Write Consistency

November 26, 2026

LinkedIn's Business Platform (LBP) runs the payments, quoting, billing, contracts, and ordering systems behind every transaction on LinkedIn, from Premium subscription renewal to an enterprise customer's invoice. As part of a company-wide effort to replace Oracle with MySQL, the open-source database that many of LinkedIn’s critical services already run on, we had to migrate these systems while customers were actively using them.

We had three non-negotiable requirements for this migration:

  • Zero data loss
  • Full transactional correctness
  • No downtime during the cutover

In financial systems, even a few minutes of blocked writes, or a single read that returns a stale balance, can charge a customer twice or leave an order stuck in the wrong state. And because the migration spanned many tables, multiple data centers, and a wide range of use cases, we needed one strategy we could apply safely everywhere.

Existing playbooks for this kind of migration required either a maintenance window, some risked serving stale or conflicting data mid-migration, and some added operational complexity that didn't scale to LBP's size. This post describes what we built instead: the Database Pin, a small, self-expiring routing record that lets us move live, financial-critical data with zero downtime, no lost writes, no stale reads, and no customer-facing incidents. The approach isn't specific to Oracle and MySQL and generalizes to any live migration between two replicated systems, a problem every growing engineering organization eventually runs into.

Why existing migration solutions don’t solve the problem

We evaluated the standard techniques used across the industry for migrating a live database, and each had certain limitations:

  • Application-level dual writes: Write to both databases on every operation. There's no atomic transaction across two databases, so a partial failure can leave them silently diverging. Mitigations exist (outbox pattern, sagas, 2PC, reconciliation jobs), but each adds latency, covers only one side, or catches the divergence after the fact. None gives us atomicity and low latency together.
  • Change Data Capture (CDC)-based replication with shadow reads: Replicate changes asynchronously (e.g., Oracle GoldenGate) and validate reads against the target. Replication lag, seconds normally, minutes under load, can make a read miss a recent write. Pausing traffic until it catches up avoids that, but then the downtime scales with the lag, which live payments and billing can't tolerate.
  • Distributed locking on primary keys: Hold a lock per write until replication catches up. Under the write concurrency financial systems see, lock timeouts start looking like outages.
  • Write blocking per cohort: Freeze writes for a slice of customers during their migration window. Still downtime, just scoped smaller, which isn't acceptable for payments and billing.
  • Dual reads with conflict resolution: Assumes data already lands in both stores via dual writes or CDC. Reads both, compares, and resolves disagreements with a rule like last-write-wins, which can silently pick the wrong side under concurrent writes. It only catches the problem after a read has already seen it, and doubles read latency.

Each of these is proven and well understood. None was built for zero downtime, zero data loss, and strong read-after-write consistency, together, under live traffic, across data centers. That gap is what the Database Pin was built to close.

The Database Pin - architecture and algorithm

LinkedIn's multi-data center setup and Entity Routing Service

Like most services at LinkedIn's scale, the systems behind payments, billing, and ordering run out of multiple data centers at once, for redundancy and to keep traffic close to where it originates. LinkedIn's internal routing layer for enterprise and financial systems, the Entity Routing Service (ERS), keeps this consistent, commonly called "sticky routing":

  • Normal operation: ERS ensures all reads and writes for a given entity land in the same data center for a period of time, rather than bouncing unpredictably.
  • Failover and entity pinning: An entity with recent write activity stays pinned at its current data center until replication has caught up for that entity specifically. Only then does ERS shift its traffic to the new data center, so an entity's writes will never show up in a data center that isn't caught up yet.

ERS predates this migration and has used this pinning pattern for over a decade. The Database Pin mechanism builds on that same idea rather than replacing it, extending it from data-center failover to feature-ramp-based database migration, as we'll see later.

To be clear, this doesn't make ERS a prerequisite. For multi-data center deployments, the Database Pin only needs some mechanism that keeps an entity's traffic consistently routed, and ERS happens to be the one already running at LinkedIn. For a single data center deployment, no such mechanism is needed at all.

What is a Database Pin?

The Database Pin is a small, short-lived key-value record that says, in effect, "this entity's source of truth is temporarily this database within a given data center."

A few design considerations shape how it works:

  • Storage: It needs a low latency, persistent key value store to live in, such as Couchbase, Redis, or DynamoDB.
  • TTL: A key-value store with native Time-To-Live (TTL) support, like Couchbase, which we use for exactly this reason, is preferable, since it lets an expired Database Pin disappear on its own. A store without native TTL still works, it just means the Database Pin mechanism has to track and check an expiry timestamp itself.
  • Scope: At LinkedIn, since ERS already keeps an entity's traffic in one data center, including during failover, we scope the Database Pin to a single data center. More generally, replicate the Database Pin across data centers only if your sticky routing doesn't already handle failover on its own. For a single location deployment, that boundary is simply the whole system.

This is the structure of the Database Pin:

  • key: {migration_id}::{entity_urn}: Uniquely identifies the Database Pin for one entity within one migration.
  • ttl: How long the Database Pin lives before it expires, refreshed on every write. The TTL matches one of three options:a dynamic value based on live replication-lag metrics.a static value set to the replication-lag SLO.a static value set to the observed upper bound for replication lag.
  • a dynamic value based on live replication-lag metrics.
  • a static value set to the replication-lag SLO.
  • a static value set to the observed upper bound for replication lag.

If an entity stops writing, its Database Pin simply expires once the TTL passes.

  • value: Which database currently owns the entity, plus whatever audit metadata you find useful, such as when the Database Pin was created.

System architecture

With the Database Pin defined, here's how it sits alongside everything else in the request path. Four pieces do the work:

  • The application: Issues reads and writes for a given entity, and connects directly to whichever database it's told to use.
  • A Database Pin routing library: Called by the application before each request, that resolves which database to use.
  • The Database Pin store: Holds the short-lived Database Pins described above.
  • A migration feature flag: A simple ramp (0-100%) that says which database an entity should use, and which moves gradually over the course of the migration.

The routing library is the only thing that talks to the Database Pin store or the migration feature flag. The application just asks the routing library for an entity's database and gets a decision back. That decision is what "The routing decision" section below expresses as pseudocode.

The routing decision

Every read or write for an entity resolves its source-of-truth database through one function:

The routing decision comes down to two simple rules:

  • Pin precedence and self-healing: An unexpired Database Pin always wins over the migration feature flag, and refreshes on every write. Once writes stop and the TTL lapses, the Database Pin expires and the entity falls back to the current ramp, which is what makes the mechanism self-healing.
  • Strict versus lenient enforcement: In strict mode, a Database Pin must be successfully persisted to the pin store prior to executing the write against the database. If the pin store write fails or is unavailable, the database write is rejected to guarantee consistency. Lenient mode instead attempts to create or refresh the pin synchronously with or after the write, preferring availability over strict pinning guarantees.

Migration Process

Steps followed to roll out migration in production:

  • Bootstrap database: The new database is bootstrapped with a snapshot of the source database and bidirectional replication between the source and target is enabled.
  1. Enable the Database Pin: Bring the Database Pin routing library and Database Pin store online.
  1. Shadow reads, write testing and validate: Compare the source database's reads against asynchronous shadow reads from the target database, checking for no mismatches on unpinned entities, correct SQL translation, and acceptable latency against the new database. Writes are tested with a shadow write strategy or in production with test customers.
  1. Ramp gradually: Ramp the Migration Feature Flag in small steps.
  1. Observe metrics: Application metrics, replication lag, read and write latency, the Database Pin Store fallback rate, and shadow-read mismatches are monitored at each ramp step. Any spike leads to the ramp being paused or rolled back.

A migration ends when the following conditions are satisfied:

  • The migration feature flag is at 100%
  • No Database Pins anywhere still reference the source database. Until then, any entity that wrote recently is still legitimately pinned to the old database, and honoring that pin is what keeps the migration safe.

Once the last Database Pin against the source database expires, the migration is, by definition, complete.

Migration Rollback

If metrics look wrong partway, the migration feature flag can be ramped back down. In a rollback scenario the entities behave differently based on if they’re pinned or not:

  • Pinned entities: Entities that have already moved and are actively pinned to the new database stay there until their Database Pin expires. Rolling them back mid-write would be the actually risky move.
  • Unpinned entities: Everything else falls straight back to resolving against the old database, no different than before the migration started.

Database Pin store failure modes

The Database Pin Store itself can also become unavailable. On lookup failure, the routing library has two options:

  • Fail closed: block traffic until the Database Pin store recovers.
  • Fail open: treat it as "no pin found" and fall back to the migration feature flag.

We default to fail open, since most of our traffic is reads and our Couchbase cluster is highly available. The exposure is also much smaller than the alternative approaches discussed earlier. The two databases are still the same replicated dataset, just briefly out of sync, so a Database Pin Store outage risks a stale read for a just-migrated entity, not a lost or corrupted write. And unlike dual writes' divergence risk on every write for the whole migration, this is rare and self-healing.

Where this pattern fits best

The Database Pin isn't a universal replacement for every migration technique and is suited to a specific shape of problem. This pattern fits best when the following conditions are true:

  • A stable, routable identifier per entity: The Database Pin is keyed on the same identifier you'd use for sticky routing in a multi-data-center deployment. Without one, there's nothing consistent to pin (e.g. in LBP’s case this is the customer identifier).
  • Reliable Database Pin visibility across data centers: Requests for a given entity need to reliably reach the same Database Pin state no matter which data center they land in, either through a globally-consistent Database Pin store, or through entity-level sticky routing to a home data center. Without one of those two, different data centers could briefly disagree about an entity's pin, and that's a conflict this mechanism isn't designed to resolve on its own.
  • Tolerance for a small write-path cost and a new dependency: Every write incurs a pin write before it, and the pin store is a new piece of infrastructure to run specifically, a TTL-native key-value store. That's worth it when correctness is non-negotiable, but it can be unnecessary overhead for lower-stakes, less consistency-sensitive data. In practice, this added latency was small, with a p90 of 10 ms or less using Couchbase.
  • A boundable replication-lag SLO: The Database Pin’s property of self healing where it expires on its own, depends on having a reasonably well-understood, boundable replication-lag SLO to calibrate the TTL against. For replication systems with highly variable or unbounded lag, getting that calibration right is much harder.

For migrations that can tolerate a downtime window, or that don't have per-record granularity requirements, one of the more established approaches may be simpler to operate.

Conclusion

The Database Pin mechanism lets us move financial transactions off Oracle to MySQL without a maintenance window, without a reconciliation job, and without asking any of those systems to tolerate stale reads. It shows that strong consistency during a live database migration doesn't require downtime, distributed transactions, or complex coordination and a simple, self-expiring, per-entity mechanism layered on top of a feature-flag rollout is enough. It's a small mechanism, a short-lived record and one routing function that composes with LinkedIn’s sticky routing service for financial systems known as the Entity Routing Service. This pattern isn't specific to Oracle-to-MySQL migrations and applies to any scenario where traffic needs to move safely between two replicated systems. We'd encourage any team with similar sticky-routing infrastructure to consider the same approach before reaching for dual writes or a maintenance window.

Acknowledgements

Thank you to Xin Sun, Myo Thein, Gourav Tiwari, and Venki Balakrishnan for their leadership and support throughout the project, and to Tanmay Khemka, Scott Winkleblack and LinkedIn alumni Yiwen Sun for their invaluable reviews of the Database Pin mechanism. Special shoutout to all the LBP and Infrastructure teams who collaborated on this massive effort to get us smoothly over the finish line.

Related articles

  • AI Where Agents Meet the Browser: Building a Browser-Native Agent Chenjie Yu Nov 24, 2026

Nov 24, 2026

  • Infrastructure Composable Torch Dataloader: A High-Performance, Modular Datal... Jonathan Hung Nov 20, 2026

Infrastructure

Jonathan Hung

Nov 20, 2026

  • How LinkedIn Runs Compute: Self-Managed Kubernetes on 500,000+... Ronak Nathani Nov 19, 2026

Ronak Nathani

Nov 19, 2026

The text above was extracted automatically from the source page and may miss images, tables or code blocks. The original is authoritative.

Published by Lobsters
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗