Memcached Architecture

Hussein Nasser
15 min readNov 29, 2022

Memcached is an in-memory key-value store originally written in Perl and later rewritten in C. It is popular with companies such as Facebook, Netflix and Wikipedia for its simplicity.

While the word “simple” has lost its meaning when it comes to describing software, I think Memcached is one of the few remaining software that is truly simple. Memcached doesn’t try to have fancy features like persistence or rich data types. Even the distributed cache is the responsibility of the client not Memcached server.

Memcached backend has one job only, an in-memory key value store.

To Cache is a cop-out

Memcached is used as a cache for slow database queries or HTTP responses that are expensive to compute. While caching is critical for scalability, it should only be used as a last resort, let me explain.

I think running a cache for every encountered slow query is cop-out. I believe understanding the cause of performance degradation is key, otherwise the cache is just a duct-tape. If it is a database query, look at the plan, do you need an index? Are there alot logic reads can you rewrite the query or include an additional filter predict to minimize the search space?

If it is an RPC, consider why are the calls chatty in the first place and can you eliminate the calls at the…

--

--

Hussein Nasser

Software Engineer passionate about Backend Engineering, Get my backend course https://backend.win