Memcached is one of the technologies that holds the modern Internet together, but do you know what it actually does? Brian Aker has certainly earned the title of Memcached guru, and below he offers a peek under the hood. He’ll also provide a deeper dive into Memcached in a tutorial at the upcoming 2011 MySQL Conference.
What problem is Memcached meant to solve?
Brian Aker: In an operation like a database or an application server, it’s very expensive to build an object or get a result set. And because of that overhead cost, what you really want to be able to do is to cache that result set. So, for instance, suppose you have 10 clients that are going to all be making the same request, and that request is fairly expensive. By placing the results inside of Memcached, all you are doing is requesting the answer and not actually requesting the complete build of an object all over again, whatever that object may be.
What are the first steps someone should take to integrate Memcached into their applications?
Brian Aker: The first thing to do is to think about how you develop the application in the first place. If you can think of the application as being event-driven, you’re way ahead of the pack when you go and design applications. So, for instance, if you were going to design something like Twitter, what you would first ask is not how do I access the database but how does my application react to a given request? That really gets into the core of how to make a difference when designing with any of these types of applications.
People will ask me, “Should I build everything with Memcached the first day?” And my usual answer is, “No, don’t.” There’s an awful lot of applications out there where you’ll never actually need to use anything like Memcached at all. And really, you should spend time designing and working on your actual application. That’s where you tend to add value. But do it in the same way so that you can eventually scale it, which really means thinking about how your interfaces If my interface is set up in a way that I can make a request and eventually insert my caching layer right there when I need it, then it’s a complete win.
Where does Memcached live in a corporate infrastructure?
Brian Aker: Usually, in smaller shops, people will put Memcached directly on the web server itself. The advantage then is that the local look-up cost overhead is really quite low. As they grow, those shops will then move it off of that local web server and out to dedicated hardware. In a lot of cases, where we really see it shine is when people start using it and spreading it across multiple servers.
Memcached has modern interfaces to pretty much any programming language. We have C, C++ bindings. We have Java bindings. We have Ruby, Perl, Python. You name it.
As far as the server goes, traditionally, we see it mostly run on Linux. Obviously it will run on OS X. There is a Windows port that’s available at any given time. It may or may not be necessarily the latest and greatest. But essentially whatever platform you’re on, it’s there. I even have a very torn down one that will run on Arduino. We can get it down to pretty small devices.
What is the most common Memcached mistake?
Brian Aker: People will think of Memcached as a database — they’ll think that data actually persists in it. That’s incorrect. Trying to build it so that it persists is not really a good plan. There are a couple of Memcached startups that have built persistent products, so you can look at one of those, but really, that’s not the point to it.
A question I’ll often hear is, “How do I dump the data back out of Memcached?” If you’re asking that question it usually means you’re not thinking about Memcached correctly.