Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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 Slow JSON Processing
00:00
5 left

Optimizing Slow JSON Processing

MediumSQL · PostgreSQL

Problem

How do you optimize a script that is performing slowly on a large JSON dataset?

Write a PostgreSQL query that reports completed events from production batches in the requested date range. Extract only the required JSON attributes and exclude batches outside the range or from other source systems.

Output

  1. One row per batch date and event action.
  2. Columns: batch_date, action, event_count, and avg_duration_ms.
  3. Include completed events from production batches dated from 2026-01-01 through 2026-01-04, inclusive.
  4. Order by batch_date, then action.

Schema

event_batches
ColumnTypeDescription
batch_idPKINTUnique identifier for an ingestion batch
batch_dateDATEDate associated with the batch
source_systemVARCHAR(50)System that produced the batch
event_records
ColumnTypeDescription
record_idPKINTUnique identifier for an event record
batch_idINTBatch containing the event record
payloadVARCHAR(2000)JSON event payload stored as text
Tablesevent_batchesevent_records
Interviewer

Your question is Optimizing Slow JSON Processing. Start with the requirements and the two 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.