Design an In-Memory Database With Transactions

Problem Implement an in-memory key-value database supporting set(key, value), get(key), and delete(key), with records that can hold multiple fields, plus nested transactions via begin(), commit(), and rollback().

Requirements

  • set, get, delete operate on keys (and named fields within a record).
  • begin() opens a transaction; transactions may be nested.
  • rollback() discards changes made since the most recent begin(), restoring the prior state.
  • commit() permanently applies all currently open transactions' changes.

Areas to design

  • How to snapshot or log changes so a nested rollback restores exactly the right state.
  • Whether commit folds one level into its parent or flushes every open level.
  • Isolation: what get sees while a transaction is open.
  • Edge cases: rollback/commit with no open transaction; deleting a key that was set in an outer transaction.
added …
LeaderboardSalaryAccount