KatInterview

Designing a Customer Account Remapping and History Preservation Engine

System DesignModel answer
HardModel answerSystem Designsystem-designdistributed-systemsdatabase-design

Last updated

Architect an idempotent system to merge platform customer identities while maintaining account ledgers, resolving entity conflicts, and preserving query accuracy.

You are designing a customer identity merge service for a high-scale financial platform (handling millions of accounts and billions of immutable ledger events).

Implement the architectural design for a function: mergeCustomers(oldId, newId)

When two customer profiles belong to the same real-world entity, the system must consolidate oldId into the surviving customer newId.

Key Constraints & Requirements

  • Ledger Immutability: Financial ledger entries (transactions, balances) reference an account_id, not a customer_id. Account history must remain completely unaltered. Accounts themselves are remapped to the surviving identity, not merged or deleted.
  • Backward Compatibility: After the merge completes, any API request, link, or legacy reference using oldId must continue to function predictably, mapping to the canonical newId.
  • Idempotency & Concurrency: Merges must be idempotent and safe under concurrent requests (including multi-step chains like A -> B followed by B -> C, or simultaneous A -> B and B -> C).

Design Requirements

In your response, address each of the following components explicitly:

  1. Identifier Unification & Resolution: How is identity mapped so both old and new IDs resolve to a single canonical ID on both read and write paths? How do you prevent multi-hop lookup chains?
  2. Ownership Remapping: How do you move accounts, payment methods, and scheduled transfers without modifying ledger records? How do you handle non-colocated or sharded databases?
  3. Scheduled Items & Historical Data: How are future/recurring operations remapped without missing runs or triggering duplicate executions?
  4. In-Flight & Pending Transactions: How are pending authorizations, holds, and active transfers settled correctly post-merge?
  5. Deterministic Conflict Resolution: Define explicit rules for resolving collisions (e.g., duplicate payment tokens, duplicate scheduled transfers, identical beneficiaries, nickname collisions).
  6. Caching & Top-N Leaderboards: How are read-through caches updated and how is a global leaderboard (e.g., top spenders/payers) updated without double-counting?
  7. Consistency, Idempotency & Cycles: How do you prevent cycles (e.g., A -> B and B -> A), ensure operational idempotency, and guarantee atomicity across system boundaries?
  8. Complexity Analysis: Provide time and space complexity for both the merge operation itself and the post-merge read paths.

Hints

Hint 1

Focus on flattening alias chains during resolution to keep lookup times O(1).

Hint 2

Decouple financial ledger entries from customer identity by maintaining an immutable association between balances/transactions and account IDs.

Hint 3

Use a deterministic tie-breaker (like creation timestamp or lexicographical ID) for handling duplicate payment methods or beneficiaries during entity conflicts.

Hint 4

For leaderboards and windowed counters, execute atomic, idempotent delta transfers backed by an idempotent execution table.