← Meta Interview Insights

Meta·Software Engineer·Onsite - Coding / Algorithms·Senior

Senior
May 2026

Summary

Meta SWE coding round, and they threw a pretty gnarly in-memory database design question at me. Lots of moving parts: TTL, conditional writes, historical reads. More of a mini system design disguised as a coding problem than a pure algo question.

Questions Asked (1)

Q1

Design and implement an in-memory key-value store (keyed by a composite key of `key` and `field`) that supports TTL-based expiration, conditional update and delete operations, prefix-based field scanning, and historical value lookups at arbitrary past timestamps.

System DesignData ModelingAlgorithms & Data Structures
Author's notes

This one took me a minute to even parse.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and constraints, then propose a data model that uses a nested hash map (key -> field -> value) with auxiliary structures for TTL and versioning. Outline the core operations (get, set, delete, scan, history) and discuss how to handle expiration and historical lookups efficiently. Finally, dive into implementation details, trade-offs, and potential optimizations.

Pro tip: Demonstrate awareness of real-world constraints by discussing memory management and concurrency, and suggest using a min-heap or timing wheel for efficient TTL expiration rather than scanning all keys.

1. Clarify Requirements and Constraints

Ask about expected scale, read/write ratio, consistency requirements, and whether TTL is per key-field pair or per key. Clarify the granularity of historical lookups (e.g., versioned values or time-series).

2. Design Data Model

Propose a nested map: outer map keyed by 'key', inner map keyed by 'field' storing value and metadata (TTL, version). For history, consider maintaining a list of (timestamp, value) per field or a separate versioned store.

3. Outline Core Operations

Describe how to implement get, set (with conditional update), delete (with condition), scan by prefix, and historical lookup. Explain how TTL expiration is checked lazily or via background cleanup.

4. Address TTL and Expiration

Discuss strategies for TTL: lazy expiration on access, active expiration using a min-heap or timing wheel, and how to handle expired entries during scans and history lookups.

5. Discuss Trade-offs and Optimizations

Talk about memory overhead, concurrency control (e.g., sharding, locks), and potential improvements like using a trie for prefix scans or a time-series database for history.

Key Points to Mention

  • Composite key structure: nested hash map (key -> field -> value) with metadata
  • TTL implementation: lazy vs. active expiration, using min-heap or timing wheel
  • Conditional operations: compare-and-swap semantics using version numbers or timestamps
  • Prefix scanning: efficient iteration over sorted fields or using a trie
  • Historical lookups: versioned values with timestamps, possibly using a time-series store
  • Concurrency and memory management: sharding, locks, and eviction policies

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