Redis As a Caching Layer
Relational Database Management Systems (RDBMs) are great for holding data that is needed over a long period of time. But for data that is frequently changed, an in-memory key-value store like Redis might be the right approach. Since Redis data is stored in memory, it can be more easily accessed than data stored on disk. Redis also happens to be most popular key-value database.
So, why would you want to Redis for your website? For a very simple reason: It will make your site load faster. If you use frequently accessed data in Redis—like user sessions, cookies, comments, snippets of text—then your front-end does not have to retrieve that data from a database server, thus making your site load more quickly.
Here are different characteristics of Redis:
- Redis supports different kinds of abstract data structures, such as strings, lists, sets, maps, and sorted sets. Redis also has support for special data types, such as geo-spatial data; this makes Redis a good candidate to calculate things such as distance between two addresses. High-level server-side operations such as intersection, union, and difference between sets are supported.
- Even though the main feature of Redis is its in-memory data access, Redis does allow you to periodically write that data to the disk, thus providing data persistence. Writing data to the disk has a performance penalty though.
- There are many ways to scale Redis, one of them is replication. Redis supports master-slave replication, wherein any Redis server can replicate data to any number of slaves. A slave can, in turn, replicate data to other slaves. This allows Redis to create a single-rooted replication tree. Obviously, slaves have limited ability to accept writes. This makes replication a useful feature for scaling read operations. There is no easy way to scale write operations, since Redis is a single-threaded process and it cannot perform parallel execution.
- The clustering story around Redis is new and evolving. There are trade-offs between scalability and write safety; you must understand these trade-offs well before implementing Redis clusters.
- Many large companies, such as Amazon, Microsoft and Twitter, are using Redis for their internal operations. Redis' ecosystem is quickly evolving and finding technical talent that knows Redis is surprisingly easy.