Implement Nested Transactions for an On-Device Settings Store
Last updated: November 29, 2026
Quick Overview
Build an in-memory key-value store with set, get, delete, and count-by-value, supporting nested begin, rollback, and commit with efficient memory use.
Apple
November 29, 20260
0
0 solved
Build an in-memory key-value store with set, get, delete, and count-by-value, supporting nested begin, rollback, and commit with efficient memory use.
Settings and preferences on Apple devices are updated in grouped changes that must apply all together or not at all, for example when a configuration profile is installed. The interviewer checks transaction semantics and whether your rollback costs are proportional to changes made, not store size.
What the Interviewer Expects
- Defines semantics: rollback undoes the innermost transaction; commit applies all open ones
- Stores only changed keys per transaction layer instead of copying the store
- Represents deletes with a tombstone so reads fall through correctly
- Keeps count-by-value correct across nested rollbacks
- States the complexity of each operation
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you make commit only close the innermost transaction (savepoint style)?
- How would you add durability with a write-ahead log?
- How would two threads with their own transactions interact here?
- How would reads perform with 1000 nested layers, and how would you fix it?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
set,get,delete,count(value).beginopens a nested transaction;rollbackdiscards the innermost;commitmakes all open transactions permanent.- Errors when rolling back or committ...
High-Level Design
A base dict plus a stack of overlay dicts. Writes go to the top overlay, with a _DELETED tombstone for deletes. Reads scan overlays from the top, then the base. The value count is maintained increme...