https://unsplash.com/photos/HtBlQdxfG9k

What is Redis and when should you use it?

What is Redis?

Redis is an in-memory data structure store, used as a database, cache, and message broker. This was taken directly from the Redis website.

Memcached architecture. Icons from Icons8.com. Image by Justin Barnett
Redis Architecture
  • Sets
  • Sorted Sets
  • Queues
  • Trees
  • BitArrays
  • Streams
  • Message broker (Pass messages between 2 different programs connected on the same network)
  • Search Indexes
  • Bloom Filters
  • Real time applications
Icons from Icons8.com. Image by Justin Barnett

When to not to use Redis?

Before talking about when to use Redis we should talk about when not to use Redis. Redis is inherently more than a cache, therefore you are typically bound by the memory constraints of the system Redis is hosted on. This means that if you plan on storing huge files, Redis probably isn’t the best choice for you.

  • Large Datasets (Memcached is better for you since the data is simple. Memcached can scale easily with instances)
  • Simple operations (If you are not going to be using Redis in a micro-services architecture or RT application, there’s very little argument on using Redis vs Memcached)

When to use Redis?

Now we covered when not to use Redis, we should talk about where Redis really shines.

Microservices

If you have a services based architecture, where you have each individual operation handled by an independently owned service, then Redis can be used as a way for all of your services to communicate with one another other

Real Time Applications

There are time constraints for processing with real time applications. Data continuously streams in which needs to be processed. If you cannot process quickly enough there is a chance of data to be dropped. This leads to a subpar user experience. Redis has simple operations to append data to a stream and effectively creates a ‘backlog’ for your unprocessed data.

Constraints of Redis

  • Keys are bound 1:1. They must be deleted before updated
  • There are no reserved keywords for strings as strings are stored as bytes
  • Maximum key, value size is 512MB
  • 2³² maximum keys
  • Single machine unless Redis is Clustered

In Conclusion

Building systems is about using the right tool at the right time. Memcached is a great k/v store that is simple and scales horizontally. Redis is a level up and offers a message broker for distributed systems and streams for RT applications. Both have their merits however using the right tool for the job is an important decision for your tech stack.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store