Price Each Marketplace Shipping Label with the Rate Card in Effect

Last updated: November 29, 2026

Quick Overview

Given a versioned shipping rate card per carrier and weight tier and a table of purchased shipping labels, find the rate that was in effect when each label was created and flag labels charged a different amount, using LEAD to build validity intervals.

Meta
Data Manipulation (SQL/Python)
Data Engineer
Meta
November 29, 2026
Data Engineer
Onsite
Data Manipulation (SQL/Python)
Hard

0

0

0 solved


Given a versioned shipping rate card per carrier and weight tier and a table of purchased shipping labels, find the rate that was in effect when each label was created and flag labels charged a different amount, using LEAD to build validity intervals.

Marketplace shipping on Meta's commerce surfaces depends on carrier rate cards that change over time, and finance reconciliation needs the as-of price. The interviewer checks that you dedupe same-day reloads, derive [from, to) intervals with LEAD, and handle labels with no applicable rate.

What the Interviewer Expects
  • Deduplicates rate card rows that share an effective date by keeping the latest load
  • Uses LEAD(effective_from) to compute each version's effective_to
  • Joins labels on carrier, tier and a half-open time interval
  • Keeps labels with no matching rate via a LEFT JOIN and labels them
  • Compares money with a tolerance rather than exact float equality
Key Topics to Cover
LEAD
as-of join
validity intervals
deduplication
reconciliation
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 report the total overcharge and undercharge by carrier and month?
  • How would the query change if weight tiers themselves were redefined between versions?
  • How would you implement the same as-of lookup efficiently in a batch pipeline with billions of labels?
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

Tables:

  • rate_card(carrier, weight_tier, rate_usd, effective_from, loaded_at). Corrections are loaded as a new row with the same effective_from.
  • `shipping_labels(label_id, carrier, weight_tier,...
Approach
  1. Keep one row per (carrier, weight_tier, effective_from) with ROW_NUMBER() by loaded_at DESC.
  2. LEAD(effective_from) per (carrier, weight_tier) gives effective_to; NULL means still curr...

Submit Your Answer
Markdown supported