Caching and Grocery Shopping

I recently talked with @TheJudgeOfCheese (t) about design patterns and grocery shopping.

I Don’t Cache, I Just Drive Fast

Software design:
Don’t implement a caching tier– go to the database for every query.

Re-enactment:
Plan to cook a dozen eggs. Go to the grocery store, and on each trip by an egg and a pat of butter. For a while this works if you can drive there really fast. Things get ugly when the store is crowded.

The Anti-Cache

Software Design:

Create a function in your application that runs a query. The query returns a result set with multiple values, but the function returns only one value at any given time.
Call the function individually for each value in the result set.

Human re-enactment:

Create a shopping list with 10 items. Go to the store and purchase all ten items and put them in the car and drive them home. When you get home, take one item out of the car. Throw the other nine items away. Repeat for each additional item.

Previous Post
Tycho Brahe and Moving to Portland
Next Post
What Y’All All Thought of Me at SQL Rally

Related Posts

2 Comments. Leave new

  • LOL! Love it! Funny thing is: sometimes our family does buy 10 things and (end up) throwing 9 away… Hmmm…

    Reply
  • Todd Everett
    May 26, 2011 10:31 am

    Kendra – this is great!! I want to play too…

    Software Design: Write a query to find a record using a highly selective filter. Retrieve each record by ID# until you find the one matching your filter. Decide this is really slow and blame the DBMS. Implement a caching tier to hold all those records you retrieved the LAST time so that at least the NEXT time you run this query in your program it won’t retrieve all the records again from the database. Congratulate yourself on being so much smarter than DBMS designers.

    Re-Enactment: Start a receipe that calls for Barilla Farfalle pasta. Send spouse to the grocery store to purchase the first (and subseqently next) box of pasta on the shelf and bring it back. Throw it away if its not Barilla Farfalle. Repeat until you get Barilla Farfalle. Decide this is really slow and blame the grocery store. Build a outbuilding next to your garage to hold all the pasta boxes you bought the LAST time you made this recipe so the NEXT time you make it your spouse will only have to go to the outbuilding. Congratulate yourself on being so much smarter than those grocery store designers.

    I swear I’m NOT making this up. I actually consulted on such a process and when the developer was explaining the performance issues to me he took great pride in how much he’d improved things so far by using the caching layer….

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Menu