Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Optimizing Skewed Joins
00:00
5 left

Optimizing Skewed Joins

HardSQL · PostgreSQL

Problem

Given two large tables with highly skewed distribution keys, how would you optimize a complex SQL JOIN operation to avoid performance bottlenecks for Roku-scale datasets?

Using the supplied PostgreSQL tables, write the query that returns the requested result while demonstrating a skew-aware execution strategy. Assume content IDs 1 and 2 are identified as heavily skewed keys.

Output

  1. One row per active content item with qualifying playback events and a matching channel.
  2. Columns: content_id, title, channel_name, total_watch_seconds, and event_count.
  3. Include playback events from January 2025 only, exclude null content IDs, and sort by total watch seconds descending, then content ID ascending.

Schema

viewing_events
ColumnTypeDescription
event_idPKBIGINTUnique playback event identifier
content_idINTContent item associated with the event
viewer_idBIGINTViewer identifier
event_dateDATEDate on which the event occurred
event_typeVARCHAR(30)Playback event classification
watch_secondsINTNumber of seconds watched
content_catalog
ColumnTypeDescription
content_idPKINTUnique content identifier
titleVARCHAR(150)Content title
channel_idINTOwning channel identifier
is_activeBOOLEANWhether the content is currently active
channels
ColumnTypeDescription
channel_idPKINTUnique channel identifier
channel_nameVARCHAR(100)Display name of the channel
Tablesviewing_eventscontent_catalogchannels
Interviewer

Your question is Optimizing Skewed Joins. Start with the requirements and the three tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.