Figma interview question
Build an in-memory key-value store with nested transactions and atomic batches
- Company:
- Figma
- Round:
- Technical
- Type:
- Coding
- Difficulty:
- Medium
- Reported:
- June 2, 2026
Problem
Implement an in-memory key-value store with:
set(key, value),get(key)(returnsNoneif missing), anddelete(key)(returnsTrueif the key existed).begin(): start a transaction; transactions can be nested.rollback(): undo all changes made in the innermost open transaction; returnFalseif no transaction is open.commit(): close the innermost transaction, keeping its changes (an enclosing transaction can still roll them back); returnFalseif none is open.apply_batch(ops): apply a list of operations atomically. Operations are("set", key, value)or("delete", key). If any operation is invalid (unknown type, or deleting a missing key), none of the batch takes effect and the method returnsFalse; otherwiseTrue.
Example 1
Input: set("a",10), begin(), set("a",20), get("a"), begin(), delete("a"), get("a"), rollback(), get("a"), commit(), get("a"), rollback()
Output: 20, None, 20, 20, False
The inner rollback restores the value 20; after the outer commit there is no open transaction.
Constraints
- Up to
10^5operations; nesting depth up to10^3. - Keys and values are strings or integers.
Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern