This week, memcached, a piece of software that prevents much of the Internet from melting down, turns 10 years old. Despite its age, memcached is still the go-to solution for many programmers and sysadmins managing heavy workloads. Without memcached, Ars Technica would likely be unable to serve this article to you at all.
Brad Fitzpatrick wrote memcached for LiveJournal way back in 2003 (check out the initial CVS commit here). While waiting for new hardware to help save the site from being overloaded, Fitzpatrick realized that he had plenty of unused RAM spread across LiveJournal’s existing servers. He wrote memcached to take advantage of this spare memory and lighten the load on the site.
memcached is a distributed in-memory key-value store that uses a very simple protocol for storing and retrieving arbitrary data from memory instead of from a filesystem. To store a value, a program connects to the memcached server on the default port of 11211 and issues a series of basic commands. (Note: a binary protocol is also supported.)
# telnet 127.0.0.1 11211 -> set hello 0 60 5 -> world <- STORED -> get hello <- world
The above log connects to the server, sets a key named hello (which expires in 60 seconds), and then fetches it back again. Simple, right? It is, but this becomes very useful when trying to avoid hitting an already overloaded database or filesystem. Additionally, through consistent hashing of keys, memcached clients are able to distribute values across multiple memcached servers.

Loading comments...