Back to all posts
☁️DevOps6 min read

Building a Zero-Downtime Auth Migration

How to migrate from one auth system to another without logging out a single user or causing any downtime.

The Migration Challenge

You've outgrown your current auth system. Maybe you're moving from Firebase Auth to Auth0, or from a homegrown solution to something more robust. The question is: how do you migrate without disrupting users?

The Dual-Write Pattern

During migration, write to both systems simultaneously. This ensures both systems stay in sync while you transition.

async function createUser(userData) {
  // Write to new system
  const newUser = await newAuth.createUser(userData);
  
  // Write to legacy system (for rollback safety)
  await legacyAuth.createUser(userData);
  
  return newUser;
}

Shadow Authentication

Authenticate against both systems, but only trust the legacy system's response initially. Log discrepancies for investigation.

async function authenticate(credentials) {
  const [legacyResult, newResult] = await Promise.all([
    legacyAuth.verify(credentials),
    newAuth.verify(credentials).catch(logDiscrepancy)
  ]);
  
  // Trust legacy during migration
  return legacyResult;
}

Gradual Traffic Shift

Use feature flags to gradually shift authentication traffic:

  • Week 1: 1% to new system (canary)
  • Week 2: 10% to new system
  • Week 3: 50% to new system
  • Week 4: 100% to new system

Session Bridging

The trickiest part: users shouldn't have to log in again. Create a session bridge that accepts tokens from both systems.

function validateSession(token) {
  // Try new system first
  let session = newAuth.validateToken(token);
  if (session) return session;
  
  // Fall back to legacy
  session = legacyAuth.validateToken(token);
  if (session) {
    // Migrate session to new system
    return migrateSession(session);
  }
  
  return null;
}

Rollback Plan

Always have a rollback plan. Keep the legacy system running (read-only) for at least 30 days after full migration. You never know what edge cases will surface.

Written by Rashad Jamara

Ready to fix your auth?

Let's discuss how to apply these patterns to your specific stack and requirements.

Book a 20-minute call →