It was developed by Brad Fitzpatrick in 2003 and has been heavily used in PHP applications after that.

Memcached is very simple to use. It can store a key value pair in memory for fast retrieval. The Memcached API offers methods to manipulate and fetch data easily. Serious Memcache users may also want to check out these books on Memcached.

This article provides a very high-level overview of Memcached system and its benefits.

How Does Memcached Work?

Memcached has a distributed caching architecture that relies on sharding of keys. Each key is stored in a dedicated shard that may be backed by one or more machines.

This approach helps us scale better for caching really large amount of data. A single machine can cache only up to its RAM limit. Whereas in the case of Memcached you can add many machines to your system and cache really large amount of data.

The design of Memcached abstracts the storage from API users, so the usage of the system is very simple. The application user need not worry about the complex logic it uses to divide keys between different machines. It guarantees that a provided key will be stored and retrieved without user knowledge about where it is stored.

Can It Be Used Only For Web Applications?

Memcached is usage in a web application is very common. However, its design does not limit it to be used in only web applications. You can use it in any application software where distributed caching can help. The key idea is to avoid IO and server data direct from RAM.

Why Is Memcached Popular?

Memcached is very popular among web applications. Below are some key benefits of using a distribute caching solution like Memcached.

Much faster application since IO is reduced and most data is served from RAM.

Better use of RAM - A lot of RAM may be left unused on multiple servers. You can easily add these machines as nodes to Memcached system and start making use of it.

The application can scale out instead of scale up.

Practical Scenarios Where Memcached Can Be Used

Below are some practical scenarios where people have used Memcached successfully.

Preventing weak passwords attack. I will describe this in a separate blog post sometime this month.

Page elements of websites can be cached that do not really change in the application lifecycle.

There may be large tables in your relational database that are accessed often with a primary key. This access can be minimized by caching most common query results in Memcached.

Who Is Using Memcached?

Memcached is a popular library and used by thousands of apps. Below are some popular names that use Memcached.

Apple

Craigslist

Wikipedia

Flickr

Wordpress

Areas Of Concern About Memcached

Memcached is a highly scalable solution however, it has some areas of concern that you need to be aware.

It stores all data in RAM. This makes it fast, however, it also makes it easy to loose. This data is never persisted to a storage system. If there is a power loss or server crash, you will lose all your data in Memcached.

Since it is always in RAM, you need to initialize the cache after every restart. This may require extra programming awareness towards serving data from cache or storage.

Since it's not persisted in any storage, the application developer must take the onus of persisting and updating data for all scenarios. All CRUD (Create, Read, Update, Delete) scenarios must be considered while designing your system with Memcached.

Memcached does not support transactions, this may be a big consideration if you are trying to cache transactional data.

It can be CPU intensive mainly due to generating a lot of garbage in memory.

What Are Memcached Alternatives?

Below are some alternatives to Memcached that you can consider using for highly scalable applications.