I pass six Starbucks (NASDAQ:SBUX) every morning on my walk to work.

Just to clarify, that's counting only the Starbucks that are actually on the west side of Eighth Avenue in midtown Manhattan. I think there are some branches on the east side, but that side remains terra incognita for me; for most New Yorkers, micro-optimizing the walk to work is a matter of habit, and I have no reason to cross the street. For all I know, the other side of Eighth Avenue consists of nothing but pachinko parlors and flea circuses. Wouldn't surprise me one bit.

One morning last week, I walked into a Starbucks on 58th Street at precisely the peak of the morning rush, to discover that this particular Starbucks had deployed a new type of employee. This employee wore a radio headset. Her main job was to go down the line of people waiting to order and ask them what they wanted in advance of their arriving at the cash register. There, they would be asked to repeat their order before paying and finally joining the line of customers waiting for their drinks to appear.

This premature order taking did not appear to improve the store's productivity. The cashiers still had to take the same number of orders, wait for the customers to fiddle with their purses for the correct change, and so forth. The coffee producers -- known theatrically in the trade as baristas -- still had to make the same number of drinks. The biggest benefit of the procedure, I thought, was that the barista got started on a drink a few seconds earlier, so people got their orders filled a little bit faster, even though the overall rate of output for the store was the same.

A network engineer would say this was a situation of "same bandwidth, lower latency" and then probably launch into a story about how the post office, mailing millions of DVDs (and a few letters) around the world every day, has the highest bandwidth of any network on earth, with far greater capacity than the biggest fiber-optic backbone, but with high latency -- so you wouldn't want to use it for, say, telephony. And this would be extremely hilarious to the network engineer. That's the kind of joke they tell.

Anyway, the extra order taker I encountered that morning was not, to be completely candid, the sweetest strawberry in the patch. She was barking commands like the Sergeant Major in Monty Python's The Meaning of Life ("Anyone got anything they'd RATHER be doing than marching UP and DOWN the square?"). I watched with astonishment as she got into an altercation with a customer because the customer wanted to pick up her warm egg -- like sandwich at the front counter rather than walking around to the back counter. This was obviously an extreme violation of the Sergeant Major's sense of order. "They're not allowed to give it to you up here!" she kept shouting at the poor customer, who was almost speechless with shock that a company whose customer service mantra is "Just say yes" would rather argue with her than pass her a sandwich she had paid for.

Isn't it a bit odd that Starbucks had gone to the trouble of paying someone to stand around the front of the shop, getting into squabbles with loyal customers, making people repeat their orders, while not even increasing the total number of Frappuccino Blended Coffees that could be produced per unit of time?

I thought so, too. I turned to the wonder box of knowledge on my desk and found a website called Starbucks Gossip (starbucksgossip.typepad.com), where an entire community of highly literate Starbucks employees (excuse me, Corporate prefers to call them partners) gathers to exchange gossip and share their thoughts on hot topics such as whether nonfat drinks should be called skinny.

Reading through the site, I discovered that there is a whole world of esoteric knowledge about how to sell handmade coffee drinks in the gigantic quantities that make Starbucks profitable.

For example, I learned from the website that the woman I had seen in the headset taking orders was officially called an expediter -- but the job title is something of a red herring, according to the collective wisdom of the Starbucks staff members chatting on the site.

Expediters are not really there to see to it that a customer's order is filled more quickly, they believe. Rather, expediters exist solely to prevent people in line from giving up and wandering off, maybe to go to the Dunkin' Donuts around the corner. Once a customer places an order, the logic goes, he or she feels an ethical obligation to wait for it to be filled, no matter how long the process takes. Expediters are there to lock in that order as soon as possible.

This is just one profit-minded policy among many at Starbucks. There's an internal deployment manual that, apparently, has instructions for where every employee should stand and what he or she should be doing at any given time. According to the anonymous posters on Starbucks Gossip, if you follow the instructions in that manual carefully, your branch can make more drinks, faster, and this will cause Starbucks HQ to allow you to hire even more people, and then there's less work for everyone.

Sounds great!

All of this fancy optimization stuff is called operations research. It's what Michael Gerber talks about in his best-selling book The E-Myth Revisited. If you're planning to expand your business to a certain scale, you must first establish procedures and build systems to get predictable outcomes so that your employees can produce decent results even when they're not having a great day. It's a real academic field of study, and it's really hard and really important. You need to hire pretty smart people to do studies and experiments and collect the statistics and then figure out what it all means.

Starbucks is great at operations research. It wouldn't have become the company it is today if it hadn't created detailed manuals telling people how best to assemble the various chemicals that make up a modern adult milk shake. All of those independent coffee shops that have a nostalgic fixation on grinding the coffee beans right before using them, claiming this "tastes better" -- these poor shops go out of business left and right, because they don't have the right system. They make only a handful of drinks in the time it takes Starbucks to serve a hundred.

But as it has grown, Starbucks seems to have lost its knack for figuring out whether the policies dreamed up at HQ are really going to work in the field. Indeed, most of the people posting on Starbucks Gossip seem to agree that Starbucks HQ is hopelessly naive about the reality of the employees' daily work lives. Those icy blended drinks might bring in more customers in the summer, but they take too long to make, so the lines are crazy. And when the lines are crazy, the staff has a hard time keeping the store clean. Hence, my local Starbucks branches are consistently dirtier and messier than the average McDonald's (NYSE:MCD). That's one problem among many.

Systems need to be flexible, and managers need to be wary of procedures that, applied blindly, can cross the line into something that looks more like antagonism toward customers. When we put a customer service policy in place at Fog Creek Software, we always deliberately leave a lot of room for our frontline people to use their own judgment -- heck, we require it.

For example, we usually reply to a customer complaint with an e-mail that includes a discount offer on the purchase of another product. But rather than automate the message, we have opted instead to create a written template that staff members have to manually cut and paste into the body of an e-mail.

They are encouraged to edit the text to suit the circumstances, which forces them to take a little extra time and think a little bit harder about whether they're saying the exact right thing to this particular customer. They can make the text more familiar if they know the person well or more apologetic if we really screwed up. They can also take the coupon code from the template and process the discount for the customer right away, if they are talking on the phone or over IM.

The objective is to make our customers feel as if they are having a real human interaction -- that they are not just dealing with cogs in a big machine. As a smaller entrepreneurial company, we have this luxury, and we exploit it. Starbucks has many more customers, so a system like that might not work for the company. But when one of your employees yells, "They're not allowed to give it to you up here!" at a customer, that's probably a sign that the systems you have put in place have become self-defeating. Personally, I was so offended by that expediter that I'm now getting my coffee at the Starbucks on 60th Street. The 58th Street branch can take a flying leap for all I care.

Joel Spolsky is the co-founder and CEO of Fog Creek Software in New York City and the host of the popular blog Joel on Software.