THE 2000S

Memcached

In 2003, Brad Fitzpatrick faced a major challenge. LiveJournal, the blogging platform he had created, was literally exploding: over 2.5 million accounts and an infrastructure beginning to show its limits. Some 70 machines ran day and night, but the databases were buckling under the pressure of queries. The site had a particular feature that complicated everything: each piece of content had different security levels and appeared in multiple views. Generating static pages was impossible when the elements composing them each had their own lifecycle.

Fitzpatrick then observed a technical reality that would shape his entire approach. Processors were gaining speed year after year, while hard drives lagged behind. Why not leverage this computing power rather than exhaust resources with endless disk accesses? The idea emerged to use the RAM sitting idle in web servers, that memory just waiting to be put to work.

A first prototype was built in Perl. The trial proved disappointing: too slow, too memory-hungry. Fitzpatrick started over in C and built a single-process, single-thread daemon that relied on asynchronous I/O. To ensure his system would work everywhere, he integrated libevent, a library that automatically chooses the best file descriptor management strategy based on the execution environment.

The principle behind Memcached can be stated simply: transform available server memory into a vast shared pool. A distributed hash table where data circulates between machines through consistent hashing. Nothing superfluous in the architecture: the server doesn’t communicate with its peers, stores nothing on disk, offers three basic operations—set, get, delete—and that’s it. This intentional austerity delivers formidable performance, with O(1) algorithms that respond instantly. The slab memory allocator prevents the fragmentation that plagued early versions using malloc.

Facebook adopted Memcached in 2007 and developed mcrouter, an enhanced variant with sharding features. Twitter followed with twemcache, tailored to its specific needs. These web giants validated Fitzpatrick’s approach and made Memcached a de facto standard.

The figures are staggering. At Facebook, the system handles billions of requests per second and stores trillions of objects. The cache hit rate regularly reaches 92%: only a handful of requests actually need to query the database. The load is reduced accordingly. The system introduced “leases” to manage write conflicts and prevent hordes of clients from all attempting to regenerate an expired entry simultaneously.

The distributed architecture allows welcome flexibility. Servers can be added to or removed from the pool on the fly; the system adjusts seamlessly. This horizontal scaling capability quickly became common practice in modern web infrastructure design.

The community embraced the project. Client libraries sprouted for PHP, Python, Ruby, Java, C#, adding object serialization and transparent compression, making the tool more manageable in various contexts. The source code continues to evolve thanks to contributions from a thriving community that shows no signs of slowing down.

In 2024, Memcached still holds its ground in web infrastructures. The project maintains its original philosophy: stay simple, fast, reliable. This minimalist approach contrasts with more baroque alternatives like Redis, but perfectly meets pure caching needs. Memcached demonstrates that an elegant, stripped-down solution sometimes solves complex problems better than sophisticated machinery.