Panoply Blog: Data Management, Warehousing & Data Analysis

Redis vs MongoDB

Written by Matan Sarig | May 29, 2017 3:01:00 PM

The battle of the NoSQL databases continues. We first analyzed Cassandra vs MongoDB. This time we will dig in Redis vs MongoDB.

Redis is an in-memory database that has been benchmarked as the fastest database in the world, while MongoDB is known for its flexibility. 

Who Uses These Databases?

Here are a few examples of companies that use these databases:

Redis: Jet.com, Samsung, Intuit, UnitedHealthcare, Shopify, TMZ

MongoDB: The Weather Channel, eBay, Electronic Arts, Forbes, Under Armour

What About Database Structure?

Redis: In its simplest form, Redis uses key-value stores to store data with pairs of a key and an associated value. This structure is very different from relational databases that have tables featuring rows and columns, and can be difficult for some traditional SQL buffs to master.

It is probably best to show how key-value works with an example:

Let’s assume you have a list of dog calendars and you need to track the photographer along with the type of dog for each calendar so you’ll know who to contact when you need a calendar for next year.

A simple key-value pair can be represented with this format:

Dogbreed : “beagle”

Photographer : “Joe Photographer”

To retrieve the dog breed or photographer from the example above, you would need to use the GET command:

> GET Dogbreed

“beagle”

> GET Photographer

“Joe Photographer”

When you need to retrieve additional dog breeds and photographers, one way to do this is to use namespaces. With namespaces, you add a unique number after the key name that will allow you to retrieve the data.

> GET Dogbreed:1

“beagle”

>GET Dogbreed:2

“labrador”

Redis also offers more advanced data structures like lists, sorted sets, hashes, strings, sets, bitmaps, and more. Redis Modules can be used to extend these capabilities further, turning it into a JSON store, search engine, rate limiter, and much more.

MongoDB: MongoDB uses JSON-like documents to store schema-free data. In MongoDB, collections of documents do not have to have a predefined structure and columns can vary for different documents.

MongoDB has many of the features of a relational database, including an expressive query language and strong consistency. However, since it is schema-free MongoDB allows you to create documents without having to create the structure for the document first.

 Are Indexes Needed?

Redis: Secondary indexing is available with Redis. It is possible to use sorted sets to create these indexes. Advanced secondary indexes, graph traversal indexes, and composite indexes are also possible.

MongoDB: Indexes are preferred for MongoDB. If you don’t have an index, every document must be searched within the collection, which can slow read times.

 How Are Their Queries Different?

Selecting records:

Redis: KEYS * - retrieves all existing keys and values

MongoDB: db.calendars.find()

 

Inserting records into the customer table:

Redis: SET dogbreed:1 "beagle"

MongoDB: db.calendars.insert({ dogbreed : 'beagle' })

 Where (And How) Are These Databases Deployed?

Redis: Redis was written in C. It is available on BSD, Linux, OS X, and Windows.

Redis has support for the following programming languages: C, C#, C++, Clojure, Crystal, D, Dart, Elixir, Erlang, Fancy, Go, Haskell, Haxe, Java, JavaScript, Lisp, Lua, MatLab, Objective-C, OCaml, Perl, PHP, Prolog, Pure Data, Python, R, Rebol, Ruby, Rust, Scala, Scheme, Smalltalk, Tcl

MongoDB: MongoDB was written in C++. It is available on Linux, OS X, Solaris, and Windows.

MongoDB has support for the following programming languages: Actionscript, C, C#, C++, Clojure, ColdFusion, D, Dart, Delphi, Erlang, Go, Groovy, Haskell, Java, JavaScript, Lisp, Lua, MatLab, Perl, PHP, PowerShell, Prolog, Python, R, Ruby, Scala, Smalltalk

What Types Of Replication / Clustering Are Available?

Redis: Redis offers master – slave replication. Using Redis Enterprise, you can have a cluster manager and shared-nothing cluster architecture. Redis handles sharding and re-sharding along with migration to make scaling automated. It offers high-availability with persistence along with in-memory replication that scales from racks to data centers to multiple cloud platforms.

MongoDB: MongoDB has a single-master replication with built-in auto-election. This means you can have a second database set up and it can be auto-elected if the primary database becomes unavailable. With MongoDB replica sets, one member is primary and any replicated databases have a secondary role.

Panoply, smart data warehouse, allows you to connect to Redis and MongoDB at the same time, giving you access to all of your data from one place.

Who's Currently Behind The Databases?

Redis: Redis was created in 2009 and is currently run by RedisLabs. It is being distributed using the open source BSD license.

MongoDB: MongoDB is currently managed by MongoDB, Inc. It was originally started in 2007 by 10gen which later changed its name to MongoDB, Inc.

 Who Provides Support?

Redis: Community support is available via the mailing list as well as #redis on Freenode (irc://irc.freenode.net/#redis). Commercial managed support is provided by RedisLabs. With managed support, you get a fully managed instance with email alerts, backups, SSL and more.

MongoDB: Community support for MongoDB is available at StackOverflow, ServerFault, Community Support Forum, and Freenode IRC chat (irc://irc.freenode.net/#mongodb).

MongoDB, Inc. offers 24x7 enterprise support with optional extended lifecycle support for people that want to use an older version. With support, you also have access to security updates and fixes.

 Who Maintains The Documentation?

Redis: RedisLabs maintains the documentation and can be found at redis.io/­documentation

MongoDB: The MongoDB documentation is maintained by MongoDB, Inc. and can be found at https://docs.MongoDB.com/

 Is There An Active Community?

Redis: The Redis community page contains instructions for local meet ups and how to contribute to the project.

MongoDB: MongoDB has their community page at https://www.MongoDB.com/community where they offer the latest news about user groups, webinars, events, and MongoDB University.

 Which Database Is Right For Your Business?

 Redis:

When speed is a priority

If you need a high performance database, Redis is hard to beat. Redis can be a good way to increase the speed of an existing application.

Not a typical standalone database

Redis is typically not a standalone database for most companies. With Craigslist, Redis is used alongside their existing primary database (i.e. MongoDB). While it is possible for a company to use Redis by itself, it’s uncommon.

When you have a well-planned design

With Redis, you have a variety of data structures that include hashes, sets, and lists but you have to define explicitly how the data will be stored. You have to plan your design and decide in advance how you want to store and then organize your data. Redis is not well suited for prototyping. If you regularly do prototyping, MongoDB is probably a better choice.

If your database will have a predictable size (or will stay the same size), Redis can be used to increase lookup speed. If you know your key, then lookup will be very fast. For applications that need real-time data, Redis can be great because it can look up information about specific keys quickly.

The size of your data is stable

While it is possible to do master-slave replication using Redis, being able to distribute your keys between multiple instances must be done within your application. This makes Redis harder to scale than MongoDB.

 MongoDB:

More flexible

If you’re not certain how you will query your data, MongoDB is probably a better choice. MongoDB is better for prototyping and is helpful when you need to get data into a database and you’re not certain of the final design from the beginning.

Easier to learn

With MongoDB, it is easier to query data because MongoDB uses a more consistent structure. MongoDB typically has a shorter learning curve.

Better use of large, growing data sets

If you need to store data in large data sets with the potential for rapid growth, MongoDB is a good choice. MongoDB is also easier to administer as the database grows.

If you want to have an even better understanding about MongoDB and its differences with other NoSQL databases, check our Cassandra vs MongoDB analysis.

Conclusion

Redis vs MongoDB? The right database for your business will likely depend upon your dev team and the applications you use.

You can pick Redis, MongoDB (or perhaps both!) to run your business. Either way, Panoply, with its cloud based data warehouse architecture, gives you a single data management solution that will connect Redis, MongoDB, cloud, and more without coding.

In addition, you can read more about Redshift clusters and Redshift architecture