AI Hints
Home›Data Science Tutorial›Randomness in Business
Data Science · Lesson 49 of 101

How Many Baristas?

Why averages lie about queues.

⏱ 2 min read▶ Video at 1:23:27🎓 Free
Watch this lesson in the Data Science courseWatch on YouTube ↗Full Data Science course

Here's a puzzle. Forty eight customers arrive per hour. Each drink takes about two minutes. That's ninety six minutes of work per hour. So two baristas have a hundred and twenty minutes available, and that's plenty, right? They'd be only eighty percent busy. Now watch what happens.

How Many Baristas?
From the video: How Many Baristas?
  • 48 customers an hour
  • Two baristas look like enough
  • Eighty percent busy

Simulating the queue

No formula is needed. We simulate it. Random gaps between customers, and random service times. Each customer goes to whichever barista gets free first, and we record how long they waited. We run two thousand hours, for two, three, and four baristas. Run it. Look at that. With two baristas, the average wait is over seven minutes, and on the slow days, twenty five. Add one person, and it falls to half a minute. That's a huge change. Queues don't get worse gently. As you get close to full capacity, waiting times explode. That's why a road that's ninety percent full is a traffic jam, and a hospital which runs at a hundred percent can't cope with a bad day.

queue_sim.pypython
import numpy as np

def simulate(baristas, per_hour=48, minutes_each=2.2, hours=2000, seed=0):
    rng = np.random.default_rng(seed)
    gaps = rng.exponential(60 / per_hour, int(per_hour * hours))
    free = np.zeros(baristas)
    t, waits = 0.0, []
    for gap in gaps:
        t += gap
        i = free.argmin()
        start = max(t, free[i])
        waits.append(start - t)
        free[i] = start + rng.exponential(minutes_each)
    return np.mean(waits), np.quantile(waits, .95)

for n in [2, 3, 4]:
    mean, worst = simulate(n)
    print(f"{n} baristas: average wait {mean:4.1f} min, slow days {worst:4.1f} min")
Output
2 baristas: average wait  7.6 min, slow days 25.3 min
3 baristas: average wait  0.6 min, slow days  3.4 min
4 baristas: average wait  0.1 min, slow days  0.9 min

The lesson of utilisation

Managers love to see staff busy all the time. But the maths says that a team at full capacity has endless queues. Some slack isn't waste. It's what absorbs randomness. Whenever you've got a server, a support team, or a machine, keep usage well below a hundred percent. Around seventy or eighty percent is a common target for good response times.

Full capacityinfinite queues
Slack absorbs randomnessit isn't waste
Targetaround 70-80%
Applies tostaff, servers, roads

Simulate or calculate?

You can solve simple queues with formulas. But real cafes have breaks, rushes, and people who walk away. Simulation handles all of that with a few lines of Python. So whenever a system has randomness and waiting, simulate it. It's how airports, hospitals, and call centres plan their staffing.

SituationUse
Simple, steady arrivalsQueue formulas
Rush hours and breaksSimulation
People who walk awaySimulation
Staff schedulingSimulation, then optimise

Summary

Averages hide queues, so simulate them. Next, a smarter way to study how long customers stay.

Key takeaways
  • Waits explode near capacity
  • Simulate it
  • Slack isn't waste
Next up: How Long Do Customers Stay? — survival analysis