Personal project · 2026
Real-time feature store
Fraud-style user features computed from a stream of events, served in one Redis round trip, and reproducible point-in-time for training.
- Role
- On my own
- When
- 2026
- Type
- Personal project
- Stack
- Kafka, Redis, Snowflake, FastAPI
A consumer reads user events from Kafka with manual offset commits, updates rolling 1-hour and 24-hour features per user in Redis and appends to an event log in Snowflake. FastAPI serves single and batch lookups from Redis, and a point-in-time SQL join over the event log and labels builds training sets. Offsets are committed only after writes succeed.
How it works
- A consumer reads user events from Kafka and commits offsets only after its writes succeed, so replays don't double count.
- Rolling 1-hour and 24-hour features per user live in a Redis hash; FastAPI serves single and batch lookups.
- Every event is also appended to a Snowflake event log, and a point-in-time SQL join with labels builds training sets.
A decision worth explaining
One test feeds the same events to the online and offline paths and asserts identical features, which is how training/serving skew gets caught before it ships.
Status
23 tests in CI. Runs locally with Docker (Kafka in KRaft mode, Redis, consumer, API). Latency hasn't been benchmarked, so no numbers are claimed.
From the code
The point-in-time join for training data: each label only sees events at or before its own timestamp, and replayed duplicates are dropped first.
-- For every label, features are computed only from events at or before the
-- label's timestamp, so no row can see the future.
WITH events AS (
SELECT *
FROM user_features
QUALIFY ROW_NUMBER() OVER (PARTITION BY event_id ORDER BY written_at) = 1 -- drop replayed duplicates
),
latest_event AS (
SELECT l.user_id, l.label_ts, l.is_fraud,
e.event_ts AS last_event_ts, e.event_type, e.cart_value_usd, e.is_mobile
FROM labels l
LEFT JOIN events e
ON e.user_id = l.user_id
AND e.event_ts <= l.label_ts
QUALIFY ROW_NUMBER() OVER (PARTITION BY l.user_id, l.label_ts ORDER BY e.event_ts DESC NULLS LAST) = 1
),