PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/System Design/OpenAI

Design an in-memory key-value database

Last updated: Jun 7, 2026

Quick Overview

This question evaluates system-design and storage engineering competencies, including in-memory data structures, concurrency control, persistence and durability mechanisms, replication and sharding strategies, and operational concerns like observability and backpressure.

  • hard
  • OpenAI
  • System Design
  • Software Engineer

Design an in-memory key-value database

Company: OpenAI

Role: Software Engineer

Category: System Design

Difficulty: hard

Interview Round: Technical Screen

Design an in-memory key-value database. Support set/get/delete, conditional updates (e.g., compare-and-set), TTL expiration, and atomic multi-key operations. Explain data structures to achieve O( 1) average-time reads/writes, how you track expirations (e.g., timing wheel or min-heap), memory management and eviction (e.g., LRU), and persistence via append-only log with periodic snapshots. Detail concurrency control (single-threaded event loop vs locks), crash recovery, replication and sharding for scale, consistency guarantees, backpressure, and observability. Provide API definitions, schemas for on-disk records, failure modes, and metrics.

Quick Answer: This question evaluates system-design and storage engineering competencies, including in-memory data structures, concurrency control, persistence and durability mechanisms, replication and sharding strategies, and operational concerns like observability and backpressure.

Related Interview Questions

  • Design Video Generation Orchestration - OpenAI (medium)
  • Design CI/CD Build Caching - OpenAI
  • Design an Instagram-like Feed System - OpenAI (medium)
  • Design Online Chess Matchmaking - OpenAI (hard)
  • Design Android MVVM API Architecture - OpenAI (medium)
OpenAI logo
OpenAI
Jul 31, 2025, 12:00 AM
Software Engineer
Technical Screen
System Design
26
0

Design an In-Memory Key–Value Database (Technical Screen)

Context

Build an in-memory key–value (KV) database that offers high-throughput, low-latency operations. It should keep most data in RAM, support optional persistence, and scale across CPU cores and machines.

Assume a typical deployment runs on commodity servers with SSDs and multiple CPU cores. The system must handle high QPS with O(1) average-time reads and writes.

Functional Requirements

  1. Core operations:
    • set(key, value[, ttl])
    • get(key)
    • delete(key)
    • compare-and-set (CAS): conditional update based on version or expected value
  2. TTL expiration for keys
  3. Atomic multi-key operations (within a shard)

Non-Functional Requirements

  1. O(1) average-time reads/writes
  2. Expiration tracking (e.g., timing wheel or min-heap)
  3. Memory management and eviction policy (e.g., LRU)
  4. Durability via append-only log (AOF) with periodic snapshots
  5. Concurrency control strategy (single-threaded event loop vs locks)
  6. Crash recovery procedure
  7. Replication and sharding for scale
  8. Consistency guarantees
  9. Backpressure under overload
  10. Observability: logs, metrics, tracing

Deliverables

  • API definitions (client-facing)
  • In-memory data structures and algorithms
  • On-disk record schemas (AOF and snapshot)
  • Concurrency and transaction model (incl. atomic multi-key)
  • Crash-recovery flow
  • Replication and sharding design
  • Consistency guarantees and trade-offs
  • Backpressure strategies
  • Failure modes and metrics

Solution

Show

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More System Design•More OpenAI•More Software Engineer•OpenAI Software Engineer•OpenAI System Design•Software Engineer System Design
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • 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.