All Challenges
9 PointsStaff
00:00

In-Memory MVCC Transactional Key-Value Store with Snapshot Isolation

Build an ACID in-memory key-value store with Multi-Version Concurrency Control (MVCC), transaction commit/rollback, and snapshot isolation.

### Problem Overview Relational engines (PostgreSQL) and distributed stores (CockroachDB) use **Multi-Version Concurrency Control (MVCC)** to allow concurrent transactions without read-write locking conflicts. Implement an in-memory transactional key-value store supporting ACID transaction boundaries, Snapshot Isolation, and rollback capabilities. ### Functional Requirements 1. **`begin(): Transaction`**: - Opens a transaction with a unique monotonically increasing transaction ID and timestamp snapshot. 2. **Transaction Operations**: - `tx.get(key: string): Value | undefined`: Reads the value version visible to this transaction snapshot. - `tx.set(key: string, value: any): void`: Writes to the transaction private write-buffer. - `tx.delete(key: string): void`: Marks a key as deleted (tombstone). 3. **`tx.commit(): boolean`**: - Detects write-write conflicts (if another transaction modified the same key and committed after this transaction started). - If no conflict, applies updates to main MVCC version chain. 4. **`tx.rollback(): void`**: - Discards all private buffer writes without affecting main store. ### Non-Functional Requirements - **Snapshot Isolation**: Long-running read transactions must never be blocked by writers and never see uncommitted dirty reads. - **Tombstones & Vacuuming**: Deletes must store version tombstones.
AI Review Rubric Dimensions (1–10 Points):
  • MVCC snapshot isolation
  • Write-write conflict detection
  • Rollback buffer safety
  • Tombstone deletion
solution.tsTYPESCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
26 lines•503 characters•
AI Review Ready