Build a Key Value Store With Nested Begin Commit and Rollback

Last updated: November 29, 2026

Quick Overview

Implement an in-memory key value store supporting set, get, delete, count of keys holding a value, and nested transactions with begin, rollback of the innermost transaction, and commit of all open transactions.

Microsoft
Software Engineering Fundamentals
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Online Assessment
Software Engineering Fundamentals
Medium

0

0

0 solved


Implement an in-memory key value store supporting set, get, delete, count of keys holding a value, and nested transactions with begin, rollback of the innermost transaction, and commit of all open transactions.

This is a classic practical exercise in the style of Microsoft online assessments and technical screens for backend roles, and it connects directly to how databases scope changes. The interviewer checks layered state, correct reads through layers, tombstones for deletes, and keeping a derived index (value counts) consistent through rollbacks.

What the Interviewer Expects
  • Represents each open transaction as a layer of changes
  • Reads from the innermost layer outward to the base store
  • Uses tombstones so deletes inside a transaction can be rolled back
  • Keeps value counts correct across set, delete, and rollback
  • Handles rollback or commit with no open transaction
  • States complexity of each operation
Key Topics to Cover
transactions
nested state
tombstones
rollback
derived indexes
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you make count O(1) without updating it on rollback?
  • How would you change commit to commit only the innermost transaction?
  • How would this relate to savepoints in SQL Server?
  • How would you make it safe for concurrent clients?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • set(k, v), get(k), delete(k), count(v) (number of keys currently equal to v).
  • begin() opens a nested transaction. rollback() discards the innermost one. commit() applies all open tra...
High-Level Design

Keep a base dictionary plus a stack of layers, each a dict of the keys changed in that transaction. A delete inside a transaction writes a tombstone sentinel, since simply removing the key fro...


Submit Your Answer
Markdown supported