PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers
|Home/Coding & Algorithms/OpenAI

Implement a persistent sharded key-value store

Last updated: Apr 19, 2026

Quick Overview

This question evaluates understanding of persistent storage and file-based sharding, including on-disk layout, record serialization, indexing strategies for locating the latest value per key, shard rollover, and recovery from partial or corrupt tails.

  • hard
  • OpenAI
  • Coding & Algorithms
  • Software Engineer

Implement a persistent sharded key-value store

Company: OpenAI

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

## Problem Implement a simple **key–value store** that persists data on disk. You must store the data in **fixed-size shards**, where each shard is saved in **one file**. If a shard file reaches its maximum size, new writes must go into a **new shard file**. The store must support **shutdown (persist)** and **restore (recover)**. You are given helper functions: - `encode(key, value) -> bytes` to serialize a key/value record - `decode(bytes) -> (key, value)` to deserialize a record Assume keys and values are strings (or byte arrays), and `encode/decode` are inverses for valid records. ## Required API Design and implement (language-agnostic) functions/methods equivalent to: - `put(key, value)` - Insert or overwrite the value for `key`. - `get(key) -> value | null` - Return the current value for `key`, or `null`/`None` if missing. - `delete(key)` (optional if you want to support removals) - Remove `key` if it exists. - `shutdown()` - Ensure all in-memory state is persisted so the store can be restored later. - `restore(directory_path)` (or constructor-based restore) - Load persisted data from disk and make the store usable again. ## Storage requirements - Data is stored across **one or more files** in a directory. - Each file is a **shard** with a configurable maximum size `SHARD_SIZE_BYTES`. - Writes append records to the current shard until it would exceed the shard size; then create a new shard file. ## What to discuss / clarify - Your on-disk layout (file naming, record boundaries, handling partial/corrupt tail). - How you locate the latest value for a key after many overwrites. - What metadata or in-memory index (if any) you maintain. - Complexity of `put/get` and `restore`. - Edge cases: empty store, large values, shard rollover, overwrite semantics, optional delete semantics.

Quick Answer: This question evaluates understanding of persistent storage and file-based sharding, including on-disk layout, record serialization, indexing strategies for locating the latest value per key, shard rollover, and recovery from partial or corrupt tails.

Related Interview Questions

  • Simulate Infection Spread on a Grid - OpenAI (hard)
  • Implement Social Follow Recommendations - OpenAI (medium)
  • Build a Compose Rating Card - OpenAI (medium)
  • Convert IPv4 Ranges to CIDR Blocks - OpenAI (medium)
  • Implement Persistent KV Store Serialization - OpenAI (hard)
OpenAI logo
OpenAI
Nov 24, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
75
0
Coding Console

Problem

Implement a simple key–value store that persists data on disk.

You must store the data in fixed-size shards, where each shard is saved in one file. If a shard file reaches its maximum size, new writes must go into a new shard file. The store must support shutdown (persist) and restore (recover).

You are given helper functions:

  • encode(key, value) -> bytes to serialize a key/value record
  • decode(bytes) -> (key, value) to deserialize a record

Assume keys and values are strings (or byte arrays), and encode/decode are inverses for valid records.

Required API

Design and implement (language-agnostic) functions/methods equivalent to:

  • put(key, value)
    • Insert or overwrite the value for key .
  • get(key) -> value | null
    • Return the current value for key , or null / None if missing.
  • delete(key) (optional if you want to support removals)
    • Remove key if it exists.
  • shutdown()
    • Ensure all in-memory state is persisted so the store can be restored later.
  • restore(directory_path) (or constructor-based restore)
    • Load persisted data from disk and make the store usable again.

Storage requirements

  • Data is stored across one or more files in a directory.
  • Each file is a shard with a configurable maximum size SHARD_SIZE_BYTES .
  • Writes append records to the current shard until it would exceed the shard size; then create a new shard file.

What to discuss / clarify

  • Your on-disk layout (file naming, record boundaries, handling partial/corrupt tail).
  • How you locate the latest value for a key after many overwrites.
  • What metadata or in-memory index (if any) you maintain.
  • Complexity of put/get and restore .
  • Edge cases: empty store, large values, shard rollover, overwrite semantics, optional delete semantics.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More OpenAI•More Software Engineer•OpenAI Software Engineer•OpenAI Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • Careers
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.