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
Software Engineering Fundamentals
Software Engineer
Apple
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Medium

0

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
transactions
rollback
tombstones
write overlays
data structures
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 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 Problems
Sample Answer
Requirements
  • set, get, delete, count(value).
  • begin opens a nested transaction; rollback discards the innermost; commit makes 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...


Submit Your Answer
Markdown supported