PracHub
QuestionsLearningGuidesInterview Prep
|Home/System Design/OpenAI

Design an in-memory database

Last updated: May 18, 2026

Quick Overview

Design an in-memory database evaluates requirements, scale assumptions, API/data design, architecture, trade-offs, failure modes, and rollout in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

  • hard
  • OpenAI
  • System Design
  • Machine Learning Engineer

Design an in-memory database

Company: OpenAI

Role: Machine Learning Engineer

Category: System Design

Difficulty: hard

Interview Round: Technical Screen

Design an in-memory key–value database for ultra–low latency reads and writes. Functional requirements: - Commands: SET(key, value[, ttl]), GET(key), DELETE(key), MGET(keys), SCAN(prefix, limit, cursor). - Optional transactions with snapshot isolation (MULTI/EXEC) and atomic increments. - TTL with automatic expiration; optional pub/sub on key changes. Non-functional requirements: - Per-node: 50k ops/s; p99 GET < 2 ms, p99 SET < 5 ms; availability 99.99%. - Durability targets: RPO ≤ 1 s, RTO ≤ 60 s on crash/restart. Sub-questions: (a) Choose core data structures (e.g., hash table for point lookups, radix/ART or skip list for prefix scans). Explain complexity, memory overhead, and cache behavior. (b) Provide durability: write-ahead log and periodic snapshots; fsync policy, log compaction, and exact crash-recovery steps. (c) Scale out: sharding via consistent hashing, leader–follower replication, read replicas, client routing, and failover. State the consistency model and how to achieve it. (d) Manage memory: allocator strategy, fragmentation control, TTL wheel/timer, and eviction (LRU/LFU) when a memory cap is reached. (e) Concurrency model: single-threaded event loop vs. multi-threaded; locking, batching, and pipelining trade-offs. (f) Operations: metrics/slowlog, backups, online config changes, and capacity planning for 100M keys (avg value 200 B) with 64 GB RAM per node.

Quick Answer: Design an in-memory database evaluates requirements, scale assumptions, API/data design, architecture, trade-offs, failure modes, and rollout in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

Related Interview Questions

  • Design a Payment Lifecycle from Hold to Charge and Settlement - OpenAI (medium)
  • Design a Payment Orchestration System - OpenAI (medium)
  • Design an Asynchronous Text-to-Video Generation Service - OpenAI (medium)
  • Design an Online Chess Service from Launch to Scale - OpenAI (medium)
  • Design a Highly Available Conversational AI Service - OpenAI (medium)
|Home/System Design/OpenAI

Design an in-memory database

OpenAI logo
OpenAI
Jul 15, 2025, 12:00 AM
hardMachine Learning EngineerTechnical ScreenSystem Design
21
0

Design an in-memory database

System Design: In-Memory Key–Value Database for Ultra–Low Latency

Context

You are designing an in-memory, per-node key–value database optimized for ultra–low-latency reads and writes. It must support point lookups, prefix scans, TTLs with automatic expiration, optional transactions with snapshot isolation, and high availability with specified durability targets.

Functional Requirements

  • Commands:
    • SET(key, value[, ttl])
    • GET(key)
    • DELETE(key)
    • MGET(keys)
    • SCAN(prefix, limit, cursor)
  • Optional:
    • Transactions with snapshot isolation (MULTI/EXEC)
    • Atomic increments (e.g., INCRBY)
    • Pub/Sub notifications on key changes

Non-Functional Requirements

  • Per-node throughput: 50k ops/s
  • Latency: p99 GET < 2 ms; p99 SET < 5 ms
  • Availability: 99.99%
  • Durability targets:
    • RPO ≤ 1 s
    • RTO ≤ 60 s on crash/restart

Sub-Questions

(a) Choose core data structures (e.g., hash table for point lookups, radix/ART or skip list for prefix scans). Explain complexity, memory overhead, and cache behavior.

(b) Provide durability: write-ahead log (WAL) and periodic snapshots; fsync policy, log compaction, and exact crash-recovery steps.

(c) Scale out: sharding via consistent hashing, leader–follower replication, read replicas, client routing, and failover. State the consistency model and how to achieve it.

(d) Manage memory: allocator strategy, fragmentation control, TTL wheel/timer, and eviction (LRU/LFU) when a memory cap is reached.

(e) Concurrency model: single-threaded event loop vs. multi-threaded; locking, batching, and pipelining trade-offs.

(f) Operations: metrics/slowlog, backups, online config changes, and capacity planning for 100M keys (avg value 200 B) with 64 GB RAM per node.

Constraints & Assumptions

  • Preserve the scope, facts, inputs, and requested outputs from the prompt above.
  • If the prompt leaves a detail unspecified, state a reasonable assumption before relying on it.
  • Keep the answer interview-ready: concise enough to present, but concrete enough to implement or evaluate.

Clarifying Questions to Ask Guidance

  • Clarify users, core use cases, read/write patterns, scale, latency, availability, and data retention.
  • State explicit assumptions before making sizing or architecture decisions.
  • Prioritize the functional path first, then address reliability, security, observability, and rollout.

What a Strong Answer Covers Guidance

  • A scoped requirements summary with concrete non-goals and success metrics.
  • API, data model, architecture, consistency, capacity, and operations.
  • Reasoned trade-offs among simple and scalable designs, including bottlenecks and failure modes.
  • A validation, monitoring, migration, and launch plan appropriate for the risk level.

Follow-up Questions Guidance

  • What breaks first at 10x traffic or data volume?
  • How would you degrade gracefully during dependency failures?
  • What metrics and alerts would prove the design is healthy after launch?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More System Design•More OpenAI•More Machine Learning Engineer•OpenAI Machine Learning Engineer•OpenAI System Design•Machine Learning Engineer System Design

Your design canvas — auto-saved

PracHub

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

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding 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.