Design a Feature Store
Understanding the Problem
🗄️ What is a feature store? A feature store is the data system that sits between raw data and ML models. Teams define features once ("number of orders a user placed in the last 7 days", "a merchant's chargeback rate over 30 days"), and the feature store computes them, keeps their history for training and serves their latest values to models in production with millisecond latency. Feast is the best-known open-source one; Tecton, Databricks and the major clouds offer managed versions.
The reason it exists is a specific, painful bug. A model is trained on features computed one way in a Spark job over the warehouse, then served with features computed another way in a Java service. The two drift apart, or the training data quietly includes information that wasn't available at prediction time, and a model that looked great offline does poorly in production. A feature store fixes this by making one definition the source of both.
Functional Requirements
Clarify which users we're serving. Here it's ML engineers building ranking, fraud and recommendation models, who need the same features for training and for serving.
Core Requirements
- Users should be able to define features in code (the source, the transformation, the entity they're keyed on and how fresh they must be) and register them for reuse.
- The system should compute features from batch sources (the warehouse) and streaming sources (Kafka) and keep them up to date.
- Users should be able to generate training datasets in which every feature value is the one that was known at each label's timestamp (point-in-time correct).
- Models should be able to fetch the latest feature values for a set of entities at low latency during online inference.
Below the line (out of scope)
- Model training and serving themselves; see ML platform.
- Embedding search (nearest neighbor lookups). The feature store can store embeddings as values; similarity search belongs to a vector database.
- A rich discovery UI. We'll have a registry with search and ownership, nothing fancier.
Non-Functional Requirements
Ask your interviewer about the read path first, since it usually dominates. Our assumptions: 10,000 features in about 1,000 feature views, 500M users and 50M items as entities, and ranking services making 100,000 requests per second, each needing features for 1 user and 100 candidate items.
Core Requirements
- Online feature fetches should take under 10 ms at p99, since they sit inside a ranking budget of 100-200 ms.
- The online store should sustain on the order of 10M entity lookups per second and stay available at 99.99%, since every model depends on it.
- Streaming features should be fresh within a minute of the event; batch features within a day.
- Training datasets must be point-in-time correct, and the values used in training must match what serving would have returned (no training-serving skew).
- Generating a training set over a billion labeled rows should take hours, not days.
Below the line (out of scope)
- Strong consistency between the online and offline stores at every instant. Eventual consistency within the freshness bound is fine.
- Multi-region writes. We'll materialize into each region's online store from one pipeline.
Here's the math that shapes the online store. 100k requests × (1 user + 100 items) is about 10M entity reads per second. If we stored each feature as its own key and a model used 200 features, that would be 2 billion key reads per second, which is not a sensible thing to build. So we store all the features of one feature view for one entity as one value, and fetch an entity's views in one batched call.
Storage is manageable. 500M users × 300 user features × ~8 bytes is about 1.2 TB of raw values, perhaps 3-4 TB with keys, encoding overhead and replication. Items add less. That fits in a Redis cluster with a few hundred GB per shard group, but it's expensive in RAM, which pushes us toward an SSD-backed store for the long tail (deep dive 3).
The insight to say out loud: a feature store is two databases with very different jobs, a log of history for training and a key-value cache of "now" for serving, kept in sync by pipelines that run the same definitions. Most of the design is about keeping those two views consistent.