A programmer's blog - will deal with everything that relates to a programmer. Occasionally, it will contain some humour, some politics and some sport news.

Monday, September 29, 2008

Memcached and Terracotta : Alternatives or Complementary ?

Last week I was having a chatty tweeter session with Ari Zilka, CTO of Terracotta. It all started with Ari's initial observation regarding the confusion that exists in people's mind regarding the actual use of memcached and how it compares to Terracotta as a caching solution. Ari was chatty and I thought it would be pretty useful to share his observations with a broader audience. Here is a transcript of the chat, with some snippets of my own personal observations and conclusions ..

Do you think Terracotta is an alternative to Memcached ?

The following is a snapshot directly captured from the Twitter stream ..

Reminder to self :

Memcached is a specialized engine for caching *only*. In case you are trying to use it as a data store, think twice and refactor your thoughts.

Memcached is NOT a distributed hash table. This is quite a popular misconception that even Dare also mentions in one of his recent posts. Every memcached server is atomic and is not aware of any other memcached server in the cluster. Any algorithm for distribution, HA, failover is the responsibility of the client.

How do you handle database updates and prevent staleness of your memcached data ? Updates to data are usually handled by pushing writes to the database and then having some asynchronous processes (or database triggers) build objects that are pushed into memcached. In case of Terracotta it is the other way round. You write into Terracotta Network Attached Memory and the data gets pushed into the database through asynchronous write behinds.

Terracotta offers a truly coherent and clustered cache that remains consistent even in the presence of database writes through write behind to System of Record. Hence by writing data directly into Terracotta Network Attached Memory, data can be safely and durable stored, without risk of loss or corruption, and later drained to the DB asynchronously.

Can we conclude that for read-only (mostly) usecases, use memcached, while, for read-write usecases, use Terracotta to obtain transparent durability to the persistent store. Rather than alternatives, the two technologies are complementary.

Anonymous: Terracotta is not a "central server". It is a server array. That array is both mirrored and striped so losing a server in Terracotta is neither a performance issue nor an outage. If one node goes down, its mirror transparently takes over.