Quick Overview

This question evaluates a candidate's proficiency in data manipulation and transaction aggregation using SQL or Python, encompassing time-zone-aware timestamp handling, pagination, late or missing events, cancellations and negative adjustments, rounding rules, and itemized breakdowns.

Compute dasher payout from API data

Company: DoorDash

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Onsite

Given a REST endpoint GET /payout that returns each delivery’s components (base pay, distance/time bonuses, promotions, tips, fees, adjustments, taxes, refunds) with timestamps, compute each Dasher’s total pay for a pay period. Handle pagination, missing/late events, time zones, partial-day boundaries, cancellations/chargebacks, negative adjustments, and rounding rules. Provide a Python or SQL implementation that aggregates per Dasher and outputs totals and itemized breakdowns; include test cases and discuss complexity.

Overview: This question evaluates a candidate's proficiency in data manipulation and transaction aggregation using SQL or Python, encompassing time-zone-aware timestamp handling, pagination, late or missing events, cancellations and negative adjustments, rounding rules, and itemized breakdowns.

You are given payout events for food-delivery couriers (Dashers). Each payout event represents a single monetary component associated with a delivery or adjustment: base pay, bonuses, promotions, tips, fees, taxes, refunds, or chargebacks. All payout events are stored in UTC. A bi-weekly pay period corresponding to 2025-05-20 to 2025-05-31 in America/Los_Angeles (UTC-7) is represented in UTC as: - start of pay period (inclusive): 2025-05-20 07:00:00 - end of pay period (inclusive): 2025-06-01 06:59:59 Your task: using the tables below, write a SQL query that computes each Dasher’s payout for this pay period with an itemized breakdown by component type. Requirements: 1. Include only payout_events whose event_timestamp is between '2025-05-20 07:00:00' and '2025-06-01 06:59:59' (inclusive). This handles the time-zone and partial-day boundary logic. 2. Events belong to the pay period when their event_timestamp falls in this window, even if the underlying delivery happened earlier or later (this models late tips or adjustments). 3. Handle cancellations, chargebacks, and negative adjustments correctly by treating the amount as-is (it can be negative and should reduce pay). 4. For each Dasher and component_type, compute the subtotal of amount and round it to 2 decimal places using standard rounding (ROUND(SUM(amount), 2)). 5. For each Dasher, compute net_total as the sum of the rounded component subtotals (so the net_total matches the sum of the displayed breakdown numbers, even if this differs slightly from rounding the grand sum directly). 6. Output one row per Dasher and component_type that occurs in the data, with columns: - dasher_id - dasher_name - component_type - component_total (rounded to 2 decimals) - net_total (sum of that Dasher’s rounded component_totals) Use only the tables and sample data described below. Do not assume any extra tables or columns.

Tables

dashers(dasher_id INT, dasher_name VARCHAR(50))

payout_events(payout_event_id INT, dasher_id INT, delivery_id INT, component_type VARCHAR(20), amount DECIMAL(10,3), event_timestamp TIMESTAMP)

Hints

  1. Filter payout_events by the explicit UTC timestamp window for the pay period.
  2. First aggregate and ROUND per dasher and component_type, then sum these rounded subtotals per dasher to get net_total.

Loading coding console...