Key-Value Store With Nested Transactions and Value Counts
Last updated: November 29, 2026
Quick Overview
Implement an in-memory key-value store supporting set, get, delete and count of keys holding a value, plus begin, rollback and commit with arbitrarily nested transactions.
Coinbase
November 29, 20260
0
0 solved
Implement an in-memory key-value store supporting set, get, delete and count of keys holding a value, plus begin, rollback and commit with arbitrarily nested transactions.
Coinbase's onsite coding rounds often grow one class through several parts, and transactional state is close to how ledger and balance services must behave. The interviewer checks that rollback is efficient, nested commit semantics are well defined and the value counter stays consistent through every path.
What the Interviewer Expects
- Pick an undo-log design or a layered overlay design and justify it
- Keep count(value) O(1) by maintaining a counter on every write
- Record only the first prior value per key per transaction
- Define commit as merging into the parent transaction
- Handle rollback or commit with no open transaction
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Compare your undo log with copying the whole map on begin; when would each win?
- How would you make get read-committed for other clients while a transaction is open?
- How would you persist this with a write-ahead log for crash recovery?
- What changes if commit must commit every open transaction at once?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
set(k, v), get(k) (None if missing), delete(k), count(v) returning how many keys currently hold v, begin(), rollback() undoing the innermost open transaction, commit() folding the innerm...
High-Level Design
Writes go straight to the live dict, which keeps get O(1). A stack of undo logs records, per transaction, the value each key had before that transaction first touched it (or a MISSING sentinel). Rollb...