Netflix Clickstream Pipeline + Trending Movies Dashboard

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2024-05-12

Problem Statement

Design a real-time data pipeline for ingesting Netflix clickstream events, and build a dashboard that, every hour, shows the top trending movies per location.


Only count views where the entire movie has been watched (full watch criteria) to qualify as a valid view.

🎯 Functional Requirements:

1.Clickstream Event Collection
•Collect events like play, pause, seek, stop, complete, etc., from various devices.
2.Event Filtering
•A view is considered valid only if the user watched 100% of the movie duration (configurable threshold like 95–100%).
3.Geo Tagging
•Each event must be tagged with the location (country/state/city) of the user/device.
4.Aggregation Job (Hourly)
•Every hour, aggregate:
•Number of valid views per movie
•Grouped by location
•Output: List of top N (e.g. 10) trending movies per location.
5.Dashboard
•Real-time or near-real-time dashboard to:
•Select location
•View top movies by hour
•Drill down into movie details (optional)


⚙️ Non-Functional Requirements:

•Handle high throughput (millions of events/hour)
•Exactly-once or idempotent processing of events
•Low latency (dashboard should update with minimal delay after the hour ends)
•Scalable and fault-tolerant
•Support schema evolution


🧱 System Components:

LayerComponentDescription

Data Source

Client SDKs

Emit clickstream events from devices (TV, web, mobile)

Ingestion

Kafka / PubSub

Collects real-time events

Processing

Apache Flink / Spark Streaming

Filters, aggregates full movie views per movie/location/hour

Storage

S3 / HDFS / BigQuery / Snowflake

Stores raw and processed event data

OLAP Engine

ClickHouse / Druid / Pinot

Powers fast queries for dashboard

Dashboard UI

React + Chart.js / Superset / Grafana

Displays top movies per location per hour

Orchestration

Airflow / dbt

Runs hourly batch/aggregation jobs (if not using streaming)


📦 Clickstream Event Schema:

1json 2CopyEdit 3{ 4 "event_type": "complete", 5 "user_id": "u123", 6 "movie_id": "m456", 7 "timestamp": "2025-07-23T09:55:00Z", 8 "watch_duration": 3600, 9 "movie_duration": 3600, 10 "location": { 11 "country": "India", 12 "city": "Mumbai" 13 }, 14 "device": "mobile" 15}
A view is valid if watch_duration >= 0.95 * movie_duration.


🔁 Processing Flow:

1.Event Ingestion
•Devices → Client SDK → Kafka topic clickstream-events
2.Stream Processing / Filtering
•Apache Flink filters only complete events where:
•watch_duration >= 0.95 * movie_duration
3.Hourly Aggregation
•Every hour: group by movie_id + location
•Count full views per movie per location
4.Sink
•Push top N movies per location per hour to:
•ClickHouse or Druid (for fast read)
•Or store summary in S3 with timestamp-based partitioning
5.Dashboard
•Query by:
•Hour timestamp
•Location
•Sorted list of top movies with view count


🛢️ Schema for Aggregated Table (OLAP Store):

hour_timestamplocationmovie_idview_count

2025-07-23 09

Mumbai, India

m123

921

2025-07-23 09

Mumbai, India

m456

851


🧠 Scalability Tips:

•Partition Kafka by region for better locality in stream processing
•Use watermarking and windowing in Flink for hourly bucketing
•Leverage approximate top-K algorithms (e.g., HyperLogLog + Count-Min Sketch) if needed
•Use materialized views in OLAP engine for fast retrieval


🔐 Security & Compliance:

•Handle PII (user ID, IP address) with data masking/anonymization
•GDPR-compliant data retention policies
•Secure transmission (TLS), IAM-based access control



Solution

Comments