Learning path: Data and Features in Production · Step 7 of 8
Feature Stores: Offline and Online Stores, and When You Actually Need One
Two pipelines, two definitions of the same feature, and a model that gets a number it never learned from. How one feature definition, an offline store and an online store fix that, and the honest signs that you need one.
What you will learn
- Explain a feature store as one definition per feature plus two places to keep the values
- Describe what the offline store gives training: full history, joined as of each event
- Describe what the online store gives serving: the latest value by key, fast, kept in sync by a copy step
- Decide honestly whether a team needs a feature store yet
Before you start
- Point-in-Time Correctness
- Training-Serving Skew
Anna and Ben cook in the same kitchen, from the same recipe. Anna grinds her cumin coarse, Ben grinds his fine. Same dish, same name on the menu, and it tastes different depending on who cooked it.
The fix is a shared pantry with labelled jars. The spice is ground once, and both cooks take from the same jar. Nobody grinds their own any more.
In machine learning, the jar label is one definition of a feature, and the cooks are your pipelines and models. That's the heart of a feature store. The honest question is: when do you really need one?
One feature, two pipelines
A ride app has one feature: rides in the last 30 days, rides_30d. Emma has 15 bookings in that window: 12 completed and 3 cancelled. (All numbers in this lesson are a made-up example.)
- The training pipeline is SQL, written by one person. It counts completed rides, so it says 12.
- The serving pipeline is app code, written by someone else. It counts every booking, so it says 15.
The model learned on values like 12, and in serving it gets 15. The same number now means something else. No error and no warning. This is training-serving skew, and here the cause is very simple: two definitions. Same name, same rider, same day, two numbers.
The label on the jar
The two rules can't both be right, so the team agrees on one, and writes it down once:
| Field | Value |
|---|---|
| name | rides_30d |
| about | one rider |
| rule | completed rides only |
| window | last 30 days |
Now training and serving don't write their own count. Both get the value from this one definition, so both get 12. When the rule changes, you change it here, once.
So at its heart, a feature store is one definition of each feature, then two places to keep the values, because training and serving need very different things.
The offline store: history, as of each event
The offline store keeps the full history: every value with the time it became true. Emma has six rows.
Training rows are past events, and each one needs the value from that moment. The event on 15 February goes to the store, everything after that date is off limits, and the last row at or before it says 10. The event on 10 March gets 13.
It never takes 12, the newest value, because that would be the leak from Point-in-Time Correctness. It's the same idea as merge_asof; the store does the join for you.
The online store: one lookup, the latest value
Serving needs something totally different. The online store keeps one row per rider and just the latest value. No history at all.
Emma books a ride. The request reaches a FastAPI service, and the model has to answer: will she cancel? The service sends one key, Emma, to the online store, and 12 comes straight back. Nothing is scanned; it's a lookup by key. The model answers, and that goes back to the app, because Emma is waiting.
Offline is big and remembers everything. Online is small and answers fast.
One computation, two stores
How do the two stay in sync? Emma finishes a ride. That event goes through the one definition, and her count goes from 12 to 13.
- 13 goes to the offline store first, as a new row. The old rows stay, because training needs them.
- A job copies the latest value to the online store, where it replaces the old one. Feast, an open-source feature store, calls this step materialize.
One honest catch: online is only as fresh as the last copy. Until that job runs, serving still sees 12. A check worth keeping: does the latest offline value match the online one? Here both say 13.
Do you need one?
To be honest, most teams start without one. They keep one shared function that both pipelines import, and one table of features. If you only score in batches, you don't need the online half at all.
A feature store has a cost: another system to run, jobs to watch, someone to fix it when it breaks, and one more tool to learn. Watch for the signs:
- Several models share the same features.
- Your online and offline values keep drifting apart.
- Several teams need the same features, and everyone is grinding their own.
One sign alone, you can often fix with that shared function. Several together, and it's worth the cost; Feast is one example to look at then. Start with the problem, not with the tool.
Quick recap
| Piece | Job | Emma's example |
|---|---|---|
| One definition | One place to change the rule | completed rides, last 30 days |
| Offline store | History for training, as of each event | 15 Feb gets 10, 10 Mar gets 13 |
| Online store | Latest value for serving, by key | Emma: 12 |
| Copy step | Keeps the two in sync | 13 reaches online after the job runs |
| The decision | Start without one until the signs show | Shared function first |
Try it yourself
Pick a model you built and write one feature's label: its name, its rule and its window. Would a second model reuse it? Do you need a store yet?
Built this? Share your solution in the StudyEasy AI Community.
Join free on Skool →Training-Serving Skew: Same Model, Different Inputs, and How to Detect It
Next →Data Versioning with DVC: Tie Every Model to the Exact Data That Trained It
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Machine Learning Engineer: From First Model to ML Engineer
Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (opens in a new tab)Related articles
Python Virtual Environments: One Project, One Toolbox
Why every Python project gets its own virtual environment: two projects that need different versions of requests, python -m venv .venv, activation, pip install and the PyCharm setting that activates it for you.
Git and GitHub Fundamentals: Commits, Branches, Push and Pull
The Git you use every day, on a tiny hello-ml project: commits as save points, the staging area, a branch merged with a fast-forward, then push, clone, pull and pull requests with a teammate.
Testing a FastAPI App with pytest: Three Small Tests
A tiny FastAPI app with a Hello World route and a name route that refuses numbers, three pytest tests that check it, and what happens when the validation is deleted by mistake.
Config and Logging Instead of Hard-Coded Values in ML Training
Take the hard-coded values out of a car price training script: one config.toml read with tomllib, logging with levels and a run id on every line, and secrets read from the environment. Same RMSE, 2195, before and after.