← Meta Interview Insights

Meta·Software Engineer·Onsite - System Design / Architecture·Senior

SeniorPrefer not to say
Jul 2026

Summary

Meta system design round for a software engineer role. The problem was an in-memory database with TTL support, scans, and backup/restore. Deceptively tricky once you get into the edge cases.

Questions Asked (1)

Q1

Design an in-memory key-field-value store where each entry can optionally expire after a given TTL. Implement set, set_with_ttl, get, delete, scan, scan_with_prefix, backup, and restore operations.

System DesignData ModelingAlgorithms & Data Structures
Author's notes

The basic set/get/delete stuff came together fast, but I underestimated how much the TTL visibility rule would ripple through everything.

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 using a hash map for O(1) key lookups and a min-heap or time-ordered structure for TTL management. Discuss each operation's implementation, focusing on efficiency and correctness, and cover backup/restore strategies.

Pro tip: Mention that lazy deletion (checking expiration on access) combined with periodic cleanup (e.g., a background thread) balances performance and memory. Also, highlight that scan operations should skip expired entries and consider snapshot isolation for backup.

1. Clarify Requirements

Ask about expected scale, concurrency needs, persistence requirements, and whether TTL is absolute or sliding. Confirm the exact semantics of each operation.

2. Design Data Model

Propose a hash map for key-value storage, with each entry storing value, optional expiration timestamp, and possibly a version. For TTL management, consider a min-heap or time-ordered structure to efficiently find expired keys.

3. Implement Core Operations

Detail set, set_with_ttl, get, and delete. For get, check expiration and lazily delete if expired. For set_with_ttl, add to TTL structure. Discuss thread safety if needed.

4. Implement Scan Operations

For scan, iterate over all keys, skipping expired entries. For scan_with_prefix, use a trie or sorted structure for efficient prefix matching, or iterate and filter if simpler.

5. Backup and Restore

For backup, serialize the current state (excluding expired entries) to a file or memory buffer. For restore, deserialize and rebuild the data structures, ensuring TTLs are preserved relative to restore time.

Key Points to Mention

  • Time complexity: O(1) for set/get/delete, O(log n) for TTL cleanup with heap, O(n) for scan.
  • Lazy vs. active expiration: trade-offs and hybrid approach.
  • Concurrency: use locks or concurrent data structures for thread safety.
  • Memory management: avoid leaks by cleaning expired entries.
  • Backup consistency: snapshot isolation or locking during backup.
  • Prefix scan optimization: trie or sorted map for efficient range queries.

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