← OpenAI Interview Insights

OpenAI·Software Engineer·Technical Phone Screen·Senior

Senior
Jul 2026

Summary

OpenAI software engineering interview with a systems-focused coding problem. The question was about building a persistent key-value store from scratch with shard-based file storage, which sounds manageable until you actually have to think through all the edge cases live.

Questions Asked (1)

Q1

Design and implement a persistent key-value store that writes data to fixed-size shard files on disk. The store should support put, get, delete, shutdown (persist to disk), and restore (reload from disk). You're given encode/decode helpers for serialization.

System DesignTechnical Trade-offsAlgorithms & Data Structures
Author's notes

I spent the first few minutes just trying to nail down the in-memory index before even thinking about the file layout, which was probably backwards.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the sharding strategy and data layout before writing any code, then implement an in-memory hash map with a deterministic shard assignment function (e.g., hash(key) % num_shards). Layer persistence on top by serializing each shard's contents to a fixed-size file on shutdown and deserializing on restore, handling edge cases like partial writes and missing files.

Pro tip: Proactively discuss the trade-offs of your sharding scheme — for example, consistent hashing vs. modulo hashing — and mention how you'd handle shard rebalancing or corruption recovery, as this signals production-level thinking that OpenAI interviewers look for.

1. Clarify Requirements & Constraints

Ask about the number of shards, maximum shard file size, concurrency requirements, and whether durability must be synchronous or can be eventual. Confirm what the encode/decode helpers accept and return to avoid assumptions.

2. Design the Data Model & Sharding Strategy

Choose a shard assignment function (e.g., hash(key) % N) and define the in-memory structure — typically a list of N dictionaries, one per shard. Sketch the on-disk file format, such as a length-prefixed sequence of encoded key-value pairs per shard file.

3. Implement Core Operations

Code put, get, and delete by routing each key to its shard index and mutating the corresponding in-memory dict. Keep operations O(1) average by leveraging the hash map and avoid cross-shard coordination for single-key ops.

4. Implement Shutdown (Persist) & Restore

On shutdown, iterate over each shard, serialize all key-value pairs using the encode helper, and write atomically to the shard file (write to a temp file then rename to prevent corruption). On restore, read each shard file, decode entries, and repopulate the in-memory dicts.

5. Discuss Edge Cases & Trade-offs

Address what happens when a shard file exceeds the fixed size (overflow strategy, rejection, or spill file), how to handle concurrent reads/writes (per-shard locks), and how deleted keys are represented on disk (tombstones vs. omission during compaction).

Key Points to Mention

  • Shard assignment via deterministic hashing (hash(key) % num_shards) to ensure consistent routing across shutdown/restore cycles
  • Atomic file writes using a write-to-temp-then-rename pattern to prevent partial/corrupt shard files
  • Per-shard locking (e.g., a list of threading.Lock objects) to enable concurrent access without a global lock bottleneck
  • Fixed-size file enforcement strategy — whether to raise an error, use overflow shards, or trigger compaction when a shard exceeds its size limit
  • Tombstone records or omission-on-persist for deleted keys, and the trade-off between space amplification and read complexity
  • Separation of concerns between the serialization layer (encode/decode helpers) and the storage layer, making the design testable and swappable

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.