Design a Real-Time Analytics System that continuously processes streaming user watch data (received every 1 minute per user), and updates a dashboard every 1 hour to show the Top 10 most-watched movies/series within that hour.
Key Observations:
• A movie can span multiple hours.
• Partial watch sessions must be accumulated across multiple minute-wise events.
• The system must aggregate watch time correctly per user per movie per hour.
• Dashboard refreshes every hour with aggregated data from the past hour only.
🎯 Functional Requirements:
1. Ingest Watch Events:
• Format: user_id, movie_id, timestamp, watch_duration (e.g., 1 minute)
• Received continuously from frontend or device
2. Session Tracking:
• Handle users watching long movies across hour boundaries
• Aggregate minute-level logs into session-aware watch duration
3. Hourly Aggregation:
• Calculate total watch time per movie/series for each 1-hour window
• Determine Top 10 content by total watch time
4. Top 10 Dashboard:
• Shows title, watch time, thumbnail, and optional metadata
• Updates exactly at each hour (e.g., 12:00, 13:00, etc.)
⚙️ Non-Functional Requirements:
• Scalable to millions of users and thousands of movies
• Fault-tolerant: no data loss even if ingestion is delayed
• Low-latency dashboard queries (<500ms)
• Exactly-once or at-least-once processing of events
🧱 Core Components:
ComponentDescription
Event Ingestion Service
Receives watch events (Kafka, Kinesis)
Session Tracker
Aggregates watch time per user-movie-hour
Hourly Aggregator Job
Runs every hour, computes Top 10 movies by total watch time
Top Movies Store
Stores result of each hourly job for fast dashboard queries
Metadata Store
Holds movie titles, thumbnails, genres, etc.
Dashboard API
Serves hourly top 10 movies
Frontend
Displays the data in a clean UI
🔁 High-Level Flow:
1. Users stream watch_event every minute.
2. Events go to Kafka, written to raw store (like S3, HDFS).
3. Stream processor (Spark Streaming / Flink / Kafka Streams):
• Groups events by movie_id within each hourly time window.
• Sums up total watch duration per movie.
4. At the end of the hour:
• Aggregate and rank by total watch time.
• Store Top 10 into top_movies_hourly table.
5. Dashboard API queries top_movies_hourly for the current hour.
6. UI displays the list.
🛢️ Schema Design:
watch_events_raw
1 sql
2 CopyEdit
3 user_id | movie_id | timestamp | watch_duration ( minutes )
movie_metadata
1 nginx
2 CopyEdit
3 movie_id | title | thumbnail_url | genre | duration
top_movies_hourly
1 nginx
2 CopyEdit
3 hour_timestamp | movie_id | total_watch_time | rank
🧰 Suggested Tech Stack:
LayerTools
Ingestion
Kafka / Kinesis
Processing
Apache Flink / Spark Structured Streaming
Storage
S3 / HDFS (raw), PostgreSQL / DynamoDB (aggregated)
API Layer
Node.js / Go / FastAPI
Caching
Redis (for fast dashboard reads)
UI
React / Next.js
📈 Scalability Considerations:
• Use windowed aggregation in streaming engine with tumbling windows (e.g., [12:00-13:00), [13:00-14:00), etc.)
• Scale ingestion and aggregation using partitions and parallelism
• Use checkpointing for stream recovery
• Serve dashboard results from a cached or denormalized store
🔒 Security & Reliability:
• Deduplicate events using event_id if needed
• Validate timestamps (avoid malformed data)
• Implement idempotent writes to hourly store
• Alerting on dropped data or spikes in latency
🔄 Example Event:
1 json
2 CopyEdit
3 {
4 "user_id" : "U123" ,
5 "movie_id" : "M456" ,
6 "timestamp" : "2025-07-23T13:42:00Z" ,
7 "watch_duration" : 1
8 }
📊 Extensions:
• Add filtering by region, language, or genre
• Show trending deltas (compare with previous hour)
• Drill-down per user or per device
• Heatmaps or graphs showing hourly engagement