A wala is the person who runs the stall. Every order needs 5 ms to take, 40 ms for the kettle to brew, and 1 ms to pour. The wala can stand at each kettle until it is done. Then 16 orders take 736 ms.
Or the wala can put a kettle on and take the next order while it brews. How much sooner is everyone served?
guess first
If the wala stops watching each kettle, how much sooner?
736 msuntil the last cup. Wala works 13% of it
time to serve everyone
22 orders a secondwatching: 736 ms
run it
Put more kettles on at once. When is everyone served?
124816
One wala, 16 customers. A burner is one kettle brewing. The big number is when the last cup goes out.
why it helps
While a kettle brews, the wala can take the next order.
Brewing needs nobody. A watching wala just stands for 40 ms. A juggling wala spends that time on other orders, so the waits overlap. This is concurrency.
the working
Wala work per order: 5 + 1 = 6 ms16 orders: 16 × 6 = 96 ms of workWatching: 16 × 46 = 736 msBusy: 96 ÷ 736 = 13%Juggling: last cup at 121 ms, 96 ÷ 121 = 79%
your call
Rush hour: 64 customers, one juggling wala. What speeds it up?
System DesignConcurrency: waiting vs working
One wala, many kettles
Sixteen customers, one wala. If the wala stops standing at each kettle, how much sooner is everyone served?
Every order at the stall is five milliseconds of taking, forty of the kettle brewing, one of pouring. One wala can stand at each kettle, or put it on and take the next order. The timeline shows each order's waiting, working and brewing.
Preparing for interviews? The ten-week plan puts this in order with DSA and the design rounds.
try this Switch to Juggle the kettles, drag Customers at once and Burners to 64, then watch Walas busy.
16
1
16
Breaking point: one order that holds the wala for 200 ms stops the event loop: 6 brewed kettles wait for a pour, and 16 orders take 316 ms instead of 121.
The stall
a kettle brewing, no wala needed
a cup poured, and a customer served
the heavy order, and brewed kettles nobody pours
One pawn per customer at the counter, one burner per kettle the stall can have on, and the walas behind. Watching, each wala stands upright at its kettle through the whole brew. Juggle, and they lean over one kettle after another while the rest brew.
The stall, order by order
One row per customer, time running left to right in ms (a millisecond, a thousandth of a second). Each order is 5 ms of taking, 40 ms of brewing and 1 ms of pouring.
waiting
a wala working
brewing, no wala needed
the heavy order, and brewed kettles nobody pours
All served in
736 ms
from the first customer to the last cup
Orders a second
21.7
served, on average, over the whole run
Walas busy
13%of the time working
The working
Where the time, the rate and the busy share come from, redone every time you move a control.
The wala's workorders1 dot = 1 order, 6 ms of workEach order needs a wala for 5 ms to take it and 1 ms to pour it, 6 ms in all. The 40 ms brew needs nobody. 16 customers bring this much work. 16 × 6= 96 ms
All served inorders in a row1 dot = 46 msThe wala stands at each kettle until it is poured, so the 16 orders go one after another, 46 ms each. 16 × 46= 736 ms
Orders a second736 ms is 0.736 of a second, and 16 orders went out in it. 16 ÷ 0.736= 21.7 a second
Walas busywala time736 msworking96 msThe wala worked 96 ms of the 736 ms the stall was open. The rest was standing and waiting. 96 ÷ 736= 13%
Each wala stands at a kettle for 40 of every 46 ms, doing nothing. The walas are busy only 13% of the time, and the line still waits.
Sixteen customers, one wala. If the wala stops standing at each kettle, how much sooner is everyone served?
Call 1: hire, or juggle?
Sixteen customers, and the one wala watches each kettle: 736 ms until the last cup. The owner can hire a second wala who also watches each kettle, or teach the one wala to juggle 16 kettles.
Which serves all sixteen sooner?
The dials wait until you make the call.
Call 2: the rush
Sixty-four customers, one wala juggling, a burner for every kettle. The last cup goes out at 384 ms and the wala never stops moving. Now a second wala joins, juggling too.
When does the last cup go out now?
The dials wait until you make the call.
Call 3: the heavy order
Back to sixteen customers, one wala juggling on 16 burners: everyone served in 121 ms. Then customer 7 orders masala ground by hand, 200 ms of the wala's hands instead of 5.
When does the last cup go out now?
The dials wait until you make the call.
Waiting is not working
Watching each kettle, one wala takes 736 ms for sixteen orders, and is busy for only 96 ms of it. Juggling doesn't make a kettle boil faster. It fills the forty milliseconds of idle time with the next order's work, so the waits overlap instead of queueing end to end. That overlap is concurrency.
Push the customers and the burners to 64 while juggling, and the walas-busy number climbs to 100%. Now every millisecond is spent working, and 64 orders times 6 ms of work is 384 ms however cleverly they are juggled. To go below that floor, you need less work per order or a second wala working at the same time. That isparallelism: more cores.
The burners cap the orders in flight. Without a cap, juggling would put every customer's kettle on at once. In a real system, the thing doing the brewing (usually a database) has a limited number of burners of its own.
Limits of this model
These are teaching values. Five, forty and one milliseconds make the pattern visible: a request that spends most of its time waiting on something else. That is true of most web requests. It is not true of work like resizing an image.
The brew here always takes forty milliseconds, however many kettles are on. A real database slows down as more requests pile onto it, so juggling harder can make every wait longer. This lab models scheduling only.
Every customer arrives at once, and a free wala always picks the task that has waited longest. Real servers take arrivals as they come and schedule in their own ways. A greedy choice like this one can even make an extra burner cost a few milliseconds.