Hacker News new | past | comments | ask | show | jobs | submit login
Your Coffee Shop Doesn’t Use Two-Phase Commit (Starbucks async processing model) (eaipatterns.com)
80 points by dshankar on March 15, 2012 | hide | past | favorite | 37 comments



When I was in college as an undergrad, I worked at a local dive bar with a grill. Being a CS guy, and working with a couple other CS guys, we had a lot of fun with this same idea. When we worked the kitchen we would apply our understanding of queueing to great effect. We would play with different algorithms, analyze the bottlenecks presented by the various stations, optimize on expected workloads and so on. When some of the younger people also in CS would be taking the relevant classes, we would challenge them or help them (depending the person's skill level and needs) by showing them the applications in terms of the kitchen. It was pretty awesome. I think it really helped us get an intuitive feel for various aspects of decoupled queue based systems -- sometimes I still flash to the kitchen experience when figuring out workflows, and sometimes my early sketches of a system are laid out like the kitchen we worked in.

Some cool lessons from this:

* If you just look at the infrastructure, there is obviously one optimal way to do it, however if you look at the people doing each task at a station, this may change. We would abstract this out in our systems thinking to imagine various people as various systems or processing algorithms with different runtimes, and which we had no control over. This had strange implications in terms of efficiency, and which method would work best for the feeding and consuming steps around those stations. Also taught us about reordering and parallelizing certain tasks, even if those orders and parallelizations were not optimal in their own right.

* If you know there will be a heavy bunch of orders for a certain type of item (e.g. daily special) you can start cooking batches before the orders come in, even if there are not yet orders, optimizing the cook time. Essentially just in time delivery stuff. Similar with fries (this place used a 2 stage fry cooking process).

* Exceptional orders and out of band mechanisms: instead of trying to make the main workflow handle exceptional orders (very large, weird items, etc) it is is easier to have a second workflow or an ad-hoc workflow for that situation - it prevents interruptions, starvation issues, etc for the main queue.

* It is very amusing to watch the puzzled look on customer's faces when they see the cooks white-boarding math equations during lulls :)


You definitely should be trying to improve your kitchen algorithms if they are causing starvation issues!

Joking aside, I love that you were applying the modeling, design, and performance analysis ideas to a different domain like this. It's the classic case of cross disciplinary teams or cross discipline thinking yielding surprising benefits. I love that you used it to teach CS as well, which makes a powerful reciprocal relationship.

I used to wonder why the fast food places didn't have hefty pattern analysis going on to predict needs, e.g. "it's Tuesday at 4:30, we almost always need 28 chicken strips in the next 30 minutes so put them down" even to the point of balancing speed vs waste and other issues. Maybe they are doing that now, but it's got a lot of potential.


At busy times, the Starbucks near me even goes farther. They have an extra employee ask people in line for their drink orders and marks them on the cup before you even reach the cashier so that the only bottleneck is actually paying for the drink.


That's for their benefit, not yours:

http://www.inc.com/magazine/20080801/how-hard-could-it-be-go...

They're taking your order as soon as you walk in the door so that by the time you realize that you'll be standing there for 20 minutes waiting for your coffee you're already committed. You'd feel guilty walking out, so they get your business where they otherwise might not.


this started happening at a local Chipotle i go to at lunch. you actually pay while in line, then order your food, then show your receipt to cashier as proof. seems weird to me in this setting because what if i change my mind on what i want to eat based on what looks good. i guess it is more efficient though.


It mirrors the various tricks Apple uses to speed up the process (floor reps can checkout without a register)


Starbucks was doing this long before there were Apple stores.


Yeah, every starbucks I've been to in Manhattan does this in the morning and lunch hours. It's damn efficient considering.


Yes, because I don't run away after I've paid. Essentially I'm blocked with a lock after I've paid which is

a.) released when I get my coffee

b.) released with a timeout (I don't want to wait any longer)


The illustration makes it easy to see how credit or gift cards benefit Starbucks' workflow, by removing the price interaction. Regulars with a card can just hand the card over with the order and payment is immediately processed. This removes the round trip around price.


Another place where 2PC isn't used is in bank accounts, even though the "bank account transfer" example is the stereotypical example introducing transactions. Networked credit banking was basically worked out in 4th century BC Egypt.


Excellent analogy.


I guess none of you has ever set foot in a coffee shop in Italy. Compared to that Starbucks is the most inefficient place ever. I'd like to have hard numbers to prove that, but the sheer fact that one espresso is about $1 in Italy, the cost off coffee is comparable and the cost of land is much higher than in the US, makes me think that Italian baristas are at least twice as efficient.


Then you must agree that the workers at my local restaurant, where water is available for free, are infinitely more efficient than the workers at fuji bottled water plant.


I'm wasting too much time on this issue: it turns out that the world record is held by these two guys [1] at 623 espresso/hour [1] http://www.youtube.com/watch?feature=player_detailpage&v...


I'd be very interested in a description of how italian coffee shops handle a rush


1. nobody ever sits

2. no paper cups

3. no useless lids

4. no endless variants of latte, mocha and what have you [1]

Let's suppose the rush hour is after lunch, then everyone will be getting an espresso, someone macchiato (only tourists drink cappuccino after 11 am), but the price is the same. And basically you have a line at the bar and a line to pay. The bar can usually make up to 8 espresso at a time and people cram in front of it by the dozen and drink it in under a minute. You can pay before or after according to where the queue is shorter.

[1] http://www.youtube.com/watch?v=rBNOB7FkSSM


01:34 here http://www.youtube.com/watch?v=PoOeU1aya0o :)

I've got an Illy cafe machine at home :)


> 4. no endless variants of latte, mocha and what have you

That sounds awesome. I can't even count the number of times I've waited for some goofball's complex six-word drink to be made so I can give the cashier $2 and get a cup in return. (Most places around here sell you the cup and you pour your own coffee from a vacuum pot.)


I like being in line behind those folks. Listening to someone order a "double skinny mocha latte without the espresso"* is one of life's purest joys.

* I shit you not. It happened at a Starbucks in Wisconsin.


It's always amusing asking for "Extra hot" and a slight look of panic as the milk is about to jump out the jug


So basically, a cup of hot chocolate made with skim milk?


That makes me curious - what is the maximum number of modifiers I can apply to one drink to arrive to a second drink on the same menu?

Bonus points if it's cheaper.


That's what the barista suggested, while kindly pointing out that would cost about half as much.

The customer insisted on the order as originally stated, and happily paid the extra two bucks for it.


Here in Portugal (and also in Spain, IIRC) it's much the same, almost everyone drinks a normal espresso or a simple mix of espresso and milk (semi-skimmed, I think you'd call it).


Yep, in Spain it's usually cafe, cafe cortado, or cafe con leche. Espresso, espresso with a tiny bit of milk, espresso and milk.

Coffeehouses here in the States make things way too complicated but I guess they only continue to sell what the customers buy so it's our own fault.


The one big differences that I can think of is that basically everybody orders the same thing (an espresso) so there is no need to take and manage orders in the same way. This also makes it a lot quicker to prepare the coffee. Also payment is a lot quicker when there is basically one order at one prices.


IIRC, they also to use the two-step method. You pay at the register and then go over to the person making coffee and give them your slip that says what you ordered.

As far as pricing, I don't think you can make a living selling shots of espresso for $1, unless you sell an awful lot of shots or sell a lot of other things.


If all you need are 400 sq ft and one or two persons behind the counter. And of course they also sell all sorts of other beverages (also alcoholic) and sometimes cigarettes and phone recharges.


Or perhaps that competition is higher?


Yes, competition is higher, but my guess is that the turnaround time and real estate prices are what make most of the price of an espresso: the first through barista wages and the second through the rent. After all an espresso costs probably 5 cents in coffee.


There's obviously more to it than efficiency. Here in Portugal an espresso (bica) is about $0.85 and that includes an higher IVA/VAT (23%).


As far as I recall the espresso experience in Portugal is very close to Italy. Cheap, good and quick. Compare to France: almost as slow as the US, much worse than your average Starbucks and around 1.5-2$.


The US has five times as many people spread out over 32 times the area. Palm Beach, Florida has an average household income of over $109,000. South Alamo, Texas is at $13,906. Climates vary from arctic to tropical, state and local taxes range from zilch to rivaling federal taxes.

Saying "one espresso" is cheaper in Italy than the US doesn't really mean anything. Prices vary, cost of doing business varies, cost of living varies.


You might be right, but you'd be surprised if you knew how varied Italy is as well. We hardly speak the same language: dialects are much more relevant than in the US and what people speak at home in different regions is mutually unintelligible. The climate is almost as varied as in the US, we have mountains that go as high as 15 000 ft and islands just off the cost of Libya. I cannot say the same for the range of income, but as far as espresso prices go I'd say the range in Italy is 0.6-1 euros and in the US it's 1.5-2.5 dollars. I'd love to be proven wrong, though.


Relatively no one drinks espresso in the US, so they charge more. The most common drinks are drip, latte, or cappuccino which can range from 2.5-6.0 dollars.


If we're talking drip coffee, the cheapest I've seen is about $1 at Dunkin Donuts.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: