← Questions
Serve inventory from disk when it doesn't fit in memory
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A system design interview question asked in Apple's technical phone screen, last asked Oct 2025. It tests storage, indexing and caching.
Design the software for an inventory server that has spinning disks, no SSD and only a little RAM. Records are keyed by item ID and hold the available quantity, the reserved quantity and some metadata. The server must answer reads, apply updates and handle conditional reservations such as "reserve one unit only if more than zero are available".
Requirements
- Functional:
get(item_id),update(item_id, fields),reserve(item_id, n)that succeeds only if enough stock is available, and releasing reservations. - Non-functional: the data set is far larger than RAM; random disk reads cost milliseconds each; reservations must never oversell; data must survive a crash.
Clarifying questions
- How many items, how large is each record, and how much RAM is there?
- What is the read to write ratio, and are some items much hotter than others?
- What latency is acceptable for reads and for reservations?
- Can requests be batched?
What a strong answer covers
- Data layout: fixed-size records in pages, or a B-tree keyed by item ID, so one lookup costs about one seek; why a log-structured layout helps writes but hurts reads on spinning disks.
- Indexing: keep the upper levels of the index in RAM so a lookup needs one disk read.
- Caching: a page cache for hot items with LRU or a scan-resistant policy, sized to the RAM budget.
- Write path: a sequential write-ahead log for durability, group commit, applying changes to pages in the background.
- Conditional reservations: an atomic check and decrement under a per-item lock or compare-and-set, recorded in the log before acknowledging.
- Latency: batching and sorting requests by disk position, prefetching, separating hot and cold items.
Follow-ups
- A flash sale makes one item extremely hot. What happens?
- The server crashes mid-update. Walk through recovery.
- Traffic grows beyond one machine. How do you split the data?
Where it's asked
- Apple · Technical phone screen · Last asked Oct 2025
What it tests
No official answer yet. Draw yours on the right; publish it and it shows under Community.
Nothing published yet. Publish your canvas and it shows here for others to open and remix.
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing
