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).

What Reports Emphasize

Common mistakes: One candidate noted that adding their own test cases exposed a bug in a different coding round (LRU), suggesting self-testing was expected but risky if it reveals problems under time pressure.

Interviewer hints: Interviewers explicitly called out the cascading rollback rule: 'if the outer txn rollbacks, the already-committed inner txns must also be rolled back' — this was stated as a hard requirement, not inferred.; At least one interviewer (or commenter acting as proxy) asked directly: 'what is the difference between nested transactions with cascading rollback and just flattening everything into a single transaction?' — implying candidates should be prepared to articulate why nesting matters.; No concurrency is required — the model is explicitly single-threaded, per interviewer clarification.

What passers do: Candidates who passed were familiar with the nested-transaction KV store problem from other companies beforehand — one report noted 'this problem has been asked at other companies too, you can search for it.'; Correctly implementing read-your-write isolation inside a transaction (get reflects in-transaction sets before commit) was expected as a baseline.; Correctly implementing cascading rollback — inner committed transactions are undone when outer transaction rolls back — was the key differentiating constraint interviewers emphasized.

Practice

Write your own against 8 test cases, or read the worked solution — approach, complexity, and code that runs.

More xAI Questions

Free preview

Every question in the xAI catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 16 xAI questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
xAI · Coding · Reported 9× across candidate reports
Is this helpful?