Current Status of Each Order from a Retried Event Stream

Last updated: November 29, 2026

Quick Overview

An order status event table receives duplicate rows because producers retry on timeouts. Write a query that returns the current status of every order created yesterday and a count of orders per status.

DoorDash
Data Manipulation (SQL/Python)
Data Engineer
DoorDash
November 29, 2026
Data Engineer
Phone Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


An order status event table receives duplicate rows because producers retry on timeouts. Write a query that returns the current status of every order created yesterday and a count of orders per status.

DoorDash order lifecycles (created, confirmed, picked up, delivered, cancelled) flow through event pipelines where at-least-once delivery creates duplicates. Analytics and data engineering screens use this to check that you dedupe with a window function and choose a sensible tie-break instead of reaching for DISTINCT.

What the Interviewer Expects
  • Use ROW_NUMBER partitioned by order_id rather than SELECT DISTINCT
  • Order by event time first, then a status precedence, then ingestion time
  • Scope by order creation date, not event date, so late events still count
  • Explain why exact duplicate rows are harmless with this approach
  • Mention how this becomes an incremental merge in a pipeline
Key Topics to Cover
deduplication
ROW_NUMBER
at-least-once delivery
tie-breaking
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you write this as an incremental MERGE into an order_current_status table?
  • What if clocks on different services disagree and a 'picked_up' event has an earlier timestamp than 'confirmed'?
  • How would you detect orders stuck in a non-terminal status for over two hours?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

Assume order_status_events(event_id, order_id, status, event_ts, ingested_at) where a retry produces a row with the same event_id, status and event_ts but a later ingested_at. A small lookup...

Approach

For every order keep exactly one row: the latest by producer event time. If two different statuses share the same event_ts (common with second-level precision), break the tie with lifecycle rank so ...


Submit Your Answer
Markdown supported