CineMatch

Kafka to Spark streaming to time-decayed ALS re-ranking, served as personalised top-10s in under 5 ms.

Data Engineering2026All work

Fig. 01CineMatch on Hugging Face Spaces, live pipeline with Top Picks and session feed.
CineMatch on Hugging Face Spaces, live pipeline with Top Picks and session feed.

What it is

What it does

CineMatch serves personalised movie top-10s under 5 ms from a genuine streaming stack: clickstream events land in Kafka, Spark Structured Streaming re-ranks ALS candidates with time-decayed preference vectors every 10 seconds, and FastAPI pushes refreshed lists to a React dashboard over WebSockets. Four serving fallbacks mean the page is never blank.

Why it exists

I've watched batch recommenders serve yesterday's taste at lunch and go blank the second Redis hiccups. I wanted to see a click turn into a re-ranked top-10 within seconds, with fallbacks that keep the page alive and an A/B test that measures the real serving path, not a UI toggle.

< 5 ms
Serving latency
4
Fallback layers
10
Docker services

Repo Amit-kr26/CinematchDemo huggingface.co/spaces/Amit-kr26/CinematchStack Python · Kafka · Spark · Redis · PostgreSQL · FastAPI · React · Docker

Lite single-container build on a free Hugging Face Space, so it needs a minute to boot. The full 10-service stack runs locally via docker-compose.

Build7decisions

How it is built

Streaming spine

Kafka 3.9 in KRaft mode (3 partitions, no Zookeeper) ingests browser and simulator events; Spark Structured Streaming consumes 10-second micro-batches and routes invalid events to a dead-letter queue inspectable at GET /events/dlq.

ALS backbone

ALS (rank=50, regParam=0.1) trains on MovieLens 1M with leave-one-out evaluation; item factors, top-100 candidates per user and exposure-damped popularity are seeded into Redis, with NDCG@10 / Precision@10 logged to MLflow.

Time-decay scoring

Each event weighs exp(−0.001 · age_s) × type weight (click 1.0, view 1.5, like 2.5, rating 3.0) × rating strength; the L2-normalised preference vector is dotted against item factors plus a 0.15 genre-overlap bonus.

Diversity guard

From the fourth title of a primary genre, scores scale by 0.7^(c−2) (boosted for positives, damped for negatives) so recommendation lists don't collapse into a single genre.

Four-layer fallback

Redis re-ranked cache (TTL ~5 min) → PostgreSQL user_recs (treatment-only, skipped past 30 min staleness) → static ALS candidates → global popularity. Sub-2 ms hits at every layer; no blank page possible.

Serving-path A/B test

Deterministic hash bucketing where assignment genuinely gates serving: control users read the static ALS key, treatment users get event-re-ranked lists, and impressions and engagements stream into GET /stats/ab CTR.

Hot reload + observability

The streaming job polls model:version every ~10 minutes and swaps item factors in place without restart; Prometheus exposes latency histograms, cache-hit counters and DLQ depth beside Grafana boards.

How the pieces connect

Events in, list out Train, serve and watch Browser + simulator clicks, views, likes FastAPI /simulate browser's producer Kafka 3 partitions, 2 sources Spark re-rank 10 s batches, exp decay Redis · recs key re-ranked, TTL 300 ALS bootstrap MovieLens 1M, MLflow Redis + Postgres ALS keys, user_recs FastAPI serve 4 layers, A/B hash React top-10 WS push, TMDB Grafana latency, cache hits treatment reads recs, control reads ALS via Prometheus

Also filed under Data Engineering