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
ExperiencesCoaching
New
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
Get started

Optimize for Performance and Scale

HardCoding00:00
Practice interviewer
In session
5 left
00:00

Whenever you're ready, walk me through how you'd approach this.

You need to log in / sign up to chat or submit.

Problem

You're a software engineer on HP's supply chain data team. This query powers a dashboard that lists pending print-supply orders for the West region, and it has gotten so slow that the dashboard times out as order volume has grown.

-- orders(order_id, customer_id, region, status, created_at)
-- order_items(item_id, order_id, product_id, quantity, unit_price)

SELECT DISTINCT o.order_id, o.customer_id, o.region, o.created_at,
       (SELECT SUM(oi.quantity * oi.unit_price)
        FROM order_items oi
        WHERE oi.order_id = o.order_id) AS order_total,
       (SELECT COUNT(*)
        FROM order_items oi2
        WHERE oi2.order_id = o.order_id) AS item_count
FROM orders o
WHERE UPPER(o.status) = 'PENDING'
  AND o.region LIKE '%WEST%'
ORDER BY order_total DESC;

Explain why this query is slow and unlikely to scale as the orders table grows, and describe exactly how you would rewrite it. You don't need to submit a full patch, just walk through each performance problem and your fix for it.