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
Coding & Algorithms
Software Engineer
Coinbase
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
design a data structure
transactions
undo log
hashing
stacks
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported