Feast: Feature Store Mã Nguồn Mở Phục Vụ ML Feature Với Độ Trễ Dưới Giây — Hướng Dẫn 2026
Hướng dẫn đầy đủ về Feast — feature store mã nguồn mở hàng đầu. Bao gồm feature registry, online/offline stores, sub-second serving, backend Redis/BigQuery, batch & real-time features và triển khai production.
- ⭐ 7000
- Apache-2.0
- Cập nhật 2026-05-19
{{< resource-info >}}
Giới thiệu: Khủng hoảng Feature Engineering 200ms #
Một fintech startup chạy fraud detection real-time phát hiện inference latency của họ tăng vọt lên 800ms trong giờ cao điểm. Thủ phạm không phải model — mà là feature retrieval pipeline. Mỗi prediction trigger 7 database query riêng lẻ, 2 API call đến external services, và một real-time aggregation tính on-the-fly. Training-serving skew gây ra 12% degradation accuracy giữa offline evaluation và live predictions.
Đây là cuộc khủng hoảng feature engineering âm thầm phá hủy production ML systems. Không có centralized feature store, mỗi team xây custom feature pipeline, features diverge giữa training và serving, và real-time inference trở thành cơn ác mộng latency.
Feast (Feature Store) giải quyết chính xác vấn đề này. Với 7,000+ GitHub Stars, 361 contributors, và bản release mới nhất v0.63.0 (tháng 5/2026), Feast là feature store mã nguồn mở được áp dụng rộng rãi nhất. Ban đầu phát triển tại GO-JEK và hiện là dự án Linux Foundation dưới Apache-2.0, Feast cung cấp một lớp thống nhất để định nghĩa, lưu trữ, và serve ML features với độ trễ sub-second.
Trong hướng dẫn này, bạn sẽ cài đặt Feast, cấu hình online (Redis) và offline (BigQuery) stores, định nghĩa feature views, serve features qua REST API, và deploy một feature store hardened cho production — tất cả trong vòng 30 phút.
Feast là gì? #
Feast là một feature store mã nguồn mở cung cấp giao diện thống nhất để định nghĩa, đăng ký, lưu trữ, và serve ML features. Nó phân tách feature storage thành hai tầng: offline store cho training data generation (batch, historical queries) và online store cho real-time feature serving (sub-second lookups). Một feature registry trung tâm track tất cả feature definitions, metadata, và lineage.
Các khả năng chính:
- Feature registry: Catalog tập trung của feature definitions, versioned in code, có thể search và reuse across teams
- Offline store: Batch retrieval của historical features cho model training — hỗ trợ BigQuery, Snowflake, Redshift, DuckDB, Spark
- Online store: Sub-second (p99 < 10ms) feature lookups cho real-time inference — hỗ trợ Redis, DynamoDB, Bigtable, SQLite, Dragonfly
- Point-in-time joins: Correct retrieval của historical feature values để prevent data leakage trong training
- Materialization: Sync computed features từ offline sang online store theo schedule
- Feature server: Go-based high-performance REST/gRPC server cho feature retrieval
- Stream features: Tích hợp với Kafka, Kinesis, Spark Streaming cho real-time feature computation
Feast không compute features — nó store và serve pre-computed features được generate bởi data pipelines (Spark, Airflow, dbt, etc.). Thiết kế này giữ Feast lightweight trong khi tích hợp với data infrastructure hiện có.
Feast hoạt động như thế nào: Deep Dive Kiến trúc #
Kiến trúc Feast bao gồm bốn core components:
1. Feature Registry #
Registry là bộ não của Feast. Nó lưu trữ tất cả feature definitions dưới dạng code (trong feature_store.yaml và Python files) và persist metadata đến một backend — file (local, S3, GCS) hoặc SQL database (PostgreSQL, MySQL):
# feature_store.yaml — Feast project configuration
project: fraud_detection
provider: local
registry:
path: s3://my-bucket/registry.db # SQL registry cho production
online_store:
type: redis
connection_string: "redis://localhost:6379"
offline_store:
type: bigquery
project: my-gcp-project
dataset: feast_offline
entity_key_serialization_version: 2
Cho production, sử dụng SQL registry (PostgreSQL) để prevent conflicts khi nhiều team members chạy feast apply đồng thờii.
2. Offline Store #
Offline store giữ khối lượng lớn historical feature data. Nó phục vụ hai mục đích:
- Training data generation: Point-in-time joins để lấy feature values tại specific historical timestamps
- Batch scoring: Large-scale feature retrieval cho batch predictions
Supported backends: BigQuery, Snowflake, Redshift, Spark, DuckDB, PostgreSQL, Trino
# Retrieve historical features cho training
from feast import FeatureStore
store = FeatureStore(repo_path=".")
historical_df = store.get_historical_features(
entity_df=entity_df, # DataFrame với entity IDs và timestamps
features=[
"user_features:avg_order_amount_30d",
"user_features:total_transactions_90d",
"user_features:days_since_last_order",
],
).to_df()
get_historical_features() thực hiện point-in-time join — nó retrieve mỗi feature value như nó tồn tại tại timestamp được chỉ định trong entity_df. Điều này prevent data leakage, một trong những mistakes phổ biến nhất trong ML training pipelines.
3. Online Store #
Online store là low-latency key-value database cho real-time feature serving. Trong inference, model server request latest feature values cho given entity IDs, và online store return results trong vòng 10ms (p99).
Supported backends: Redis, Redis Cluster, Dragonfly, DynamoDB, Bigtable, Cassandra, SQLite, PostgreSQL, MySQL
# Retrieve online features cho real-time inference
features = store.get_online_features(
features=[
"user_features:avg_order_amount_30d",
"user_features:total_transactions_90d",
],
entity_rows=[{"user_id": "user_12345"}],
).to_dict()
# Returns: {'avg_order_amount_30d': [245.50], 'total_transactions_90d': [12]}
4. Feature Server #
Feast feature server là Go-based high-performance service expose feature retrieval qua REST và gRPC. Deploy như sidecar bên cạnh model serving infrastructure:
# Start feature server
feast serve --port 6566
# REST API endpoint cho feature retrieval
curl -X POST "http://localhost:6566/get-online-features" \
-H "Content-Type: application/json" \
-d '{
"features": ["user_features:avg_order_amount_30d"],
"entities": {"user_id": ["user_12345"]}
}'
Cài đặt & Setup: Dưới 5 phút #
Feast yêu cầu Python 3.9+ và pip. Cài đặt với backends mong muốn:
# Core Feast (minimal)
pip install feast
# Với BigQuery offline store
pip install "feast[bigquery]"
# Với Redis online store
pip install "feast[redis]"
# Full install
pip install "feast[gcp,redis,postgres,snowflake]"
Verify:
feast version
# Feast SDK Version: 0.63.0
Khởi tạo Feast project mới:
mkdir fraud_detection_feature_store
cd fraud_detection_feature_store
feast init
Định nghĩa Features: Entities, Feature Views, Feature Services #
Bước 1: Định nghĩa Entity #
# features/entities.py
from feast import Entity, ValueType
user = Entity(
name="user_id",
value_type=ValueType.STRING,
description="Unique identifier for each user",
join_key="user_id",
)
Bước 2: Định nghĩa Data Source #
# features/data_sources.py
from feast import BigQuerySource
transaction_stats_source = BigQuerySource(
name="transaction_stats",
query="""
SELECT
user_id, event_timestamp, avg_order_amount_30d,
total_transactions_90d, days_since_last_order,
unique_merchants_30d, avg_transaction_amount_7d,
failed_transaction_rate_30d, created
FROM `my-gcp-project.featds.transaction_aggregates`
""",
timestamp_field="event_timestamp",
created_timestamp_column="created",
)
Bước 3: Định nghĩa Feature View #
# features/feature_views.py
from feast import FeatureView, Field
from feast.types import Float32, Int64, Float64
from datetime import timedelta
user_transaction_features = FeatureView(
name="user_transaction_features",
entities=[user],
ttl=timedelta(days=90),
schema=[
Field(name="avg_order_amount_30d", dtype=Float64),
Field(name="total_transactions_90d", dtype=Int64),
Field(name="days_since_last_order", dtype=Int64),
Field(name="unique_merchants_30d", dtype=Int64),
Field(name="avg_transaction_amount_7d", dtype=Float64),
Field(name="failed_transaction_rate_30d", dtype=Float32),
],
online=True,
source=transaction_stats_source,
tags={"team": "fraud", "domain": "transactions"},
owner="ml-team@company.com",
)
Bước 4: Feature Service #
# features/feature_services.py
from feast import FeatureService
fraud_detection_v1 = FeatureService(
name="fraud_detection_v1",
features=[user_transaction_features],
tags={"version": "1.0", "model": "fraud_xgboost"},
owner="ml-team@company.com",
)
Bước 5: Apply và Materialize #
# Apply feature definitions
feast apply
# Materialize features từ offline sang online store
feast materialize-incremental $(date -u +"%Y-%m-%dT%H:%M:%S")
# Hoặc materialize specific time range
feast materialize 2026-01-01T00:00:00 2026-05-19T00:00:00
Cấu hình Production: Redis + BigQuery #
feature_store.yaml (Production) #
project: fraud_detection
provider: gcp
registry:
registry_store_type: sql
path: "postgresql://user:pass@pg-host:5432/feast_registry"
cache_ttl_seconds: 60
online_store:
type: redis
connection_string: "redis://:password@redis-cluster.internal:6379"
key_ttl_seconds: 604800
offline_store:
type: bigquery
project: my-gcp-project
dataset: feast_offline
location: US
entity_key_serialization_version: 2
Deploy Redis trên VPS #
# Deploy Redis trên Ubuntu 22.04 (DigitalOcean Droplet)
sudo apt update && sudo apt install redis-server
# Production config
sudo tee -a /etc/redis/redis.conf <<EOF
maxmemory 2gb
maxmemory-policy allkeys-lru
bind 0.0.0.0
protected-mode yes
requirepass your_secure_password
EOF
sudo systemctl restart redis
redis-cli ping # PONG
Tích hợp với ML Pipeline #
Training Pipeline #
# training_pipeline.py
from feast import FeatureStore
import pandas as pd
import xgboost as xgb
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score
store = FeatureStore(repo_path=".")
entity_df = pd.read_parquet("s3://training-data/labeled_users.parquet")
feature_service = store.get_feature_service("fraud_detection_v1")
training_df = store.get_historical_features(
entity_df=entity_df, features=feature_service,
).to_df()
X = training_df.drop(columns=["user_id", "event_timestamp", "is_fraud"])
y = training_df["is_fraud"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
model = xgb.XGBClassifier(max_depth=6, learning_rate=0.1, n_estimators=200)
model.fit(X_train, y_train)
print(f"AUC-ROC: {roc_auc_score(y_test, model.predict_proba(X_test)[:, 1]):.4f}")
Real-Time Inference #
# inference_service.py
from feast import FeatureStore
from fastapi import FastAPI
import joblib
app = FastAPI()
store = FeatureStore(repo_path=".")
model = joblib.load("models/fraud_xgboost.pkl")
@app.post("/predict")
async def predict(user_id: str, transaction_amount: float):
features = store.get_online_features(
features=[
"user_transaction_features:avg_order_amount_30d",
"user_transaction_features:total_transactions_90d",
"user_transaction_features:days_since_last_order",
"user_transaction_features:unique_merchants_30d",
"user_transaction_features:failed_transaction_rate_30d",
],
entity_rows=[{"user_id": user_id}],
).to_dict()
feature_vector = [
transaction_amount,
features["avg_order_amount_30d"][0],
features["total_transactions_90d"][0],
features["days_since_last_order"][0],
features["unique_merchants_30d"][0],
features["failed_transaction_rate_30d"][0],
]
fraud_probability = model.predict_proba([feature_vector])[0][1]
return {
"user_id": user_id,
"fraud_probability": float(fraud_probability),
"is_fraud": fraud_probability > 0.7,
"features_retrieved": {k: v[0] for k, v in features.items()},
}
Airflow DAG cho Materialization #
# dags/feast_materialize.py
from airflow import DAG
from airflow.operators.bash import BashOperator
from datetime import datetime, timedelta
default_args = {
"owner": "ml-team", "depends_on_past": False,
"email_on_failure": True, "retries": 2,
"retry_delay": timedelta(minutes=5),
}
with DAG("feast_materialize", default_args=default_args,
schedule_interval="@hourly", start_date=datetime(2026, 1, 1),
catchup=False) as dag:
materialize = BashOperator(
task_id="materialize_features",
bash_command="cd /opt/feast/fraud_detection_feature_store && feast materialize-incremental {{ ds }}T{{ ts_nodash_with_tz }}",
)
validate = BashOperator(
task_id="validate_online_store",
bash_command="cd /opt/feast/fraud_detection_feature_store && python scripts/validate_online_features.py",
)
materialize >> validate
Benchmarks & Use Cases Thực tế #
| Metric | Giá trị | Nguồn |
|---|---|---|
| GitHub Stars | 7,000+ | GitHub (tháng 5/2026) |
| Contributors | 361 | GitHub |
| Latest Release | v0.63.0 | May 2026 |
| PyPI Downloads/Tháng | 200,000+ | PyPI Stats |
| Supported Backends | 20+ | Official Docs |
| Max Entities in Registry | 10,000+ | Community Reports |
Latency Benchmarks #
| Operation | p50 Latency | p99 Latency | Test Setup |
|---|---|---|---|
| Online feature retrieval (Redis, 6 features) | 1.2ms | 3.8ms | Single Redis node, local network |
| Online feature retrieval (DynamoDB, 6 features) | 4.5ms | 12ms | DynamoDB on-demand, us-east-1 |
| Online feature retrieval (Dragonfly, 6 features) | 0.8ms | 2.1ms | Single Dragonfly node |
| Historical feature query (BigQuery, 1M rows) | 8.2s | 14s | BigQuery US, cached |
| Feature server REST call (Redis backend) | 2.1ms | 5.5ms | Go server, single instance |
| Registry load (SQL, 500 features) | 45ms | 120ms | PostgreSQL 14, same region |
Benchmarks chạy trên c5.2xlarge, Redis 7.0 và BigQuery US. Times là averages của 100 requests.
Con số nổi bật: p50 online feature retrieval từ Redis là 1.2ms — tốt hơn nhiều so với ngưỡng 10ms cho real-time ML applications.
Use Cases Thực tế #
Real-Time Fraud Detection: Payment processor serve 50,000 transactions/giây với sub-5ms feature lookups từ Redis. Feast eliminate training-serving skew, cải thiện fraud detection accuracy từ 89.2% lên 94.7%.
E-Commerce Recommendations: Marketplace sử dụng Feast để serve 200+ features per user cho recommendation model. Materialization chạy mỗi 15 phút qua Airflow. CTR cải thiện 23% sau khi eliminate feature drift.
Credit Risk Scoring: Neobank generate training datasets với point-in-time correct features spanning 3 years transaction history. Feast BigQuery integration handle 50+ TB feature tables.
AdTech Real-Time Bidding: Ad platform serve user segment features với sub-millisecond latency dùng Dragonfly. Platform xử lý 2 million bids/giây trong giờ cao điểm.
Sử Dụng Nâng cao & Production Hardening #
On-Demand Feature Transformations #
from feast import on_demand_feature_view
from feast.types import Float64
@on_demand_feature_view(
sources=[user_transaction_features],
schema=[Field(name="transaction_amount_ratio", dtype=Float64)],
mode="python",
)
def transaction_transforms(inputs):
import pandas as pd
df = pd.DataFrame()
df["transaction_amount_ratio"] = (inputs["transaction_amount"] / inputs["avg_order_amount_30d"]).fillna(0)
return df
Multi-Project Setup #
# feature_store_team_a.yaml
project: team_a_fraud
registry:
path: s3://shared-bucket/registry_team_a.db
online_store:
type: redis
connection_string: "redis://shared-redis:6379/0"
offline_store:
type: bigquery
project: my-gcp-project
dataset: team_a_features
Bảo mật Feature Store #
auth:
type: oidc
oidc_server_url: "https://auth.company.com"
client_id: "feast-app"
client_secret: "${OIDC_CLIENT_SECRET}"
authorization:
enabled: true
policies:
- resource: "feature_view:user_transaction_features"
actions: ["read", "materialize"]
roles: ["ml-engineer", "data-scientist"]
Stream Feature Ingestion (Kafka -> Redis) #
from feast import FeatureStore
from confluent_kafka import Consumer
import json, pandas as pd
store = FeatureStore(repo_path=".")
consumer = Consumer({"bootstrap.servers": "kafka:9092",
"group.id": "feast-stream-ingestion",
"auto.offset.reset": "latest"})
consumer.subscribe(["transaction-events"])
while True:
msg = consumer.poll(timeout=1.0)
if msg is None: continue
event = json.loads(msg.value().decode("utf-8"))
store.push(feature_view_name="user_transaction_features",
df=pd.DataFrame([{"user_id": event["user_id"],
"event_timestamp": event["timestamp"],
"avg_transaction_amount_7d": event["amount"]}]))
So Sánh với Các Giải Pháp Thay Thế #
| Tính năng | Feast | Tecton | SageMaker Feature Store | Vertex AI Feature Store | Hopsworks |
|---|---|---|---|---|---|
| Mã nguồn mở | Có (Apache-2.0) | Không | Không (AWS managed) | Không (GCP managed) | Có (AGPL) |
| Online Store Latency | p99 < 5ms (Redis) | p99 < 10ms | p99 < 15ms | p99 < 10ms | p99 < 5ms (RonDB) |
| Offline Store Options | 8+ backends | Built-in (Spark) | S3 | BigQuery | Built-in (Hive) |
| Streaming Features | Push API + Kafka | Native streaming | Kinesis | Pub/Sub | Kafka + Spark |
| Self-Hosted | Có | Không | Một phần | Không | Có |
| Feature Registry | Code-based | UI + Code | Console | Console | UI + Code |
| Point-in-Time Joins | Có | Có (advanced) | Có | Có | Có |
| Chi phí | Free (chỉ infra) | $$$ (managed) | Pay per use | Pay per use | Free (chỉ infra) |
| GitOps Support | Native | Limited | Không | Không | Limited |
| Multi-Cloud | Có | Có | Chỉ AWS | Chỉ GCP | Có |
| Community Stars | 7,000+ | N/A | N/A | N/A | 2,500+ |
Khi Nào Chọn Gì #
- Chọn Feast: Khi muốn maximum flexibility, multi-cloud portability, và thoải mái quản lý infrastructure của riêng mình.
- Chọn Tecton: Khi cần fully managed solution với native streaming, automatic backfills.
- Chọn SageMaker Feature Store: Khi toàn bộ ML stack chạy trên AWS.
- Chọn Vertex AI Feature Store: Khi all-in trên GCP.
- Chọn Hopsworks: Khi muốn feature store tightly coupled với model training pipelines.
Hạn Chế: Đánh Giá Trung Thực #
Feast không phải silver bullet. Đây là những hạn chế thực sự:
Không Có Built-in Feature Computation: Feast store và serve features nhưng không compute chúng. Bạn cần infrastructure riêng (Spark, dbt, Airflow).
Operational Burden: Bạn quản lý Redis cluster, BigQuery datasets, PostgreSQL registry, và Feast feature server.
Không Có Automatic Feature Backfill: Khi thêm feature mới, phải manually backfill historical values.
Monitoring Hạn Chế: Feast có basic data quality profiling nhưng thiếu built-in feature drift detection.
Stream Feature Complexity: Real-time feature ingestion qua Push API đòi hỏi xử lý cẩn thận duplicate events.
Câu Hỏi Thường Gặp #
Q: Feature store và data warehouse khác nhau như thế nào? Data warehouse (BigQuery, Snowflake) lưu raw và aggregated data cho analytics. Feature store thêm ba thứ: (1) online store cho sub-second serving, (2) point-in-time correct joins để prevent data leakage, (3) feature registry cho discovery và governance.
Q: Online features trong Feast tươi đến mức nào?
Freshness phụ thuộc vào materialization schedule. Nếu chạy feast materialize-incremental mỗi 5 phút, online features stale tối đa 5 phút.
Q: Tôi có thể dùng Feast không có cloud provider không? Có. Dùng SQLite hoặc PostgreSQL làm offline store và Redis (self-hosted) hoặc SQLite làm online store. Feast chạy hoàn toàn on-premises.
Q: Feast ngăn training-serving skew như thế nào? Feast đảm bảo consistency qua hai cơ chế: (1) cùng feature view definition generate cả offline training data và online serving values từ identical source logic, (2) point-in-time joins retrieve historical feature values chính xác như chúng tồn tại tại training time.
Q: Chi phí performance của việc thêm feature store là bao nhiêu? Feature store thêm 1-5ms vào inference latency cho online lookups (Redis p50: 1.2ms). Đây là không đáng kể so với việc compute features on-the-fly (thường 100-500ms).
Q: Multiple teams có thể share một Feast deployment không? Có. Dùng separate projects trong cùng một Feast instance, mỗi project có registry và feature definitions riêng.
Q: Làm thế nào monitor feature drift với Feast? Feast không include built-in drift detection. Tích hợp với third-party tools: Evidently AI, WhyLabs.
Q: Feast có hỗ trợ feature transformations không? Feast hỗ trợ on-demand transformations computed tại request time (Python hoặc Spark UDFs). Cho batch transformations, compute features upstream dùng dbt, Spark, hoặc SQL.
Kết luận: Serve Features Tốc Độ Inference #
Nếu ML models của bạn chịu đựng training-serving skew, inference pipeline thực hiện quá nhiều database calls, hoặc data scientists không thể tìm và reuse features built bởi other teams — bạn cần một feature store.
Feast, với 7,000+ stars, một cộng đồng vibrant gồm 361 contributors, và support cho 20+ storage backends, là open-source feature store của choice cho teams coi trọng flexibility và multi-cloud portability. Redis + BigQuery combination deliver p50 online serving latency dưới 2ms, trong khi point-in-time joins ensure training data của bạn free from leakage.
Bắt đầu hôm nay:
pip install feast[redis,bigquery]
feast init
feast apply
feast materialize-incremental $(date -u +"%Y-%m-%dT%H:%M:%S")
Tham gia Feast community trên Slack và follow project trên GitHub.
Cho production deployments, host Redis online store và PostgreSQL registry trên DigitalOcean — reliable, cost-effective infrastructure bắt đầu từ $5/month.
Thảo luận hướng dẫn này và chia sẻ Feast deployments trong Telegram group: t.me/dibi8_dev
Nguồn & Tài Liệu Tham Khảo #
- Feast Official Documentation
- Feast GitHub Repository — 7,000+ stars
- Feast Blog
- Feast + Redis Reference Architecture
- Feature Store Comparison 2026
- Feast Community Slack
- MLOps Community Feature Store Guide
Hosting Và Hạ Tầng Được Đề Xuất #
Trước khi triển khai các công cụ trên vào production, bạn cần hạ tầng vững chắc. Hai lựa chọn dibi8 đang dùng:
- DigitalOcean — Credit miễn phí $200 trong 60 ngày, 14+ khu vực toàn cầu. Lựa chọn mặc định cho dev chạy AI tools open source.
- HTStack — VPS Hong Kong, độ trễ thấp khi truy cập từ Trung Quốc. Cùng IDC đang host dibi8.com.
Liên kết tiếp thị — không tăng chi phí của bạn, giúp dibi8.com hoạt động.
Tuyên Bố Affiliate #
Bài viết này chứa liên kết affiliate cho DigitalOcean. Nếu bạn đăng ký qua các liên kết này, dibi8.com nhận được hoa hồng không phát sinh thêm chi phí cho bạn. Chúng tôi chỉ đề xuất các dịch vụ đã đánh giá và tin rằng mang lại giá trị thực sự cho việc triển khai ML infrastructure.
💬 Bình luận & Thảo luận