Design an In-Memory Transactional Key-Value Store
Design an in-memory key-value database that supports transactional reads and writes.
Expose a class with these operations:
begin()starts a transaction and returns a transaction id.get(txid, key)reads the value visible to that transaction.set(txid, key, value)writes a value inside that transaction.commit(txid)attempts to make the transaction's writes visible.rollback(txid)discards the transaction's writes.
Constraints & Assumptions:
- The database is in memory only; durability and crash recovery are out of scope unless the interviewer asks.
- Keys and values can be treated as strings.
- Transaction ids are generated by the database.
- A transaction should read its own writes.
- You may choose optimistic or pessimistic concurrency control, but you must explain the trade-offs.
The interviewer is especially interested in how your design handles conflicting concurrent writes to the same key, and read/write races where two transactions observe stale values and then swap values between keys.
AI interview prep
Core dilemma
Balancing transactional isolation guarantees (especially preventing race conditions like write-write conflicts and read-write anomalies) against performance and complexity in an in-memory, single-process environment.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Design an In-Memory Transactional Key-Value Store
Design an in-memory key-value database that supports transactional reads and writes.
Expose a class with these operations:
begin()starts a transaction and returns a transaction id.get(txid, key)reads the value visible to that transaction.set(txid, key, value)writes a value inside that transaction.commit(txid)attempts to make the transaction's writes visible.rollback(txid)discards the transaction's writes.
Constraints & Assumptions:
- The database is in memory only; durability and crash recovery are out of scope unless the interviewer asks.
- Keys and values can be treated as strings.
- Transaction ids are generated by the database.
- A transaction should read its own writes.
- You may choose optimistic or pessimistic concurrency control, but you must explain the trade-offs.
The interviewer is especially interested in how your design handles conflicting concurrent writes to the same key, and read/write races where two transactions observe stale values and then swap values between keys.