Main differences between Mongodb and Redis

Asked

Viewed 2,562 times

8

I’m reading a book on real time applications with Nodejs.

The author used Mongodb and Redis to exemplify the use of database with Nodejs.

My doubt arose when he used both at the same time, justifying that Redis would be used for data requiring constant updates because it is faster to write and read data on a hard drive.

The question is, why use Mongodb? What is the technical reason to divide the project between Mongodb and Redis?

1 answer

10

Redis uses a different paradigm than Mongodb.

Redis uses the paradigm value key for the storage of data. Basically, it is a "giant array" that stays in the server memory, you ask Redis to "give me the data of the XXX key" and it only returns the data. It can work with simple data and with data lists. Perks: access to data is provided in an agile manner, no access to the disk, of asymptotic form O(1) (very fast indeed). Disadvantages: it does not allow special operations such as SQL joins or nesting data, not to mention that as the data is all stored in RAM, you need available memory space of the same size as the amount of data you will store, which can be a problem.

Mongodb uses the paradigm of documents. It stores the data in format JSON, nested (documents may contain data, arrays or other documents) and non-relational. Perks: quick access to data and easy viewing because it is a JSON, which is much more Human-readable what other data formats. Downside: Just like Redis, there is no data relationship. If any relationship is required, it should be done at the application level, for example: User B was created by User A, but User A was deleted from the system, so it is up to your application to treat this type of null referencing, since Mongodb does not make relationships.


In short: Redis is an array that stays in memory and is most used for simple things that need to be curly or for quick access. Mongodb is a flexible document database that does not use relationships between them and allows documents to store data, arrays and even other documents.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.