Tecton
An enterprise feature platform
An enterprise feature platform
Tecton is an enterprise-grade Feature Platform for machine learning. It manages feature engineering, storage, and serving in an integrated way, accelerating the production deployment and operation of ML models. It was founded by the team that developed Uber's Michelangelo.
Tecton prevents Training-Serving Skew and improves feature reusability, reducing model development time. It is used especially in domains where real-time ML is important, such as finance (fraud detection), e-commerce (recommendation), and ridesharing (pricing).
# features/user_features.py
from tecton import Entity, BatchSource, SnowflakeConfig, batch_feature_view
from datetime import timedelta
# Entity ์ ์ - ํผ์ฒ๊ฐ ์ฐ๊ฒฐ๋ ๋น์ฆ๋์ค ๊ฐ์ฒด
user = Entity(
name="user",
join_keys=["user_id"],
description="๊ณ ๊ฐ ์ํฐํฐ"
)
# ๋ฐ์ดํฐ ์์ค ์ ์
user_transactions = BatchSource(
name="user_transactions",
batch_config=SnowflakeConfig(
database="ANALYTICS",
schema="PUBLIC",
table="user_transactions",
timestamp_field="transaction_time"
)
)
# ๋ฐฐ์น Feature View ์ ์
@batch_feature_view(
sources=[user_transactions],
entities=[user],
mode="spark_sql",
batch_schedule=timedelta(days=1),
ttl=timedelta(days=30),
online=True,
offline=True,
feature_start_time=datetime(2023, 1, 1),
description="์ฌ์ฉ์ ๊ฑฐ๋ ํต๊ณ ํผ์ฒ"
)
def user_transaction_features(user_transactions):
return f"""
SELECT
user_id,
transaction_time,
COUNT(*) as transaction_count_30d,
SUM(amount) as total_amount_30d,
AVG(amount) as avg_transaction_amount,
MAX(amount) as max_transaction_amount,
COUNT(DISTINCT merchant_id) as unique_merchants_30d
FROM {user_transactions}
WHERE transaction_time >= CURRENT_DATE - INTERVAL '30 days'
GROUP BY user_id, transaction_time
"""
# features/realtime_features.py
from tecton import StreamSource, KafkaConfig, stream_feature_view
from tecton.types import Field, String, Int64, Float64, Timestamp
from datetime import timedelta
# Kafka ์คํธ๋ฆผ ์์ค
click_events = StreamSource(
name="click_events",
stream_config=KafkaConfig(
bootstrap_servers="kafka:9092",
topics=["user-clicks"],
timestamp_field="event_time"
),
schema=[
Field("user_id", String),
Field("event_time", Timestamp),
Field("page_id", String),
Field("session_id", String)
]
)
# ์ค์๊ฐ ์๋์ฐ ์ง๊ณ Feature
@stream_feature_view(
source=click_events,
entities=[user],
mode="spark_sql",
aggregation_interval=timedelta(minutes=1),
aggregations=[
Aggregation(column="page_id", function="count", time_windows=[
timedelta(minutes=5),
timedelta(minutes=30),
timedelta(hours=1)
]),
Aggregation(column="session_id", function="count_distinct", time_windows=[
timedelta(hours=1),
timedelta(hours=24)
])
],
online=True,
offline=True,
feature_start_time=datetime(2024, 1, 1),
description="์ค์๊ฐ ์ฌ์ฉ์ ํด๋ฆญ ํผ์ฒ"
)
def user_click_features(click_events):
return f"""
SELECT
user_id,
event_time,
page_id,
session_id
FROM {click_events}
"""
# feature_services/fraud_detection_service.py
from tecton import FeatureService
from features.user_features import user_transaction_features
from features.realtime_features import user_click_features
from features.device_features import user_device_features
# ์ฌ๋ฌ Feature View๋ฅผ ๋ฌถ์ด Feature Service ์์ฑ
fraud_detection_service = FeatureService(
name="fraud_detection_service",
features=[
user_transaction_features,
user_click_features,
user_device_features
],
description="์ฌ๊ธฐ ํ์ง ๋ชจ๋ธ์ฉ ํผ์ฒ ์๋น์ค"
)
# ----- ์ถ๋ก ์ ํผ์ฒ ์กฐํ (Python SDK) -----
import tecton
# Feature Service ๊ฐ์ ธ์ค๊ธฐ
fs = tecton.get_feature_service("fraud_detection_service")
# ์จ๋ผ์ธ ํผ์ฒ ์กฐํ (์ค์๊ฐ ์ถ๋ก )
features = fs.get_online_features(
join_keys={"user_id": "user_123"}
)
print(features.to_dict())
# {
# "transaction_count_30d": 45,
# "total_amount_30d": 12500.0,
# "avg_transaction_amount": 277.8,
# "user_click_features__page_id_count_5m": 12,
# "user_click_features__session_id_count_distinct_1h": 2,
# ...
# }
# ์คํ๋ผ์ธ ํผ์ฒ ์กฐํ (ํ์ต ๋ฐ์ดํฐ ์์ฑ)
training_events = spark.read.parquet("s3://bucket/training_events/")
training_data = fs.get_historical_features(
spine=training_events, # user_id, timestamp ์ปฌ๋ผ ํฌํจ
timestamp_key="event_timestamp"
).to_spark()
training_data.write.parquet("s3://bucket/training_features/")
# REST API ํธ์ถ ์์
import requests
TECTON_API_URL = "https://app.tecton.ai/api/v1/feature-service/get-features"
TECTON_API_KEY = "your-api-key"
headers = {
"Authorization": f"Tecton-key {TECTON_API_KEY}",
"Content-Type": "application/json"
}
payload = {
"params": {
"feature_service_name": "fraud_detection_service",
"join_key_map": {
"user_id": "user_123"
},
"workspace_name": "production"
}
}
response = requests.post(
TECTON_API_URL,
headers=headers,
json=payload
)
features = response.json()["result"]["features"]
print(features)
# [45, 12500.0, 277.8, 12, 2, ...]
Take a mock interview on this topic โ WIA SOOM AI Interview ยท Start for free
Be sure to use Point-in-Time Join when generating training data. If future data is used at a past point in time, Data Leakage occurs, in which the model shows better performance than it actually has.
Even with the same feature definition, values in the Online Store and Offline Store can differ. Carefully verify the aggregation window, timezone, and null handling logic.
Batch features incur delay according to batch_schedule. Implement features where real-time freshness matters with a Stream Feature View, and set the TTL appropriately to prevent serving stale data.
Costs for the Online Store (DynamoDB, Redis) and streaming compute can increase. Rather than serving all features online, set only the features needed for real-time inference to online=True.
When changing a feature schema, check compatibility with existing models. Adding a new feature is safe, but deleting an existing feature or changing its type can affect models that are being served.
SDK reference, tutorials, architecture guides
docs.tecton.ai