Buying Fish Concurrently

Architectural patterns practically pop up everywhere and in places least expected.  An example of this is Starbucks does not use two-phase commit.  Recently at my local farmers market, I came across the need to leverage another one.

I typically purchase fruit, vegetables and fresh fish at my farmers market. The fruit and vegetables stalls are located right at the front of the market with the fish located at the back.  Purchasing fruit and vegetables is generally pretty straightforward as I just pick up what I want, it’s buying fresh fish that gets a lot more involving.

It starts off with  getting a ticket for getting in line to be attended too.  Once your number is called, you get to select the fish you want and the preparation method of choice. After you’ve selected your fish and preparation method, the fish is taken to a preparation station where it is cleaned and cut (if you so choose).  Once it has been cleaned based on your instructions, the fish is bagged and returned to you for pick up.

Because of the dependency involved in buying the fish (cleaning and cutting), fish buying general takes some time with lines of people waiting for their fish to be processed.  Even though it is managed in an asynchronous fashion i.e. you place your order and someone else is attended too, its still a time consuming operation and the average wait for fish is anywhere between 10 and 30 minutes depending on how many people came to buy fish.  This operation could probably be sped up by the Farmers Market dedicating more resources to cutting and cleaning fish, but it doesn’t look like that will happen anytime soon.  Besides, adding more resources is completely out of my control.

The fact that it takes 30 minutes to buy fish is not inherently bad.  It’s the fact that the fish stall happens to be at the back of the farmers market.  Let me explain what I mean here.  The average shopper (including myself) will pick up fruits and vegetables before buying fish simply because the fruit and vegetables are the first things the shopper will see.  However, picking up fruits and vegetables is not time consuming at all because the only dependency is the shopper i.e. I can move from fruit stall to fruit stall at my own pace with no external dependencies.  However, once I hit the fish section, I am now dependency of the fish order processing system.  It is guaranteed that my shopping time will take at least the time the “fish buying process” takes plus however long it took me to pick up my fruits and vegetables.

Now imagine for a moment that instead of instead of picking up my fruits before fish, I actually went and placed my order for fish and then came back and picked up my fruit and vegetables?  In essence, I would have two operations occur concurrently and the total time for shopping could theoretically be shaved in half.  While I would have to check in on my fish order (to make sure someone else didn’t take my fish!!), I would be assured that it was being processed and could do other shopping in the time my fish order was being processed.

This pattern can be used in the architecture of software systems by identifying activities of a business process that can be run in parallel or asynchronously without impacting each other.  This is particularly important when the processes in question are external systems but is still applicable even with internal systems.  With multi-core systems, this also allows system resources to be leveraged to their fullest capacity.

A little lesson from your friendly Farmers Market.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s