---
title: "Build an in-memory key–value store in stages under a time limit: basic get/set/delete, then expiring entries, then…"
url: https://gurkanozkan.ai/learn/questions/research-progressive-timed-implementation-083/
markdown: https://gurkanozkan.ai/learn/questions/research-progressive-timed-implementation-083.md
kind: question
role: Research
stage: Coding
difficulty: Medium
json: https://gurkanozkan.ai/api/learn/questions/research-progressive-timed-implementation-083.json
robots: noindex
---

# Build an in-memory key–value store in stages under a time limit: basic get/set/delete, then expiring entries, then nested transactions with rollback, and finally saving and restoring state.

Research · Coding · Medium

Theme reported publicly: [Anthropic](https://www.sundeepteki.org/advice), [OpenAI](https://www.aced.io/guides/openai-research-engineer-interview)

## Answer

*Model answer, written in a candidate's voice*

### In short

- Define one explicit model: key -> value + optional expiry + transaction metadata.
- Build basic get/set/delete first with tests for missing, overwrite, and delete-absent cases.
- Add lazy expiry on read; test expired, not-yet-expired, and no-expiry entries.
- Add nested transactions with undo logs or snapshots; test inner rollback, outer commit, and outer rollback.
- Serialise committed state including expiry; restore through the same validation path; test round-trip and bad input.
- Refactor by layering, not rewriting; narrate trade-offs and protect edge cases under time pressure.

### In full

I would start by defining the model explicitly: each key maps to a value, an optional expiry timestamp, and enough metadata to know whether it was written inside a transaction, so every later stage extends the same structure instead of replacing it. I would build the basic map first with focused tests for set/get/delete, missing keys, overwrites, and delete-of-absent-key, then add expiry lazily on read with tests for expired, not-yet-expired, and no-expiry entries, accepting that lazy expiry is simpler and cheaper than a background sweeper but can leave stale entries until touched. For nested transactions I would keep a stack of undo logs or snapshots so an inner rollback restores only the inner changes while an outer commit makes the whole tree visible, with tests for inner rollback followed by outer commit, outer rollback after inner commit, and failure mid-transaction. Persistence would serialise the committed state, including expiry timestamps, and restore it through the same validation path, with round-trip and corrupt-input tests rather than trusting the file. Under time pressure I would keep the core small, add one stage at a time, and narrate trade-offs: lazy expiry versus active cleanup, snapshots versus a write-ahead log, and memory simplicity versus durability, while not letting speed turn into untested edge cases.

*Corrected by an independent AI reviewer.*

## What a strong answer covers

- A clean data model.
- Tests at every level.
- Edge cases: expired keys, nested rollback.
- Refactor to extend rather than rewrite.
- Keeps pace without losing correctness, and narrates the trade-offs.

## Common mistakes

- Over-engineering level 1.
- Skipping tests, so bugs cascade through later levels.

## Topic guides

- [Coding for ML and LLM engineering](https://gurkanozkan.ai/learn/topics/coding-engineering.md)
---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
