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
Schema Design for User Activity
00:00
5 left

Schema Design for User Activity

HardSQL · PostgreSQL

Problem

Tell me about how you would design a schema for a new user-activity tracking feature to ensure low-latency querying at AWS.

For this hands-on exercise, use the provided tables to represent the schema and write the query needed to retrieve a recent activity summary. Restrict activity to the inclusive start and exclusive end timestamps specified in the query.

Output

  1. One row per user, including users with no activity in the time range.
  2. Columns: user_id, email, activity_count, categories_seen, latest_activity_at, and latest_activity_name.
  3. Order by activity count descending, latest activity descending with nulls last, then user ID ascending.

Schema

users
ColumnTypeDescription
user_idPKBIGINTUnique user identifier
emailVARCHAR(255)User email address
activity_types
ColumnTypeDescription
activity_type_idPKINTUnique activity type identifier
activity_nameVARCHAR(100)Human-readable activity name
categoryVARCHAR(100)Activity category
user_activity_events
ColumnTypeDescription
event_idPKBIGINTUnique activity event identifier
user_idBIGINTReferenced user
activity_type_idINTReferenced activity type
occurred_atTIMESTAMPTime at which the activity occurred
event_sourceVARCHAR(80)Source that emitted the event
Tablesusersactivity_typesuser_activity_events
Interviewer

Your question is Schema Design for User Activity. 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.