Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter 15: Feature Stores and Model Serving

In the previous chapter, we explored the end-to-end process of building ML pipelines. A key part of that process is feature engineering, the art and science of transforming raw data into the predictive signals that power machine learning models. In a large organization with many different ML models, it is common for different teams to independently create the same or similar features. This leads to duplicated effort, inconsistent feature definitions, and a significant challenge in managing and reusing these valuable assets. Furthermore, there is a critical and often painful problem that arises when moving a model from training to production: the training-serving skew. This occurs when the features used to train the model are different from the features used to make predictions in production, leading to a significant drop in model performance.

To solve these challenges, a new type of data system has emerged: the feature store. A feature store is a centralized platform for storing, managing, and serving machine learning features. It is a critical piece of infrastructure for any organization that wants to do machine learning at scale. This chapter is dedicated to the world of feature stores. We will explore the core concepts of a feature store and understand how it solves the key challenges of feature management. We will look at the leading open-source feature store, Feast, and understand its architecture. We will then move on to the closely related topic of model serving, exploring the different patterns and frameworks for deploying models into production. By the end of this chapter, you will understand how to build a robust and scalable platform for managing the entire lifecycle of your features and models.

15.1 The Feature Store: A Central Hub for Your ML Features

Why Do You Need a Feature Store?

A feature store is designed to solve several key problems in operational machine learning:

  1. Feature Reuse and Discovery: It provides a centralized registry where data scientists can discover and reuse existing features instead of reinventing the wheel. This accelerates the development of new models and ensures that features are defined consistently across the organization.

  2. Solving the Training-Serving Skew: This is the most critical problem that a feature store solves. It provides a single, consistent source of feature data for both model training and model serving. When you train a model, you get your feature data from the feature store. When you make a prediction in production, you get the feature data for that prediction from the same feature store. This guarantees that the features are computed in the same way in both environments, eliminating the training-serving skew.

  3. Point-in-Time Correct Joins: When building a training dataset, it is critical to use the feature values that were available at the time of the event you are trying to predict. For example, if you are building a model to predict customer churn, you need to use the customer’s feature values from before they churned. A feature store is designed to handle these complex, point-in-time correct joins, which are very difficult to do correctly with a traditional data warehouse.

  4. Feature Governance and Lineage: A feature store provides a centralized place to manage the metadata for your features, including their definitions, owners, and versions. It also provides lineage, allowing you to track how a feature was created and where it is being used.

The Architecture of a Feature Store

A typical feature store has several key components:

15.2 Feast: The Leading Open-Source Feature Store

Feast (Feature Store for ML) is the most popular open-source feature store. It was originally created by Gojek (a Southeast Asian super-app) and is now a part of the Linux Foundation AI & Data.

Feast provides a simple, declarative framework for defining, managing, and serving your features. It is designed to be a lightweight and modular feature store that can be integrated with your existing data infrastructure.

Key Concepts in Feast:

How Feast Works:

  1. Define Your Features: You define your features in a set of Python files in a Feast project.

  2. Deploy Your Feature Store: You run feast apply to deploy your feature definitions to the feature registry.

  3. Load Data into the Online Store: You run feast materialize to load the latest feature values from your offline store into your online store.

  4. Create a Training Dataset: You use the Feast SDK to generate a point-in-time correct training dataset from the offline store.

  5. Serve Features for Online Inference: You use the Feast SDK to retrieve the latest feature values from the online store for real-time predictions.

Feast is a powerful tool that provides a solid foundation for building a feature store. It is designed to be flexible and to integrate with the tools you are already using, such as Spark for transformation, Parquet for offline storage, and Redis for online storage.

15.3 Model Serving: From a File to a Service

Once you have a trained model, you need a way to serve it—to make it available to other applications to make predictions. Model serving is the process of deploying a trained model into a production environment and managing its lifecycle.

Model Serving Patterns

Model Serving Frameworks

While you can build your own model serving API using a web framework like Flask or FastAPI, there are several open-source frameworks that are specifically designed for model serving and provide features like batching, monitoring, and GPU support out of the box.

Optimizing Model Serving Performance

Serving a large ML model with low latency and high throughput can be a challenging engineering problem. Some common optimization techniques include:

15.4 Feature Stores and Model Serving on Alibaba Cloud

Alibaba Cloud provides a set of services that can be used to build a complete feature store and model serving platform.

By combining these services with an open-source feature store framework like Feast, you can build a powerful and flexible MLOps platform on Alibaba Cloud.

Chapter Summary

In this chapter, we have dived into two of the most critical components of a modern MLOps stack: the feature store and the model serving platform. We have understood how a feature store can solve the key challenges of feature reuse and the training-serving skew, and we have explored the architecture of the leading open-source feature store, Feast. We have also looked at the different patterns and frameworks for model serving, and we have discussed some of the key techniques for optimizing model serving performance. You should now have a clear understanding of how to build a robust and scalable platform for managing the entire lifecycle of your features and models.

In the next chapter, we will continue our journey into the world of AI data engineering by taking a deep dive into one of the most important and rapidly evolving areas of the field: vector databases and embeddings.