← Meta Interview Insights

Meta·Software Engineer·Online Assessment (OA)·Senior

SeniorPrefer not to say
Jun 2026Remote

Summary

Meta coding screen, the multi-level in-memory database design kind. Four progressively nastier levels, each one building on the last, and by the time TTLs and snapshots showed up I was definitely sweating.

Questions Asked (4)

Q1

Build an in-memory database that supports SET, GET, and DELETE operations on records identified by a key and a field.

Algorithms & Data StructuresSystem Design
Author's notes

Straightforward enough.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements: in-memory, key-field-value store, operations SET, GET, DELETE. Then propose a nested hash map (dictionary) where the outer map maps keys to inner maps, and inner maps map fields to values. Discuss time complexity, edge cases, and potential extensions like transactions or TTL.

Pro tip: Mention that you would use a hash map for O(1) average time complexity, but also consider thread-safety if the database is accessed concurrently. This shows awareness of real-world constraints beyond the basic algorithm.

1. Clarify Requirements

Ask questions to confirm the exact behavior: Are keys and fields strings? What should GET return if key or field doesn't exist? Should DELETE remove the entire key or just a field? Are there any constraints on memory or concurrency?

2. Design Data Structure

Propose a nested hash map: a top-level map from keys to inner maps, and each inner map from fields to values. This allows O(1) average time for SET, GET, and DELETE.

3. Define Operations

Specify the semantics: SET(key, field, value) inserts or updates; GET(key, field) returns value or null; DELETE(key, field) removes the field, and if the inner map becomes empty, optionally remove the key to save memory.

4. Analyze Complexity and Edge Cases

State that all operations are O(1) average time, O(n) worst-case due to hash collisions. Discuss edge cases: missing key/field, deleting non-existent entries, and potential memory leaks from empty inner maps.

5. Discuss Extensions and Trade-offs

Mention possible extensions: thread-safety using locks or concurrent data structures, TTL for automatic expiration, transactions, or persistence. Compare with alternative designs like a single flat map with composite keys.

Key Points to Mention

  • Use of nested hash maps (dictionaries) for O(1) average time complexity.
  • Handling of missing keys or fields (return null or throw exception based on requirements).
  • Memory management: removing empty inner maps after DELETE to avoid leaks.
  • Thread-safety considerations if concurrent access is expected.
  • Potential extensions: TTL, transactions, persistence, or range queries.
  • Trade-offs between nested maps and a flat map with composite keys.

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

Q2

Extend the database to support SET_AT and SET_AT_WITH_TTL, where each field can have a per-field expiry timestamp, and reads after expiry should return nothing.

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

This is where it started getting fiddly.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements and constraints, then propose a data structure that stores per-field expiry timestamps alongside values. Discuss how to handle lazy vs. active expiration, and analyze trade-offs in terms of time/space complexity and system design.

Pro tip: Mention that lazy expiration is often preferred for read-heavy systems to avoid background overhead, but active expiration can be combined for memory efficiency. Also, highlight the importance of using a monotonic clock to avoid issues with system time changes.

1. Clarify Requirements

Ask about expected read/write patterns, memory constraints, and whether expiration should be lazy or active. Confirm that SET_AT sets a field with an absolute expiry timestamp, and SET_AT_WITH_TTL sets a relative TTL.

2. Design Data Structure

Propose storing each field's value along with its expiry timestamp in a hash map or similar structure. For per-field expiry, consider a nested map: field -> (value, expiry).

3. Handle Expiration

On read, check if the field's expiry timestamp is in the past; if so, return nothing and optionally delete the field. Discuss lazy deletion vs. background sweeping for memory reclamation.

4. Analyze Trade-offs

Compare lazy vs. active expiration: lazy avoids background overhead but may retain expired data; active frees memory but adds complexity. Discuss time/space complexity of operations.

5. Consider Scalability

If this is part of a larger system, discuss how to handle persistence, replication, and clock synchronization across nodes. Mention potential use of a min-heap or time wheel for efficient active expiration.

Key Points to Mention

  • Per-field expiry requires storing a timestamp with each field.
  • Lazy expiration checks on read and deletes if expired; active expiration uses a background process.
  • Trade-offs: lazy is simpler but may waste memory; active is more complex but frees memory promptly.
  • Use a monotonic clock to avoid issues with system time adjustments.
  • Consider using a min-heap or time wheel for efficient active expiration.
  • Discuss how to handle persistence and replication if the database is distributed.

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

Q3

Add SCAN and SCAN_BY_PREFIX operations that return all matching fields for a given key, sorted in lexicographic order, with prefix filtering as an option.

Algorithms & Data StructuresData Modeling
Author's notes

Felt manageable.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the data model and requirements (e.g., key-value store, sorted order, prefix semantics) before designing the solution. Propose an ordered data structure like a balanced BST or trie to support efficient range scans and prefix filtering, then analyze time and space complexity. Discuss trade-offs and potential optimizations for large-scale systems.

Pro tip: Mention that SCAN should be inclusive of the start key and that SCAN_BY_PREFIX can be implemented as a range scan from prefix to prefix + '\xff' (or equivalent), showing attention to edge cases. Also, consider concurrency and consistency if the store is distributed.

1. Clarify Requirements

Ask about the data model (e.g., key-value store), expected operations, and constraints like ordering, prefix semantics, and performance goals.

2. Choose Data Structure

Select an ordered structure such as a balanced BST (e.g., red-black tree) or trie that supports efficient range queries and prefix matching.

3. Design SCAN Operation

Implement SCAN by performing an in-order traversal starting from the given key (inclusive) to collect all matching fields in lexicographic order.

4. Design SCAN_BY_PREFIX Operation

Implement SCAN_BY_PREFIX by converting it to a range scan from the prefix to the prefix with the highest possible suffix (e.g., prefix + '\xff'), then filter results.

5. Analyze Complexity and Trade-offs

Discuss time complexity (O(log n + k) for balanced BST, O(k) for trie) and space complexity, and mention alternatives like sorted arrays or skip lists.

Key Points to Mention

  • Use of an ordered data structure (e.g., balanced BST, trie, skip list) to maintain lexicographic order.
  • SCAN should return all fields for keys >= given key, sorted; clarify inclusivity.
  • SCAN_BY_PREFIX can be implemented as a range scan from prefix to prefix + '\xff' (or equivalent) to capture all keys with that prefix.
  • Time complexity: O(log n + k) for balanced BST, O(k) for trie, where k is number of results.
  • Space complexity: O(n) for storing the data structure.
  • Consider concurrency, consistency, and scalability if the store is distributed.

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

Q4

Implement BACKUP(timestamp) and RESTORE operations so the entire database state can be snapshotted at a given timestamp and later restored, with TTLs adjusted relative to the restore time rather than the original set time.

System DesignTechnical Trade-offsData Modeling
Author's notes

This one hurt a little.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and constraints, then design a snapshot mechanism that captures the full database state at a given timestamp, likely using a copy-on-write or versioned approach. For restore, focus on how to adjust TTLs relative to the restore time, ensuring expired keys are handled correctly and consistency is maintained.

Pro tip: Emphasize the trade-offs between storage overhead and restore speed, and propose a lazy expiration strategy for TTLs to avoid scanning the entire dataset during restore.

1. Clarify Requirements and Constraints

Ask about expected data size, frequency of backups, acceptable downtime during restore, and consistency requirements. Confirm that TTLs should be recalculated based on restore time, not original set time.

2. Design Snapshot Mechanism

Propose a method to capture the database state at a timestamp, such as periodic full snapshots with incremental changes, or a versioned key-value store. Consider using a write-ahead log or copy-on-write for efficiency.

3. Handle TTL Adjustment on Restore

Explain how to store TTLs as absolute expiration times or as remaining TTL at snapshot time. On restore, compute new expiration times relative to restore time, and discard keys that would have already expired.

4. Implement Restore Operation

Describe the restore process: load the snapshot, apply any necessary transformations (like TTL adjustment), and atomically swap the new state into place. Discuss how to handle concurrent writes during restore.

5. Address Trade-offs and Edge Cases

Discuss trade-offs between storage cost, restore time, and consistency. Cover edge cases like keys expiring during backup, clock skew, and partial failures during restore.

Key Points to Mention

  • Use of copy-on-write or versioning to minimize snapshot overhead
  • Storing TTLs as absolute timestamps vs. relative durations and implications
  • Lazy expiration vs. eager expiration for TTL adjustment during restore
  • Atomicity and consistency guarantees during restore (e.g., using a shadow copy)
  • Handling of keys that expire between snapshot and restore
  • Scalability considerations for large datasets (e.g., distributed snapshots)

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