Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Repl Session Activity Timeline Analytics

MediumSQL · PostgreSQL00:00
I
Practice interviewer
In session
5 left
00:00

Your question is Repl Session Activity Timeline Analytics. Start with the requirements and the one table on the right.

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.

Problem

Business Context

Replit runs multiplayer coding sessions where multiple users collaborate in real time on the same Repl. At peak, the platform supports millions of daily active users and hundreds of thousands of concurrent sessions. Product and Trust & Safety teams need reliable analytics to understand who was active, when they were active, and what actions they performed (editing, running code, chat, file operations). These metrics drive decisions like collaboration UX improvements, abuse detection, and capacity planning.

You’re given a simplified event schema that tracks session membership and user actions. Events arrive from clients and servers and may be slightly out of order; however, event_ts is the canonical timestamp.

Task

Write a SQL query that produces a per-user activity summary per session for a given day.

Assume you are analyzing activity for 2025-01-15 (UTC).

Requirements

Return one row per (session_id, user_id) that had at least one event on 2025-01-15, with:

  1. session_id, user_id
  2. first_event_ts: earliest event timestamp for that user in that session on that day
  3. last_event_ts: latest event timestamp for that user in that session on that day
  4. event_count: total number of events for that user in that session on that day
  5. active_minutes: number of distinct minutes (UTC) in which the user produced at least one event in that session on that day
  6. top_action_type: the most frequent action_type for that user in that session on that day; break ties by choosing the lexicographically smallest action_type

Order results by session_id, then event_count descending, then user_id.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
handleVARCHAR(50)Public username/handle
created_atTIMESTAMPAccount creation timestamp
repl_sessions
ColumnTypeDescription
session_idPKVARCHAR(20)Unique multiplayer session id
repl_idVARCHAR(20)Underlying Repl identifier
started_atTIMESTAMPSession start time
ended_atTIMESTAMPSession end time; NULL if still active
session_participants
ColumnTypeDescription
session_idPKVARCHAR(20)Session id
user_idPKINTUser id
joined_atTIMESTAMPWhen the user joined the session
left_atTIMESTAMPWhen the user left the session; NULL if still present
roleVARCHAR(20)Participant role (owner/collaborator/viewer)
session_events
ColumnTypeDescription
event_idPKBIGINTUnique event id
session_idVARCHAR(20)Session id where the event occurred
user_idINTUser who performed the action
event_tsTIMESTAMPEvent timestamp in UTC
action_typeVARCHAR(30)Action category (edit/run/chat/etc.)
action_metadataVARCHAR(255)Additional metadata (often JSON)
Tablessession_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results