# Feast Feature Store

> Feature store for ML with offline and online serving.

- Category: AI & Machine Learning
- Difficulty: advanced
- Components: feast, redis, postgres
- Tags: feast, feature-store, mlops, features
- Source: https://docker.recipes/ai-ml/feast

## Overview

Feast (Feature Store) is an operational data system for managing and serving machine learning features to models in production. Originally developed by Gojek and later open-sourced, Feast addresses the critical challenge of feature engineering at scale by providing a centralized platform for storing, managing, and serving ML features with consistent offline training and online inference capabilities. The system bridges the gap between data engineering and machine learning by standardizing how features are defined, computed, stored, and retrieved across the entire ML lifecycle. This Docker configuration combines Feast's feature server with Redis as the online feature store and PostgreSQL as the offline feature store, creating a complete feature management pipeline. Redis provides sub-millisecond feature retrieval for real-time model inference, while PostgreSQL handles historical feature storage for training data generation and batch processing. The architecture enables teams to maintain feature consistency between training and serving environments, eliminating training-serving skew that commonly degrades model performance in production. This stack is ideal for ML teams building production systems that require both historical feature access for model training and low-latency feature serving for real-time predictions. The combination offers enterprise-grade reliability with PostgreSQL's ACID compliance for critical feature lineage and Redis's proven performance for high-throughput inference workloads, making it suitable for organizations scaling from prototype ML models to production feature stores serving thousands of requests per second.

## Features

- Dual-store architecture with Redis online store for sub-millisecond feature retrieval and PostgreSQL offline store for historical analysis
- Feature registry in PostgreSQL with versioning, lineage tracking, and metadata management for reproducible ML experiments
- Time-travel queries enabling point-in-time correct feature retrieval for training data generation without data leakage
- Materialization engine for syncing features from offline PostgreSQL storage to online Redis cache on configurable schedules
- Feature server REST API on port 6566 supporting both online feature retrieval and offline feature extraction
- Redis hash-based feature storage optimized for batch feature retrieval across multiple entities and feature groups
- PostgreSQL JSONB support for flexible feature schema evolution without breaking existing feature definitions
- Feast CLI integration for feature definition deployment, data source registration, and infrastructure management

## Use cases

- Real-time recommendation systems requiring millisecond feature lookups for user preferences, item embeddings, and contextual signals
- Fraud detection models needing historical transaction patterns from PostgreSQL and real-time account features from Redis
- ML model training pipelines requiring consistent feature definitions between offline training and online serving environments
- A/B testing frameworks where feature flags and user segments must be consistently applied across training and inference
- Financial trading algorithms needing both historical market data analysis and real-time feature serving for trade decisions
- Customer churn prediction models combining long-term behavioral patterns with real-time activity features
- MLOps platforms centralizing feature engineering across multiple data science teams and model deployments

## Prerequisites

- Minimum 2GB RAM (512MB for Redis online store, 1GB for PostgreSQL offline store, 512MB for Feast server)
- Docker Engine 20.10+ and Docker Compose 2.0+ with networking capabilities for inter-service communication
- Available ports 6566 (Feast API), 6379 (Redis), and 5432 (PostgreSQL) for service access
- Understanding of feature store concepts including entities, feature views, and online/offline stores
- Python environment for Feast SDK usage and feature definition management outside containers
- Basic knowledge of SQL for PostgreSQL feature queries and Redis data structures for online serving optimization

## docker-compose.yml

```yaml
services:
  feast:
    image: feastdev/feature-server:latest
    container_name: feast
    restart: unless-stopped
    command: feast serve -h 0.0.0.0 -p 6566
    volumes:
      - ./feature_repo:/feature_repo
    working_dir: /feature_repo
    ports:
      - "6566:6566"
    depends_on:
      - redis
      - postgres
    networks:
      - feast

  redis:
    image: redis:alpine
    container_name: feast-redis
    ports:
      - "6379:6379"
    networks:
      - feast

  postgres:
    image: postgres:16-alpine
    container_name: feast-postgres
    environment:
      POSTGRES_DB: feast
      POSTGRES_USER: feast
      POSTGRES_PASSWORD: feast
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - feast

volumes:
  postgres_data:

networks:
  feast:
    driver: bridge
```

## .env

```bash
# Initialize with: feast init feature_repo
```

## Usage notes

- Docs: https://docs.feast.dev/
- Feature server API at http://localhost:6566
- Initialize: feast init feature_repo, then cd feature_repo
- Register features: feast apply - reads feature_store.yaml
- Materialize: feast materialize-incremental $(date -u +%Y-%m-%dT%H:%M:%S)
- Get features: store.get_online_features(features=[...], entity_rows=[...])

## Troubleshooting

- Error 'No module named feast': Install Feast SDK locally with pip install feast for CLI operations outside containers
- feast apply fails with database connection error: Ensure PostgreSQL container is healthy and POSTGRES_DB environment matches feature_store.yaml configuration
- Feature server returns 404 for registered features: Run feast materialize to sync offline features to Redis online store before querying
- Redis connection timeout during high load: Increase Redis maxclients setting and consider Redis Cluster for horizontal scaling
- PostgreSQL disk space issues with large feature datasets: Implement table partitioning by date and configure automated cleanup policies
- Feast CLI commands hang: Verify feature_repo directory contains valid feature_store.yaml and feature definitions before running feast commands

