System Design Task: mergeCustomers(oldId, newId)
Context
Your payments platform allows a single real person to accumulate multiple customer identities (duplicates). Each customer may own multiple accounts. Accounts have balances, immutable transaction history, and transfers (including pending/held states).
Task
Design and implement mergeCustomers(oldId, newId) to merge the identity represented by oldId into the identity represented by newId.
Requirements
-
Preserve all accounts as-is (no balance moves, no ledger rewrites), including:
-
Account balances
-
Full transaction history
-
Transfer records (completed, pending, held/authorized)
-
Remap ownership from oldId to newId across the system.
-
Handle customerId collisions (e.g., uniqueness constraints, duplicated identifiers, preferences).
-
Update indexes and caches, including a top-N payers leaderboard/structure.
-
Ensure atomicity, consistency, and idempotency; handle concurrent merges safely.
-
Describe locking and failure handling.
Deliverables
-
Clear invariants and data model assumptions (minimal and reasonable).
-
Step-by-step algorithm for mergeCustomers(oldId, newId), including:
-
Ownership remapping strategy
-
Collision resolution rules
-
Index and cache updates (incl. top-N payers)
-
Atomicity/consistency guarantees and locking
-
Pseudocode-level detail sufficient for implementation.