Design a scalable video platform database
Company: Google
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates relational database design and data engineering competencies—including schema modeling, many-to-many relationships, idempotent ingest, indexing and partitioning, OLTP versus analytics integration, GDPR-compliant deletion strategies, and query formulation—within the Data Manipulation (SQL/Python) domain for a Data Scientist role. It is commonly asked to assess both conceptual understanding and practical application of scalable data architectures, performance tuning, and compliance trade-offs, focusing on the ability to reason about schema choices, read/write optimization, and analytics integration without implementation details.
Daily watch-time per video
Tables
users(user_id BIGINT, username VARCHAR(50), created_at TIMESTAMP, is_deleted BOOLEAN)
videos(video_id BIGINT, uploader_user_id BIGINT, title VARCHAR(200), uploaded_at TIMESTAMP, is_deleted BOOLEAN)
views(view_id BIGINT, view_uuid VARCHAR(36), video_id BIGINT, viewer_user_id BIGINT, event_date DATE, viewed_at TIMESTAMP, watch_seconds INT, session_id VARCHAR(64))
comments(comment_id BIGINT, video_id BIGINT, user_id BIGINT, created_at TIMESTAMP, body VARCHAR(1000), is_deleted BOOLEAN, is_spam_flagged BOOLEAN, abuse_score INT)
Hints
- Aggregate watch_seconds grouped by event_date and video_id.
- Join to videos to return the video title.
Top N videos by unique viewers in a 7-day window
Tables
users(user_id BIGINT, username VARCHAR(50), created_at TIMESTAMP, is_deleted BOOLEAN)
videos(video_id BIGINT, uploader_user_id BIGINT, title VARCHAR(200), uploaded_at TIMESTAMP, is_deleted BOOLEAN)
views(view_id BIGINT, view_uuid VARCHAR(36), video_id BIGINT, viewer_user_id BIGINT, event_date DATE, viewed_at TIMESTAMP, watch_seconds INT, session_id VARCHAR(64))
comments(comment_id BIGINT, video_id BIGINT, user_id BIGINT, created_at TIMESTAMP, body VARCHAR(1000), is_deleted BOOLEAN, is_spam_flagged BOOLEAN, abuse_score INT)
Hints
- Use COUNT(DISTINCT viewer_user_id) grouped by video_id.
- Apply the explicit date filter and then LIMIT 2 with a deterministic tie-break.
Keyset pagination for comments with anti-abuse fields
Tables
users(user_id BIGINT, username VARCHAR(50), created_at TIMESTAMP, is_deleted BOOLEAN)
videos(video_id BIGINT, uploader_user_id BIGINT, title VARCHAR(200), uploaded_at TIMESTAMP, is_deleted BOOLEAN)
views(view_id BIGINT, view_uuid VARCHAR(36), video_id BIGINT, viewer_user_id BIGINT, event_date DATE, viewed_at TIMESTAMP, watch_seconds INT, session_id VARCHAR(64))
comments(comment_id BIGINT, video_id BIGINT, user_id BIGINT, created_at TIMESTAMP, body VARCHAR(1000), is_deleted BOOLEAN, is_spam_flagged BOOLEAN, abuse_score INT)
Hints
- Keyset pagination uses a strict 'less than cursor' condition on the (created_at, comment_id) sort key.
- Use the same ORDER BY as the keyset comparison, and LIMIT for page size.