# Feast Feature Store + Redis

> ready feature store for ML with Redis online store.

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

## Overview

Feast (Feature Store) is an open-source operational data system for managing and serving machine learning features to both training and serving workloads. Originally developed at Gojek and later open-sourced, Feast addresses the critical challenge of feature engineering consistency across ML pipelines by providing a centralized registry and serving layer for features. This eliminates the common problem where features computed differently between training and inference lead to model performance degradation in production. This stack combines Feast's feature server with Redis as the online store for low-latency feature retrieval, PostgreSQL for offline feature storage and metadata management, and the Feast UI for feature discovery and monitoring. Redis serves as the high-performance online store, enabling sub-millisecond feature lookups during model inference, while PostgreSQL handles the offline store responsibilities including feature materialization jobs and historical feature queries for training datasets. The combination provides both the speed required for real-time ML serving and the reliability needed for batch feature engineering workflows. This configuration is ideal for ML teams building production-grade feature infrastructure who need to serve features with consistent low latency while maintaining a robust offline pipeline for feature development and model training. The setup particularly benefits organizations transitioning from ad-hoc feature engineering to a more systematic MLOps approach, providing the foundation for feature reusability across multiple models and teams.

## Features

- Redis-backed online feature store with sub-millisecond feature retrieval for real-time inference
- PostgreSQL offline store for historical feature queries and point-in-time correct training data generation
- Feast feature server providing gRPC and HTTP APIs for feature retrieval with automatic serialization
- Feature registry with versioning and lineage tracking stored as protocol buffer format
- Web-based UI for feature discovery, monitoring, and validation with real-time feature statistics
- Automatic feature materialization from offline to online stores with configurable batch jobs
- Point-in-time correct joins for training data generation preventing data leakage
- Feature transformation engine supporting Python-based feature definitions and computations

## Use cases

- Real-time recommendation systems requiring low-latency user and item feature lookups
- Fraud detection models needing immediate access to user behavior and transaction features
- ML model serving pipelines requiring consistent feature computation between training and inference
- A/B testing frameworks where different model variants need access to the same feature definitions
- Multi-team ML organizations sharing features across recommendation, search, and personalization models
- Financial services applications serving credit scoring features with strict latency requirements
- E-commerce platforms providing personalized pricing and inventory features to multiple services

## Prerequisites

- Minimum 2GB RAM (1GB for PostgreSQL, 512MB for Redis, remainder for Feast services)
- Available ports 5432, 6379, 6566, and 8888 for database, cache, feature server, and UI respectively
- Environment variables POSTGRES_USER and POSTGRES_PASSWORD configured in .env file
- Understanding of feature engineering concepts and ML model serving architecture
- Python knowledge for defining feature transformations and data sources
- Basic familiarity with protocol buffers for feature registry configuration

## docker-compose.yml

```yaml
services:
  feast:
    image: feastdev/feature-server:latest
    environment:
      - FEAST_OFFLINE_STORE_TYPE=file
      - FEAST_ONLINE_STORE_TYPE=redis
      - FEAST_REDIS_HOST=redis
      - FEAST_REDIS_PORT=6379
      - FEAST_REGISTRY_PATH=/feast/registry.pb
    volumes:
      - feast-data:/feast
    ports:
      - "6566:6566"
    depends_on:
      - redis
    networks:
      - feast-network
    restart: unless-stopped

  redis:
    image: redis:alpine
    command: redis-server --appendonly yes
    volumes:
      - redis-data:/data
    ports:
      - "6379:6379"
    networks:
      - feast-network
    restart: unless-stopped

  postgres:
    image: postgres:15
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=feast
    volumes:
      - postgres-data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    networks:
      - feast-network
    restart: unless-stopped

  feast-ui:
    image: feastdev/feast-ui:latest
    environment:
      - FEAST_FEATURE_SERVER_URL=http://feast:6566
    ports:
      - "8888:8888"
    depends_on:
      - feast
    networks:
      - feast-network
    restart: unless-stopped

volumes:
  feast-data:
  redis-data:
  postgres-data:

networks:
  feast-network:
    driver: bridge
```

## .env

```bash
# Feast Feature Store
POSTGRES_USER=feast
POSTGRES_PASSWORD=secure_postgres_password

# Redis as online store
# PostgreSQL as offline store
```

## Usage notes

- Feature server at http://localhost:6566
- Feast UI at http://localhost:8888
- Redis for online serving
- PostgreSQL for offline storage
- Initialize with feast init

## Troubleshooting

- Feature server fails to start with registry errors: Ensure feast-data volume has proper write permissions and initialize with 'docker-compose exec feast feast init'
- Redis connection refused during feature retrieval: Verify Redis container is healthy and FEAST_REDIS_HOST environment variable matches the service name
- PostgreSQL connection timeout in offline queries: Check POSTGRES_USER and POSTGRES_PASSWORD environment variables are set correctly in the feast service
- Feast UI shows 'Feature server unreachable': Confirm FEAST_FEATURE_SERVER_URL points to http://feast:6566 and containers are on the same network
- Features not materializing to online store: Check Redis memory limits and ensure appendonly persistence is working with sufficient disk space

