Remote Dictionary Server (Redis) and MongoDB are two NoSQL databases that store data in an unstructured format. NoSQL databases store data differently than relational databases, which use tables, rows, and columns. Redis is an open-source, in-memory database that stores data as key-value pairs. It stores data in RAM for high performance but does offer on-disk persistent storage as an additional feature. MongoDB is a source-available document database that stores data in serialized JSON format. It stores data on external memory but includes an in-memory storage engine in the enterprise edition.","sortDate":"2023-07-20","headlineUrl":"https://aws.amazon.com/compare/the-difference-between-redis-and-mongodb/?trk=faq_card","id":"faq-hub#whats-the-difference-between-redis-and-mongodb","category":"Databases","primaryCTA":"https://portal.aws.amazon.com/gp/aws/developer/registration/index.html?pg=compare_header","headline":"What’s the Difference Between Redis and MongoDB?"},"metadata":{"tags":[{"id":"GLOBAL#tech-category#databases","name":"Databases","namespaceId":"GLOBAL#tech-category","description":"Databases","metadata":{}},{"id":"faq-hub#faq-type#compare","name":"compare","namespaceId":"faq-hub#faq-type","description":"
compare","metadata":{}}]}}]},"metadata":{"auth":{},"testAttributes":{}},"context":{"page":{"locale":null,"site":null,"pageUrl":"https://aws.amazon.com/compare/the-difference-between-redis-and-mongodb/","targetName":null,"pageSlotId":null,"organizationId":null,"availableLocales":null},"environment":{"stage":"prod","region":"us-east-1"},"sdkVersion":"1.0.115"},"refMap":{"manifest.js":"289765ed09","what-is-header.js":"251923df8a","what-is-header.rtl.css":"ccf4035484","what-is-header.css":"ce47058367","what-is-header.css.js":"004a4704e8","what-is-header.rtl.css.js":"f687973e4f"},"settings":{"templateMappings":{"category":"category","headline":"headline","primaryCTA":"primaryCTA","primaryCTAText":"primaryCTAText","primaryBreadcrumbText":"primaryBreadcrumbText","primaryBreadcrumbURL":"primaryBreadcrumbURL"}}}
Remote Dictionary Server (Redis) and MongoDB are two NoSQL databases that store data in an unstructured format. NoSQL databases store data differently than relational databases, which use tables, rows, and columns. Redis is an open-source, in-memory database that stores data as key-value pairs. It stores data in RAM for high performance but does offer on-disk persistent storage as an additional feature. MongoDB is a source-available document database that stores data in serialized JSON format. It stores data on external memory but includes an in-memory storage engine in the enterprise edition. \n Learn more about NoSQL databases » \n Read about MongoDB » \n ","id":"seo-faq-pairs#whats-the-difference-between-redis-and-mongodb","customSort":"1"},"metadata":{"tags":[{"id":"seo-faq-pairs#faq-collections#whats-the-difference-between-redis-and-mongodb","name":"whats-the-difference-between-redis-and-mongodb","namespaceId":"seo-faq-pairs#faq-collections","description":" whats-the-difference-between-redis-and-mongodb","metadata":{}}]}},{"fields":{"faqQuestion":"Data model: Redis vs. MongoDB ","faqAnswer":" Redis and MongoDB use distinct data models and architecturally store data differently. \n Redis stores data in RAM, so you can access data directly from memory. While this provides low-latency responses, it also limits the volume of data you can store. Redis saves the dataset to disk through snapshotting and append-only file (AOF) logging, which provides data durability. \n Redis stores data as key-value pairs, where each data entry has a unique key. It supports various data types like sorted sets, hashes, sets, lists, and strings. Keys can be any length up to a total of 512MB. \n The following image shows the Redis data model. \n \n MongoDB follows a document data model to primarily store data in external memory storage. It stores data as serialized Binary JSON (BSON) documents. The maximum document size is 16MB. \n MongoDB’s architecture is useful for scaling large data volumes as it can increase capability based on disk space. Enterprise users can also use an in-memory storage engine for a hybrid approach. You can use memory caching for data you frequently access, while still primarily relying on disk storage for persistence. \n The following image shows the MongoDB data model. \n ","id":"seo-faq-pairs#data-model-redis-vs-mongodb","customSort":"2"},"metadata":{"tags":[{"id":"seo-faq-pairs#faq-collections#whats-the-difference-between-redis-and-mongodb","name":"whats-the-difference-between-redis-and-mongodb","namespaceId":"seo-faq-pairs#faq-collections","description":" whats-the-difference-between-redis-and-mongodb","metadata":{}}]}},{"fields":{"faqQuestion":"Similarities between Redis and MongoDB","faqAnswer":" Both Redis and MongoDB are NoSQL databases that offer flexible schema design, horizontal scalability, and high availability. You can use them to store unstructured data like documents and images more flexibly. Unlike relational databases, they allow for dynamic data models that don’t use schemas. \n There are various similarities between these two non-relational databases. \n Redis and MongoDB provide secondary indexing. With this function, you can create additional indexes on non-primary key fields. Once you have made these additional indexes, you can query and retrieve data faster while searching different criteria. Secondary indexing increases flexibility and query performance in both NoSQL databases. \n To provide high availability and durability, MongoDB and Redis use replication. You create replica sets (or clusters), where the NoSQL databases replicate data across several nodes to provide redundancy. In both databases, there’s a primary instance that accepts write operations and one or more secondary instances that replicate the data from the primary instance. If the primary instance fails, a secondary one can take over. \n \n Both Redis and MongoDB deliver low-latency responses and can handle high-throughput workloads. Redis is an in-memory database, which means it stores data in memory. This storage system allows Redis to deliver high-speed read and write operations. MongoDB combines memory storage with disk-based storage, which provides speed and data durability. ","id":"seo-faq-pairs#similarities-between-redis-and-mongodb","customSort":"3"},"metadata":{"tags":[{"id":"seo-faq-pairs#faq-collections#whats-the-difference-between-redis-and-mongodb","name":"whats-the-difference-between-redis-and-mongodb","namespaceId":"seo-faq-pairs#faq-collections","description":" whats-the-difference-between-redis-and-mongodb","metadata":{}}]}},{"fields":{"faqQuestion":"Key differences: Redis vs. MongoDB","faqAnswer":" Redis and MongoDB also have differences in their functions and capabilities. Here are some other key points of difference between the two. \n Horizontal scaling enables MongoDB to handle large volumes of data efficiently. It uses sharding to distribute data across multiple regions and nodes. With cross-sharding operations, you can query and update across multiple shards. \n Redis doesn’t offer the same degree of scalability as MongoDB. Redis only uses a single shard by default for primary operations. You must manually maintain sharding on a hash basis, which makes management more complicated. Redis also lacks cross-shard functionality. \n Both MongoDB and Redis support availability through replication. However, MongoDB supports a higher degree of availability by using replica sets. MongoDB can create up to 50 copies of your data, distributed across multiple nodes, data centers, and even geographic regions. It supports automatic failover mechanisms; if a primary node goes offline, it elects a new primary node from the replicas. \n In contrast, Redis doesn’t provide automatic failover by default. Admin users initiate manual failover, especially if the replica is in a different data center. You have to set up and configure a separate component, called Redis Sentinel, if you want automatic failover. \n MongoDB supports multi-document atomic, consistent, isolated, and durable (ACID) transactions. So, you can keep data consistent across multiple operations. Using multi-document transactions, you can perform multiple operations as one unit. Within a session, MongoDB commits all changes or rolls them back, which helps ensure ACID compliance. \n Conversely, Redis does not provide built-in ACID support. However, you can use the MULTI command to group multiple commands into a single atomic operation. But this alone isn’t a solution. You also need to implement rollback functionality within your application code, as Redis doesn’t support this natively within transactions. \n MongoDB provides a high level of flexibility in its querying, even performing complex spatial computations and data analysis functions. MongoDB uses MongoDB Query Language (MQL), which supports JSON-like syntax to simplify advanced querying. With MQL, you can perform advanced queries across single or multiple keys, text searches, and ranges. \n In contrast, Redis is optimized for fast key-value access operations rather than complex querying and searching capabilities. You use Redis mainly by providing keys and retrieving corresponding data. Redis doesn’t have a query language like MQL. Instead, it offers a wide range of commands to interact with data. For example, you can use the GET command to retrieve values, by providing the corresponding keys. ","id":"seo-faq-pairs#key-differences-redis-vs-mongodb","customSort":"4"},"metadata":{"tags":[{"id":"seo-faq-pairs#faq-collections#whats-the-difference-between-redis-and-mongodb","name":"whats-the-difference-between-redis-and-mongodb","namespaceId":"seo-faq-pairs#faq-collections","description":" whats-the-difference-between-redis-and-mongodb","metadata":{}}]}},{"fields":{"faqQuestion":"When to use Redis vs. MongoDB","faqAnswer":" For temporary data storage with rapid querying, use Redis. For long-term persistent storage of complex data with rich querying, use MongoDB. \n Redis provides fast access to frequently accessed data, which makes it suitable for caching and session storage. You can use it in real-time applications or event-driven architectures due to its built-in support for publish-subscribe (pub/sub) messaging patterns. It also offers advanced data structures like sorted sets and lists, which can be used for implementing rate limiting, task queues, and job scheduling systems. It’s also efficient for counting and aggregating data, which makes it suitable for tracking leaderboard data or other statistics. \n In contrast, you can use MongoDB for storing complex application data at scale. It offers more traditional database structures and storage that doesn’t use a schema, so developers can take a more flexible approach. It handles high-volume writes and reads efficiently and can handle large datasets. You can use it for content management or for managing user profiles at scale. MongoDB also has built-in geospatial indexes and supports spatial queries, which makes it suitable for location-based applications or data with geospatial components.","id":"seo-faq-pairs#when-to-use-redis-vs-mongodb","customSort":"5"},"metadata":{"tags":[{"id":"seo-faq-pairs#faq-collections#whats-the-difference-between-redis-and-mongodb","name":"whats-the-difference-between-redis-and-mongodb","namespaceId":"seo-faq-pairs#faq-collections","description":" whats-the-difference-between-redis-and-mongodb","metadata":{}}]}},{"fields":{"faqQuestion":"Can you use Redis and MongoDB together?","faqAnswer":" Using Redis and MongoDB together is a common strategy in many applications. The speed of Redis naturally complements the long-term storage capabilities of MongoDB. You can use both Redis and MongoDB to optimize database performance, boost scalability, and provide a flexible system for your applications. \n For example, you could use Redis for real-time data processing. Redis is ideal for capturing and processing live streaming data, as it handles real-time data processing scenarios. Then, you can store the data or results that you process with Redis in MongoDB for archiving and more complex integrated analytics. \n Another example is a hybrid data model across Redis and MongoDB. You could use Redis’ key-value store and MongoDB’s document-oriented model at the same time. Redis provides a simple system to access metadata you frequently access, while you can use MongoDB for more complex data structures. ","id":"seo-faq-pairs#can-you-use-redis-and-mongodb-together","customSort":"6"},"metadata":{"tags":[{"id":"seo-faq-pairs#faq-collections#whats-the-difference-between-redis-and-mongodb","name":"whats-the-difference-between-redis-and-mongodb","namespaceId":"seo-faq-pairs#faq-collections","description":" whats-the-difference-between-redis-and-mongodb","metadata":{}}]}},{"fields":{"faqQuestion":"Summary of differences: Redis vs. MongoDB","faqAnswer":"Redis \n
MongoDB \n
Secondary indexing \n
Replication \n
Performance \n
Scaling \n
Availability \n
Integrity \n
Query language \n