AO
Back

In-Memory Database / KV Store with Transactions

CodingPhone, OnsiteSoftware Engineer, Machine Learning EngineerLast reported April 2026Medium Frequency

Problem Overview

Implement an in-memory key-value store that supports transactions.
Where you'll code it
CodeSignal
Live shared coding environment. You may need to create test files / inputs yourself.
Full problem statement
Implement an in-memory key-value store that supports transactions. Core operations: set(key, field, value), get(key, field), delete(key, field). Transaction operations: begin/start a transaction, commit, and rollback. The key constraint is nested transaction semantics: a begin inside an active transaction creates an inner transaction; reads within any transaction must reflect writes made in that same transaction (read-your-write isolation); and outer-transaction rollback must also discard inner commits. Observed variants add TTL expiration and backup/restore on top of the transactional core. This is xAI's most-reported coding question (9 reports across a year), typically run in a CodeSignal-style staged format where requirements arrive level by level.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Trade-off discussion · 5
Trade-off discussion
How would you productionize this solution?
Probes for: after basic implementation is working
If the outer transaction rolls back after inner transactions have committed, what happens to those inner commits?
Probes for: when nested transactions are introduced
Can a transaction read its own uncommitted writes?
Probes for: candidate asks about read semantics inside a transaction
What is the practical difference between nested transactions with cascading rollback versus flattening all writes into a single transaction?
Probes for: after nested transactions are implemented
How do you handle TTL expiration on backup and restore?
Probes for: TTL/versioned variant

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
Copy-on-write snapshot per transactiontake a full snapshot at each begin — simple to reason about but O(N) memory per transaction
Undo log / undo bufferrecord the previous value of each key before overwriting; on rollback, replay the undo log in reverse — O(writes) memory, the production-grade answer).

Practice

Open the editor to write a solution against test cases, then return here to compare against the follow-ups.
Open Editor →
xAI · Coding · Reported 9× across candidate reports