Tarantool and Memcached: Two Cache Engines Considered
There are many things to consider when deciding between Memcached and Tarantool — everything from syncing issues to the need for persistence to scaling.
Join the DZone community and get the full member experience.Join For Free
Memcached (2003) and Tarantool (2009) hail from two different generations of in-memory cache databases. So, in some respects, it isn't completely fair to compare them because later technologies often benefit from and surpass earlier ones. But just because a technology comes later doesn't mean it's the best tool for the job; sometimes, a less capable but simpler technology may fit your needs. This article assumes that you're choosing between Memcached and Tarantool for a new application or perhaps are deciding whether to continue to support a legacy Memcached installation.
Caching vs. Smart Caching
Memcached operates with a nice and simple approach. Applications using it check first to see whether requested data is in Memcached before making a call to the slower database it is paired with. One issue that can arise is when Memcached and its paired database get out of sync due to a failed update on one or the other since they're not replicated and the application is communicating with them separately. Tarantool fixes this problem by functioning as a smart cache, meaning that an update will be completed in Tarantool only after the update has succeeded in the paired database. The way this works is that instead of communicating with both layers, an application communicates only with Tarantool, which is responsible for updating the paired database. Additionally, you can perform work on the data in Tarantool at any point in the process using the full Lua application server that runs concurrent to its database server.
Reads and Writes
A major difference between the two cache options is their respective capabilities for handling reads from and writes to paired databases. Memcached is intended for offloading reads but not writes. Tarantool supports reads quite well; in fact, its high efficiency per core may allow you to downsize expensive enterprise replicas. However, Tarantool also has extensive capabilities for writes. It handles them at scale and can thus potentially replace any highly available relational machines up front in a stack. And Tarantool's write duties can also be transactional because it is fully ACID.
When you start Memcached, it has no data, so all selects must hit the paired database directly. Tarantool's persistence feature fixes this issue because it reconstitutes your data from saved files.
Simplicity of Use
Memcached is easy to install and allows you to
SET quite quickly, which may be all that you require. Tarantool is also easy to install, but given its deeper feature set, naturally has more extensive syntax. Familiarizing yourself with it, however, could eventually pay off with what you are able to accomplish with it — everything from microservices to the aforementioned high-load, ACID-compliant OLTP.
Memcached was invented to support other databases. Tarantool works in conjunction with other databases but can also function completely independently — which is uncommon for a cache solution. There are several features that enable Tarantool to accomplish this: high-quality persistence, the aforementioned ACID transactions, the ability to work with data sets larger than RAM, and a full application server. In fact, not only can Tarantool run independently of a relational database, it can run without an additional backend language, as well. You can program anything you'd like in Lua, and, unlike more traditional stored procedures, your work can be backed up to version control.
Memcached was designed to scale easily by adding extra machines, although you will need to use consistent hashing to avoid losing data. Scaling Tarantool, because it handles writes as well as reads, can require a combination of replication and sharding — but is quite doable.
As you can see, there are many things to consider when deciding between Memcached and Tarantool — everything from syncing issues to the need for persistence to scaling. Should you have any questions regarding Tarantool's side of the equation, please contact us.
Opinions expressed by DZone contributors are their own.