What they’re really asking
If you only remember one thing, say this in the first minute: “I’ll write the simplest correct store first, a dictionary with
get,setanddelete, with tests, in a few minutes. Then I’ll ask what comes next, because this is usually the first step of a longer problem. For each likely extension, transactions, versions, expiry, threads or saving to disk, I can name the data structure and its cost in one sentence, and I’ve kept the core small so any of them is a small change.”The rest of this page explains each part of that answer, so you can say it with understanding.
On its face this is the easiest question in the bank. Every backend engineer has used a key-value store, and the code is a dictionary. That is exactly why it is a screen. The interviewer is not checking whether you can write a dictionary wrapper. They are checking three things:
- Speed with tests. Can you produce clean, tested, running code in minutes, with someone watching? Hello Interview says OpenAI’s live coding often turns on “the amount of working code you need to produce within the session” (Hello Interview).
- Design sense under extension. When the interviewer adds a requirement, do you already know what shape it takes, and what it costs?
- Asking instead of guessing. Do you find out where the problem is going before building for it?
The report itself is thin: a summary of an OpenAI phone screen, behind a login wall, that names “implement a key-value store” next to a GPT-like system design and says nothing about follow-ups (1Point3Acres). Treat it as the opening of the practical problem the rest of this family describes.
Clarify first
Spend under a minute here. Say your assumptions out loud and keep moving:
- Operations. “Just
get,setanddelete, or also expiry, versions or transactions? I’ll start with the three and ask what comes next.” - Types. “Keys and values as strings? I’ll assume yes.”
- Missing keys. “
getof a missing key returnsNone, anddeleteof a missing key does nothing. Is that right?” - Threads. “One caller for now?”
- Persistence. “Will it need to survive a restart?” Ask this one directly; in this family it is the most common next part.
Answer
Write the obvious version fast
class KV:
def __init__(self):
self._data: dict[str, str] = {}
def get(self, key: str) -> str | None:
return self._data.get(key)
def set(self, key: str, value: str) -> None:
self._data[key] = value
def delete(self, key: str) -> None:
self._data.pop(key, None)
def test_kv():
kv = KV()
assert kv.get("a") is None
kv.set("a", "1"); assert kv.get("a") == "1"
kv.set("a", "2"); assert kv.get("a") == "2"
kv.delete("a"); assert kv.get("a") is None
kv.delete("missing") # no error
The test covers the cases people forget: a missing key, an overwrite, and deleting something that is not there. Run it before saying anything else. A passing test in the first five minutes sets the tone for the rest of the call.
Then show where it can go
Use one running example. Picture the store holding credit balances for a small service: alice → "100",
bob → "100". For each likely extension, say what the interviewer would ask, what data structure answers it,
and what it costs.
| Extension | The request, in the credits example | Data structure | What to say in the interview |
|---|---|---|---|
| Transactions | ”Move 30 from Alice to Bob, all or nothing, and let transfers nest.” | A stack of small dictionaries, one per open transaction, with a “deleted here” marker (a tombstone) | “Reads check the newest layer first. Rollback drops a layer, O(1).” |
| Versions | ”What was Alice’s balance at time t?” | Per key, a sorted list of (timestamp, value) | “A binary search per read, O(log n).” |
| Expiry (TTL) | “Hold this reservation for 10 minutes.” | An expiry time stored with each value | ”Check on read, so expired keys never come back, and sweep now and then to free memory.” |
| Threads | ”Many request handlers share the store.” | One lock around the dictionary | ”One lock first. Split it into several only if I measure contention.” |
| Persistence | ”Balances must survive a restart, then a crash.” | A length-prefixed snapshot saved atomically, then a write-ahead log | ”Snapshot for restart; a log forced to disk before I return for crash safety.” |
A few of those terms need a sentence each if the interviewer goes there:
- TTL (time to live) is how long a key is valid. Lazy expiry means you don’t delete a key the moment it expires; you notice it is expired when someone reads it, and a background sweep removes the rest.
- A snapshot is the whole store written to a file. Saving it atomically means writing a temporary file and renaming it over the old one, so a crash leaves the old file or the new one, never half.
- A write-ahead log is a file of changes, each one forced to disk before the call returns, so a crash cannot lose a write the caller saw succeed.
You do not need to build any of these unprompted. Naming the shape and the cost in one sentence each is what shows design sense on a phone screen. Then ask: “Which of these matters for the role?”
Keep the core small so changes stay small
Resist building classes for every concept before the first test passes. The best preparation for the next
requirement is a short, obvious core with a test around it. When transactions arrive, get grows a loop over
layers; when persistence arrives, set grows one line that logs before it writes. If the core is already
tangled, each change touches everything.
Say: “I’m keeping this deliberately small. Tell me what comes next and I’ll extend it.”
Where each extension leads
The other cards in this family build the extensions in full:
- Transactions: a stack of overlay dictionaries with tombstones (eng-119).
- Persistence: a length-prefixed snapshot saved atomically (infra-025), then a write-ahead log (infra-031).
Senior vs Staff
Phone-screen store
Senior
- Working code and tests in minutes, then a clean extension when asked.
Staff
- Asks which extension matters for the role, names its data structure and cost up front, and keeps the core small enough to change.
In plain words: a Senior candidate is fast, correct and tested, and extends cleanly when told what to add. A Staff candidate also steers: they find out which extension matters and have its cost ready before being asked.
Small-team version
In production this is a dictionary, functools.lru_cache, Redis or a database table. You would not write it,
and you should not pay for anything new to get it. The interview skill that carries over is speed with tests: a
small, correct core you can extend while someone watches.
Practise it timed and without AI tools, because candidates are told to expect none in OpenAI’s live coding (Hello Interview). Afterwards, ask an agent to propose the next three extensions and compare its choices with yours.
Pitfalls
- Over-building before the first test passes. Classes for every concept cost minutes you need for the extensions.
- No tests, or happy-path tests only. Missing keys and repeated deletes are where small stores break.
- Waiting to be told about persistence or transactions. Asking what comes next is part of the signal.
- Naming an extension without its cost. “Add versions” is a guess; “a sorted list per key, O(log n) reads” is a design.
Go deeper
- Family walkthrough: Key-value store to durable log.
- The next parts: transactions and serialization.
- Labs: Build Your Own In-Memory Cache (Redis-lite)Not an LLM lab (a Redis-style store with TTL and LRU) and Build Your Own Write-Ahead Log.