Merge customers and preserve history
MetaSoftware Engineer · Online AssessmentLast updated
A Meta software-engineer system-design take-home: implement mergeCustomers(oldId, newId) for a payments/ledger platform, absorbing one customer into another while preserving every account's balance and immutable transaction history. Tests identity unification, ownership remap, conflict/duplicate resolution, top-N leaderboard maintenance, atomicity, concurrency, idempotency, and complexity analysis.
Question
Implement mergeCustomers(String oldId, String newId) for a payments/ledger platform. The call absorbs oldId into the survivor newId while preserving every account's balance and complete, immutable transaction history. Accounts are not coalesced — each account, with its history and balances, stays attached to its own account id.
Design the full merge and explain your reasoning for each of the following:
- Identifier unification — How do you unify the two identities so that, from the moment of merge commit, both
oldIdandnewIdresolve to a single canonical identity for all reads and future writes? - Ownership remap — How do you reassign ownership metadata across the entities that reference a customer (accounts, payment instruments, transfers, beneficiaries, etc.) without rewriting the ledger?
- Re-link historical and scheduled items — How do you re-link historical payments/transfers and recurring/scheduled items so nothing is lost or double-executed?
- Pending / held items — How do pending or held transactions, authorizations, and in-flight transfers continue to settle correctly after the merge?
- Conflict & duplicate resolution — How do you handle
customerIdcollisions and uniqueness conflicts (e.g. duplicate payment methods on the same token, identical scheduled items, beneficiary collisions, single-primary constraints, per-customer unique nicknames)? Give deterministic policies. - Indexes & caches — How do you update or invalidate indexes and caches, including the top-N payers / top-N spenders structure, so leaderboards stay correct immediately after the merge?
- Post-merge query correctness — How do balances, transaction history, and top-N aggregates remain correct (no loss, no double-counting) for queries issued by either id?
- Atomicity & consistency — What are your atomicity and system-wide consistency guarantees? How do you make the operation idempotent (repeating a merge is a no-op) and safe under concurrent merges (including chains A→B then B→C)?
- Complexity — Analyze time and space complexity of the merge and of the post-merge read path.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.