TryBugHunt

The Ghost Overwrite on Dual-Write Migration

hardjavascript

Asynchronous dual-writing and unversioned CDC reconciliation lead to silent out-of-order data corruption

0:00
Step 1: Test Traffic & Expose Flaw
/**
 * Dual-Write Sync Dispatcher
 * Dispatches updates synchronously to Primary DB and asynchronously to Replication Bus.
 */

export class SyncDispatcher {
  constructor(primaryDb, messageBus) {
    this.primaryDb = primaryDb;
    this.messageBus = messageBus;
  }

  async updateEntity(entityId, updates) {
    // Commit to primary database which increments entity.version
    const updatedRecord = this.primaryDb.update(entityId, updates);

    // AI Attempt: Forward record payload to async message bus for CDC replica
    // BUG: Omitted updatedRecord.version in event payload!
    const cdcEvent = {
      entityId: entityId,
      payload: { ...updatedRecord.data },
      timestamp: Date.now()
    };

    await this.messageBus.publish("cdc.entities", cdcEvent);
    return updatedRecord;
  }
}
Step 1: Test Traffic & Expose Flaw

Simulate an out-of-order network replay where an older update packet arrives after a newer update, corrupting the replica.

Choose Traffic Scenario to TestClick to simulate
Architectural Guide & Interview Notes
↑ Jump to Interactive Studio

Deep Dive: The Ghost Overwrite on Dual-Write Migration

An engineering analysis of why this AI-generated Pull Request passed isolated unit tests, how multi-tenant traffic exposes the architectural flaw, and how interviewers score your response.

The Root Cause Anti-Pattern

The Interviewer's Scoring Rubric

Candidates are assessed on whether they jump to trial-and-error editing or follow a hypothesis-driven approach. A "Strong Hire" candidate restates the data flow between modules, explains why single-client unit tests passed, crafts an adversarial probe showing cross-tenant leakage, and implements a surgical 1-line patch without breaking existing contracts.

Candidate Strategy for the Code Comprehension Round

  1. 1Map Module ContractsTrace how the gateway invokes the underlying service. Note what data is passed by reference vs. by value.
  2. 2Break It With An Adversarial ProbeSimulate concurrent or sequential traffic across multiple identities to force shared state mutation.
  3. 3Deliver a Surgical PatchMake the minimal required diff to ensure proper per-client state isolation without refactoring unnecessary files.