Redis: Something to think of while choosing data store next time

Deepti Mittal
6 min readJan 17, 2022

Redis, which stands for Remote Dictionary Server, is a fast, open source, in-memory, key-value data store. The project started when Salvatore Sanfilippo, the original developer of Redis, wanted to improve the scalability of his Italian startup. From there, he developed Redis, which is now used as a database, cache, message broker, and queue.

Redis features and advantages

  • Performance: All Redis data resides in memory, which enables low latency and high throughput data access. Unlike traditional databases, In-memory data stores don’t require a trip to disk, reducing engine latency to microseconds. Because of this, in-memory data stores can support an order of magnitude more operations and faster response times. The result is blazing-fast performance with average read and write operations taking less than a millisecond and support for millions of operations per second.
  • Simplicity and ease-of-use: Redis enables you to write traditionally complex code with fewer, simpler lines. With Redis, you write fewer lines of code to store, access, and use data in your applications. Redis comes with native data structures and many options to manipulate and interact with your data. Many open source clients are available for Redis developers. Supported languages include Java, Python, PHP, C, C++, C#, JavaScript, Node.js, Ruby, R, Go, and many others.
  • High availability and scalability: Redis offers a primary-replica architecture in a single node primary or a clustered topology. This allows you to build highly available solutions providing consistent performance and reliability. When you need to adjust your cluster size, various options to scale up and scale in or out are also available. This allows your cluster to grow with your demands.
  • Easy to setup and work with: After downloading, Redis set up just take 5 mins and will be ready for start using and experimenting.
  • Flexible data structures: Unlike other key-value data stores that offer limited data structures, Redis has a vast variety of data structures to meet your application needs. Redis data types include:

Strings — text or binary data up to 512MB in size

Lists — a collection of Strings in the order they were added

Sets — an unordered collection of strings with the ability to intersect, union, and diff other Set types

Sorted Sets — Sets ordered by a value

Hashes — a data structure for storing a list of fields and values

Bitmaps — a data type that offers bit level operations

HyperLogLogs — a probabilistic data structure to estimate the unique items in a data set

Streams — a log data structure Message queue

Geospatial — a longitude-/latitude-based entries Maps, “nearby”

Redis drawbacks

  • Redis is a data structure server. There is no query language. You cannot submit ad-hoc queries (like you can using SQL on a RDBMS). All data accesses should be anticipated by the developer, and proper data access paths must be designed. A lot of flexibility is lost.
  • Redis offers 2 options for persistency: regular snapshotting and append-only files. None of them is as secure as a real transactional server providing redo/undo logging, block checksuming, point-in-time recovery, flashback capabilities, etc …
  • Redis only offers basic security (in term of access rights) at the instance level. RDBMS all provide fine grained per-object access control lists (or role management).
  • A unique Redis instance is not scalable. It only runs on one CPU core in single-threaded mode. To get scalability, several Redis instances must be deployed and started. Distribution and sharding are done on client-side (i.e. the developer has to take care of them). If you compare them to a unique Redis instance, most RDBMS provide more scalability (typically providing parallelism at the connection level). They are multi-processed (Oracle, PostgreSQL, …) or multi-threaded (MySQL, Microsoft SQL Server, … ), taking benefits of multi-cores machines.
  • Clients connecting to redis cluster should be aware of cluster topology, causing overhead configurations on clients.
  • Requires huge RAM as data is stored in-memory.
  • Master-slave structure side effect: Master-slave architecture comes with its own side effects. Please note that there will be only one master with multiple slaves for replication. All writing goes to the master, which creates more load on the master node. So, when the master goes down, the whole architecture does.
  • Lacks better UI like other systems, Only command like application available for free. Hence become difficult to do administrations work for redis.
  • Redis replication is asynchronous. Therefore, when a primary cluster fails over to a replica, a small amount of data might be lost due to replication lag.

Redis popular use cases

  1. Caching: Redis is a great choice for implementing a highly available in-memory cache to decrease data access latency, increase throughput, and ease the load off your relational or NoSQL database and application. Redis can serve frequently requested items at sub-millisecond response times, and enables you to easily scale for higher loads without growing the costlier backend. Database query results caching, persistent session caching, web page caching, and caching of frequently used objects such as images, files, and metadata are all popular examples of caching with Redis.
  2. Gaming leaderboards: Redis is a popular choice among game developers looking to build real-time leaderboards. Simply use the Redis Sorted Set data structure, which provides uniqueness of elements while maintaining the list sorted by users’ scores. Creating a real-time ranked list is as easy as updating a user’s score each time it changes. You can also use Sorted Sets to handle time series data by using timestamps as the score.
  3. Session store: Redis as an in-memory data store with high availability and persistence is a popular choice among application developers to store and manage session data for internet-scale applications. Redis provides the sub-millisecond latency, scale, and resiliency required to manage session data such as user profiles, credentials, session state, and user-specific personalization.
  4. Real-time analytics: Redis can be used with streaming solutions such as Apache Kafka and Amazon Kinesis as an in-memory data store to ingest, process, and analyze real-time data with sub-millisecond latency. Redis is an ideal choice for real-time analytics use cases such as social media analytics, ad targeting, personalization, and IoT.
  5. Machine Learning: Modern data-driven applications require machine learning to quickly process a massive volume, variety, and velocity of data and automate decision making. For use cases like fraud detection in gaming and financial services, real-time bidding in ad-tech, and matchmaking in dating and ride sharing, the ability to process live data and make decisions within tens of milliseconds is of utmost importance. Redis gives you a fast in-memory data store to build, train, and deploy machine learning models quickly.
  6. Geospatial: Redis offers purpose-built in-memory data structures and operators to manage real-time geospatial data at scale and speed. Commands such as GEOADD, GEODIST, GEORADIUS, and GEORADIUSBYMEMBER to store, process, and analyze geospatial data in real-time make geospatial easy and fast with Redis. You can use Redis to add location-based features such as drive time, drive distance, and points of interest to your applications.
  7. Chat, messaging, and queues: Redis supports Pub/Sub with pattern matching and a variety of data structures such as lists, sorted sets, and hashes. This allows Redis to support high performance chat rooms, real-time comment streams, social media feeds and server intercommunication. The Redis List data structure makes it easy to implement a lightweight queue. Lists offer atomic operations as well as blocking capabilities, making them suitable for a variety of applications that require a reliable message broker or a circular list.

I love Redis and is there is data to be stored for short term Redis should definitely be considered.

Good references to get more details:

https://aws.amazon.com/redis/

https://redis.com/blog/5-industry-use-cases-for-redis-developers/

https://www.trustradius.com/products/redis/reviews?qs=pros-and-cons&f=25#reviews

--

--

Deepti Mittal

I am working as software engineer in Bangalore for over a decade. Love to solve core technical problem and then blog about it.