System Design Atlas

Grocery orders with store inventory and substitutions

03 / 10Worked example

Scale estimates

Why is a good average not enough for the last article?

The rules are there; now we set a computable scale for their test. Suppose ten stores with 300 orders each day, an average of 20 order lines per order and twelve hours of order picking. These figures are deliberately chosen test assumptions. The average spreads work throughout the day; a simultaneously in-demand article focuses it on an inventory line.

Starting point The handover requirements from step 2 must also apply under simultaneous requests.

Assumptions for the example case

Own example design for pick-up from a store and packaged piece goods with strictly positive integer cent prices. Free and fully discounted baskets are outside the case. Replacement items are specifically allowed in advance; the final positive amount arises from goods actually provided and is collected on collection. Figures and target values are illustrative design assumptions.

From daily volume to hotspot

Illustrative scale · Rate, test peak and contention separately

Daily volume3,000 orders/day10 branches × 300
Order lines60,000/day3,000 × 20
Average1.39/s60,000 ÷ 43,200 s
Test peak · 28/s15 minutes: 25,200 order-line completions
Raw data · 3.43 GiB/30 days2 KiB per position history
Concurrency test 50 allocations on 1 pack in store-17: 1 winner, 49 conflicts

28 order-line completions per second test load. 50 concurrent allocations for one pack test domain uniqueness.

The load profile separates the mean of around 1.39 deals per second, the test peak of 28 per second, and 50 competing allocations to the same last pack.

Calculations for the first test

  1. 01

    Orders per day

    3,000 orders/day

    10 stores × 300 orders

    For the designThe test distributes the daily volume among ten stores.

  2. 02

    Order lines per day

    60,000 order lines/day

    3000 × 20 order lines

    For the designOrder line closures determine the local write rate.

  3. 03

    Average rate

    1.3889 order-line completions/s

    60,000 ÷ (12 × 3,600)

    For the designThe mean value describes the base load during twelve hours of picking.

  4. 04

    Test peak

    28 order-line completions/s

    20 × 1.3889 = 27.7778; rounded up

    For the designThis profile checks the goal from step 2.

  5. 05

    15-minute test

    25,200 order-line completions

    28 × 900 seconds

    For the designThe volume makes the peak test reproducible.

  6. 06

    Raw data

    117.19 MiB/day; around 3.43 GiB/30 days

    60,000 × 2 KiB = 120,000 KiB; × 30

    For the designIndices, payments, backups and longer storage are added.

  7. 07

    Article Hotspot

    50 requests for 1 pack

    50 parallel allocations at P=1, Z=0

    For the designExactly one commit wins; 49 requests get a conflict.

Case decision and verification approach

Relational transactional store

Use a relational transaction store with short item-level locks.

Moderate total load encounters short competing changes to the same item row.

Stock and allocation must remain consistent together. Test 28 order-line completions per second and, separately, 50 concurrent requests with exactly one winner.

Alternative considered
Separate inventory and order record stores require additional reconciliation of the promise.
Trade-off
A popular article serializes accesses.
Reassess
Only measured waiting times under the real peak profile justify further distribution.

Terms in this step

Average
The order-line rate spread over twelve hours.
Test peak
Twenty times the load profile for 15 minutes.
Article Hotspot
Many simultaneous allocations to the same last pack.

Try it yourself

Calculate the average order-line rate, the peak profile at twenty times that rate, and the winning outcome for 50 concurrent requests for one pack.

A hint for your attempt

The rate and number of successful promises measure different things.

Compare with a possible solution
Average rate
60,000 ÷ 43,200 gives about 1.39 order-line completions per second.
Test peak
Twenty times the mean is about 27.8 completions per second; round up to 28 per second for the test profile.
Article Hotspot
Exactly one allocation wins and 49 requests get a conflict; high throughput must not generate a second winner.

Apply to your project

Which single item concentrates contention in your project?

Step 4 defines the commands that remain repeatable correctly under this profile.