Main differences between MongoDB and Redis


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 that needs constant updates because it is faster to write and read data on a hard disk.

The question is, why use MongoDB? What is the technical reason for splitting the project between MongoDB and Redis?

asked by anonymous 29.09.2014 / 16:16

1 answer


Redis uses a different MongoDB paradigm.

Redis uses the key-value paradigm for data storage. Basically, it's a "giant array" that stays in the server's memory, you ask Redis to "give me the key data XXX" and it only returns the data. It can work with simple data and with data lists. Advantages: Access to data is done in an agile way, without access to the disk , from asthmatic form O (1) (translating: very fast indeed). Disadvantages: It does not allow special operations such as SQL joins or data nesting, not to mention that because the data is all stored in RAM, you need available memory space of the same size as the amount of data you are going to store, which can be a problem.

MongoDB uses the documents paradigm . It stores the data in JSON format, in a nested way (documents can contain data, arrays or other documents) and not relational. Advantages: quick access to data and easy visualization because it is a JSON, which is much more human-readable than other data formats. Disadvantage: Just like Redis, there is no data relationship. If a relationship is needed, it must be performed 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 commonly used for simple things that need to be cached or for quick access. MongoDB is a flexible document database that does not use relationships between documents and allows documents to store data, arrays, and even other documents.

30.09.2014 / 19:39