PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Implement an Expiring Record Store

Last updated: May 19, 2026

Quick Overview

This question evaluates skills in designing and implementing an in-memory, level-based key-field-value store with lexicographic scanning, time-based versioning, TTL semantics, and efficient mutation operations.

  • medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Implement an Expiring Record Store

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Implement a level-based in-memory record store. The store contains records identified by a string `key`. Each record contains fields, where each `field` is a string and each `value` is a string. ### Level 1: Basic mutations Implement: - `set(key, field, value)`: Create the record if it does not exist, then set `field` to `value`. - `get(key, field)`: Return the current value for `field`, or `null` if the record or field does not exist. - `delete(key, field)`: Remove `field` from the record. Return `true` if a field was removed, otherwise return `false`. If a record becomes empty, it may be removed from the store. ### Level 2: Scanning Implement: - `scan(key)`: Return all fields for `key`, sorted lexicographically by field name. Format each item as `field(value)`. Return an empty list if the record does not exist. - `scan_by_prefix(key, prefix)`: Return only fields whose names start with `prefix`, sorted lexicographically by field name and formatted as `field(value)`. ### Level 3: Timestamps and TTL Extend the store so fields can be written with timestamps and optional time-to-live values. Implement: - `set_at(key, field, value, timestamp)`: Set the field at `timestamp` with no expiration. - `set_at_with_ttl(key, field, value, timestamp, ttl)`: Set the field at `timestamp`; it is visible for query times `t` such that `timestamp <= t < timestamp + ttl`. - `delete_at(key, field, timestamp)`: Delete the field at `timestamp` if it exists and is not expired at that time. Return `true` if a field was deleted, otherwise return `false`. - `get_at(key, field, timestamp)`: Return the value visible at `timestamp`, or `null` if none exists. - `scan_at(key, timestamp)`: Return all fields visible at `timestamp`, sorted and formatted as in `scan`. - `scan_by_prefix_at(key, prefix, timestamp)`: Return all visible fields at `timestamp` whose names start with `prefix`, sorted and formatted as in `scan_by_prefix`. Assume timestamps passed to timestamped operations are non-decreasing. A later write to the same `(key, field)` replaces the previous value and expiration policy. Expired or deleted fields must not appear in reads or scans.

Quick Answer: This question evaluates skills in designing and implementing an in-memory, level-based key-field-value store with lexicographic scanning, time-based versioning, TTL semantics, and efficient mutation operations.

Related Interview Questions

  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)
  • Solve a Key-Door Corridor Maze - Meta (medium)
  • Solve Array Merge and Parentheses Cleanup - Meta (medium)
Meta logo
Meta
Apr 1, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
0
0

Implement a level-based in-memory record store.

The store contains records identified by a string key. Each record contains fields, where each field is a string and each value is a string.

Level 1: Basic mutations

Implement:

  • set(key, field, value) : Create the record if it does not exist, then set field to value .
  • get(key, field) : Return the current value for field , or null if the record or field does not exist.
  • delete(key, field) : Remove field from the record. Return true if a field was removed, otherwise return false . If a record becomes empty, it may be removed from the store.

Level 2: Scanning

Implement:

  • scan(key) : Return all fields for key , sorted lexicographically by field name. Format each item as field(value) . Return an empty list if the record does not exist.
  • scan_by_prefix(key, prefix) : Return only fields whose names start with prefix , sorted lexicographically by field name and formatted as field(value) .

Level 3: Timestamps and TTL

Extend the store so fields can be written with timestamps and optional time-to-live values.

Implement:

  • set_at(key, field, value, timestamp) : Set the field at timestamp with no expiration.
  • set_at_with_ttl(key, field, value, timestamp, ttl) : Set the field at timestamp ; it is visible for query times t such that timestamp <= t < timestamp + ttl .
  • delete_at(key, field, timestamp) : Delete the field at timestamp if it exists and is not expired at that time. Return true if a field was deleted, otherwise return false .
  • get_at(key, field, timestamp) : Return the value visible at timestamp , or null if none exists.
  • scan_at(key, timestamp) : Return all fields visible at timestamp , sorted and formatted as in scan .
  • scan_by_prefix_at(key, prefix, timestamp) : Return all visible fields at timestamp whose names start with prefix , sorted and formatted as in scan_by_prefix .

Assume timestamps passed to timestamped operations are non-decreasing. A later write to the same (key, field) replaces the previous value and expiration policy. Expired or deleted fields must not appear in reads or scans.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Software Engineer•Meta Software Engineer•Meta Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ 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.