← Gym/Mini Feature Store
00:00/ 25 min

🧭 Do not search for the first 15 minutes. When stuck: re-read the requirements → define I/O → choose the data structure → trace a small example by hand → write code.

Implement a FeatureStore that saves and serves per-entity feature values in front of model serving. The whole problem is honoring the API contract exactly — skim the spec and you will get it wrong.

Basic shape

python
store = FeatureStore()

store.set("user1", "clicks", 10)
store.set("user1", "purchases", 2)

store.get("user1", "clicks")     # 10
store.get_all("user1")           # {"clicks": 10, "purchases": 2}
  • Entities (user1) and feature names (clicks) are strings.
  • Values are ints or floats.

How missing keys behave — this is where answers diverge

CallWhen missing
get(entity, feature)None
get_all(entity)an empty dictionary (not None)
delete(entity, feature)does nothing (never raises)
increment(entity, feature, delta)starts at 0 and adds delta

get_all returns a copy. Mutating what it returns must not change the store.

Level structure

LevelAdded requirement
1set, get, get_all
2increment, delete
3entities(), snapshot() — whole-store reads

Each level must preserve the behavior of the previous ones.

Level 1 · Storing and reading

python
FeatureStore()
set(entity: str, feature: str, value) -> None
get(entity: str, feature: str)            # None when missing
get_all(entity: str) -> dict              # {} when missing
  • Writing set to an existing key overwrites it.
  • get_all returns every feature of that entity as {feature name: value}.
  • Mutating the dictionary get_all returned must not affect the store (return a copy).
  • get_all on an entity that was never stored returns an empty dictionary.