Design Scalable Database and Analyze E-commerce Data
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-manipulation competencies, including schema modeling and normalization, SQL-based association analysis for co-purchases, and vectorized data transformation using Python/Pandas.
Design video platform schema
Tables
users(user_id INTEGER, email VARCHAR(255), created_at TIMESTAMP, country CHAR(2), status VARCHAR(20))
plans(plan_id INTEGER, name VARCHAR(50), price DECIMAL(10,2), currency CHAR(3), max_screens INTEGER, quality VARCHAR(20))
subscriptions(subscription_id BIGINT, user_id INTEGER, plan_id INTEGER, start_date DATE, end_date DATE, status VARCHAR(20), auto_renew BOOLEAN)
profiles(profile_id BIGINT, user_id INTEGER, profile_name VARCHAR(50), maturity_rating VARCHAR(10))
videos(video_id BIGINT, title VARCHAR(255), type VARCHAR(10), release_date DATE, duration_seconds INTEGER, rating VARCHAR(10))
video_assets(asset_id BIGINT, video_id BIGINT, language VARCHAR(10), resolution VARCHAR(10), codec VARCHAR(20))
genres(genre_id INTEGER, name VARCHAR(50))
video_genres(video_id BIGINT, genre_id INTEGER)
devices(device_id BIGINT, user_id INTEGER, device_type VARCHAR(50), os VARCHAR(50), registered_at TIMESTAMP)
views(view_id BIGINT, profile_id BIGINT, video_id BIGINT, device_id BIGINT, started_at TIMESTAMP, ended_at TIMESTAMP, seconds_watched INTEGER)
payments(payment_id BIGINT, user_id INTEGER, subscription_id BIGINT, amount DECIMAL(10,2), currency CHAR(3), paid_at TIMESTAMP, status VARCHAR(20), method VARCHAR(20))
transactions(user_id INTEGER, order_id INTEGER, product_id INTEGER, order_time DATE)
Hints
- Identify many-to-many relationships like videos-to-genres and use junction tables.
- Use surrogate primary keys (e.g., user_id, video_id) and composite keys where natural keys exist (e.g., order_id + product_id).
Top co-purchased product pairs
Tables
transactions(user_id INTEGER, order_id INTEGER, product_id INTEGER, order_time DATE)
Hints
- De-duplicate items within each order_id before forming pairs, to avoid over-counting.
- Self-join the order items on order_id and use a condition like product_id_1 < product_id_2 to avoid reversed/duplicate pairs.
Derive column from conditions
Tables
users(user_id INTEGER, email VARCHAR(255), created_at TIMESTAMP, country CHAR(2), status VARCHAR(20))
Hints
- Use a CASE expression in the SELECT clause to derive the segment value.
- Order the CASE conditions from most specific to least specific so they evaluate correctly.