Derive Daily On-Hand Inventory From a Receipts and Shipments Ledger

Last updated: November 29, 2026

Quick Overview

Given an opening inventory snapshot per fulfillment center and SKU as of Nov 1, 2026, and an inventory_ledger of signed quantity changes (receipts, shipments, adjustments), compute the end-of-day on-hand quantity for every FC, SKU and active day, and flag days where the balance goes negative.

Amazon
Data Manipulation (SQL/Python)
Data Engineer
Amazon
November 29, 2026
Data Engineer
Onsite
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given an opening inventory snapshot per fulfillment center and SKU as of Nov 1, 2026, and an inventory_ledger of signed quantity changes (receipts, shipments, adjustments), compute the end-of-day on-hand quantity for every FC, SKU and active day, and flag days where the balance goes negative.

Amazon's inventory systems are event sourced: on-hand quantity is the opening position plus every receive, pick, ship and adjustment since. Onsite data engineering rounds use this to probe running totals, aggregation grain, and whether you treat a negative balance as a data quality signal rather than hiding it.

What the Interviewer Expects
  • Aggregate to daily net change before the running sum to fix the grain
  • Use SUM OVER with an explicit ROWS UNBOUNDED PRECEDING frame
  • Add the opening snapshot with a LEFT JOIN and COALESCE for SKUs first seen after the snapshot
  • Surface negative balances as a flag for reconciliation
  • Discuss filling days with no activity if a dense daily series is required
Key Topics to Cover
running total
window frames
event sourcing
data quality
grain
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 produce a value for every calendar day, including days with no transactions?
  • What would cause a negative balance in practice and how would you reconcile it?
  • How would you make this incremental so each day only processes new ledger rows?
  • How would you handle ledger events that arrive late for a day already published?
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
  • opening_snapshot(fc_id, sku, on_hand): position at the start of Nov 1.
  • inventory_ledger(fc_id, sku, txn_ts, qty_delta, txn_type): receipts positive, shipments negative, adjustments either sign...
Approach
  1. Collapse the ledger to daily net change per FC and SKU. Doing the running sum over raw rows would give intraday balances and multiple rows per day.
  2. Running SUM over days, partitioned by FC and...

Submit Your Answer
Markdown supported