5 Reasons Why You Should Use Redis As Your Web App's Database

5 Reasons Why You Should Use Redis As Your Web App's Database

Redis is an open-source in-memory key-value cache store which has been around since 2009. Many high-traffic websites opt to use it due to its extraordinary performance; it offers sub-millisecond latency. In this article we discuss reasons why you should use Redis as your web application's database.

#1: Redis is really, really fast

The first thing you will notice when you start using Redis is that it is extremely fast. What's more, Redis does not slow down when you add more data, in contrast to regular SQL databases, where the lookup time increases with the number of records you have. This makes Redis extremely attractive for sites where performance is a top concern.

Redis' speed means that you can access and write data in a fraction of the time it would take to do so with a regular SQL database. We advise going for Redis as your main database primarily for performance reasons; logging in users to your web application is lightning fast with Redis, whereas it may take a second or two with a traditional database. This speed saving makes the overall experience better for your end users.

We decided to use Redis because of its speed and scalability.Anthony Daly, CEO & Founder, PushRadar

#2: Redis is easy to implement

Forget lengthy SQL queries and parsing of results. Redis offers an entirely different way of working to what you may be used to; Redis databases are structured with keys. Each key can hold one value, or in the case of hashes or sets, multiple values. Redis features simple data types and a set of commands which can be run to do things such as retrieve the content of a key or expire a key after a set number of seconds. This makes Redis really easy to work with.

Redis' documentation is great, and there is a large, active community backing the project. If you need help at any time, a quick Google search should return the command you are looking for. The language bindings are also very easy to access; dedicated libraries have been produced for PHP, Node and other languages, which allow you to easily set up and work with Redis.

#3: Redis scales up much better than MySQL

For many websites, scalability is a concern. Whereas processes may work well for one or two users, what happens if your web app gets 100,000 users or more on it? Can your web app cope with the demands of such traffic? It is important to design for scalability from day one of making your web app, and nothing matters more than what database you choose on the back end.

MySQL isn't awfully good at scaling up. Generally, the more users you have, the more MySQL will slow down, and this is simply not good enough for web apps of today. Redis on the other hand is much better than MySQL in regards to scaling up. Its performance does not suffer the more users you add, and because the data is stored in-memory, it can be retrieved in an instant. Not to mention, you can distribute data easily among multiple Redis instances, making scalability simple.

#4: Redis is secure

Redis offers basic security which is good enough for the vast majority of cases. Redis instances can be password protected and you can whitelist certain IP addresses from the sources you would expect to access your Redis cache.

Redis can be installed on a dedicated server. You should ideally put your Redis cache on a separate, dedicated server and use private networking from each main web application server to access it. This way, if your main web app server(s) get compromised, your data is safe on its own box.

#5: Redis is designed for flexibility

Redis is essentially NoSQL which means that you have great flexibility with regard to record properties; every record can have different properties, something which is a nightmare to replicate in MySQL.

Redis offers a range of data types to suit most needs. Serialization can be used to store complex objects in Redis; when storing an object, serialize it to a string, store the string and then unserialize it back to an object when you need to retrieve it.

Final word

Although Redis was designed to be a cache store, it can easily be adapted to be used as a database, with optional data persistence to disk. We hope that the above reasons will help you in your decision over whether to use Redis as your web app's database.