Deduplicating Retried Trip Events Before Joining to Payments
Last updated: November 29, 2026
Quick Overview
Trip status events are duplicated by client retries and payments can have several attempts per trip. Write a query that computes completed trips and captured revenue per city without double counting.
Uber
November 29, 20260
0
0 solved
Trip status events are duplicated by client retries and payments can have several attempts per trip. Write a query that computes completed trips and captured revenue per city without double counting.
Uber's event pipelines deliver at least once, so duplicated rows and many-to-many joins are a constant source of inflated revenue numbers. The interviewer checks that you dedupe each side to the right grain before joining.
What the Interviewer Expects
- Identify the grain of each table and the join key
- Pick the latest state per trip with ROW_NUMBER
- Keep one captured payment per trip and flag duplicates
- Use a LEFT JOIN to find completed trips without capture
- Explain why joining before deduplication inflates sums
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you detect riders who were charged twice?
- What if a late event changes a trip from completed to cancelled after the report ran?
- How would you make this incremental in a daily pipeline?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
trip_events(trip_id, city_id, status, event_ts, ingested_at): many rows per trip (state changes plus retried duplicates). payments(payment_id, trip_id, amount_usd, payment_status, created_at): fai...
Approach
- Reduce
trip_eventsto the latest state per trip, ordering byevent_tstheningested_atto break ties between duplicates. - Reduce payments to the first captured payment per trip.
- Left joi...