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"}}}

What’s the Difference Between Redis and MongoDB?


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 \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 \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

Secondary indexing \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

Replication \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

Performance \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

Scaling  \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

Availability \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

Integrity \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

Query language \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":"

\n \n \n \n \n \n \n \n
  \n

Redis \n

MongoDB \n \n

Data model \n

Key-value based in memory data store. \n

Persistent document database. \n \n

Scaling \n

Redis doesn’t offer as much scalability. \n

A MongoDB database is highly scalable through horizontal scaling, sharding, and partitioning data. \n \n

Availability \n

You need a separate component called Redis Sentinel to monitor clusters for automatic failover. \n

Automatic failover by default. \n \n

Integrity \n

Redis offers commands to create single atomic operations. Rollback must be managed in application code. \n

MongoDB has built-in support for multi-document ACID transactions and rollback. \n \n

Query language \n

Redis uses commands for querying. \n

MongoDB uses MongoDB Query Language (MQL) to query and manipulate data. \n \n \n","id":"seo-faq-pairs#summary-of-differences-redis-vs-mongodb","customSort":"7"},"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":"How can AWS help with your Redis and MongoDB requirements?","faqAnswer":"

Amazon Web Services (AWS) has many offerings to support your work with Redis and MongoDB. \n

Amazon MemoryDB is a Redis-compatible, durable, in-memory database service that delivers ultra-fast performance. It’s purpose-built for modern applications created with microservices architectures. MemoryDB stores data durably across multiple Availability Zones (AZs) using a Multi-AZ transactional log to enable fast failover, database recovery, and node restarts. You can achieve microsecond read and single-digit millisecond write latency alongside high throughput.  \n

Amazon ElastiCache is a fully managed caching service that makes it easy to set up, operate, and scale a cache in the cloud. With ElastiCache, you can accelerate application speed and unlock microsecond read and write latency by caching data from primary databases and data stores. \n

Amazon DocumentDB (with MongoDB compatibility) is a fully managed native JSON document database that scales enterprise workloads effortlessly. With the ability to store, query, index, and aggregate data in a flexible JSON format, you can develop and evolve applications faster than ever. A managed database eliminates the need for you to perform manual database management tasks, which increases productivity and streamlines development. \n

Get started with Redis and MongoDB on AWS by creating an account today.","id":"seo-faq-pairs#how-can-aws-help-with-your-redis-and-mongodb-requirements","customSort":"8"},"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":{}}]}}]},"metadata":{"auth":{},"pagination":{"empty":false,"present":true},"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":"3dea65b485","rt-faq.rtl.css":"75bc12ff4b","rt-faq.css":"b00bda11a1","rt-faq.css.js":"0af1d62724","rt-faq.js":"da177bdd5f","rt-faq.rtl.css.js":"a89cd83194"},"settings":{"templateMappings":{"question":"faqQuestion","answer":"faqAnswer"}}}

What’s the Difference Between Redis and MongoDB?

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.

Learn more about NoSQL databases »

Read about MongoDB »

 

Data model: Redis vs. MongoDB

Redis and MongoDB use distinct data models and architecturally store data differently. 

Redis

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. 

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.

The following image shows the Redis data model.

 

MongoDB

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.

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.

The following image shows the MongoDB data model.

Similarities between Redis and MongoDB

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.

There are various similarities between these two non-relational databases.

Secondary indexing

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.

Replication

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.

 

Performance

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. 

Key differences: Redis vs. MongoDB

Redis and MongoDB also have differences in their functions and capabilities. Here are some other key points of difference between the two.

Scaling 

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.

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. 

Availability

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. 

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. 

Integrity

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.

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. 

Query language

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. 

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. 

When to use Redis vs. MongoDB

For temporary data storage with rapid querying, use Redis. For long-term persistent storage of complex data with rich querying, use MongoDB. 

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.

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.

Can you use Redis and MongoDB together?

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.

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.

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. 

Summary of differences: Redis vs. MongoDB

 

Redis

MongoDB

Data model

Key-value based in memory data store.

Persistent document database.

Scaling

Redis doesn’t offer as much scalability.

A MongoDB database is highly scalable through horizontal scaling, sharding, and partitioning data.

Availability

You need a separate component called Redis Sentinel to monitor clusters for automatic failover.

Automatic failover by default.

Integrity

Redis offers commands to create single atomic operations. Rollback must be managed in application code.

MongoDB has built-in support for multi-document ACID transactions and rollback.

Query language

Redis uses commands for querying.

MongoDB uses MongoDB Query Language (MQL) to query and manipulate data.

How can AWS help with your Redis and MongoDB requirements?

Amazon Web Services (AWS) has many offerings to support your work with Redis and MongoDB.

Amazon MemoryDB is a Redis-compatible, durable, in-memory database service that delivers ultra-fast performance. It’s purpose-built for modern applications created with microservices architectures. MemoryDB stores data durably across multiple Availability Zones (AZs) using a Multi-AZ transactional log to enable fast failover, database recovery, and node restarts. You can achieve microsecond read and single-digit millisecond write latency alongside high throughput. 

Amazon ElastiCache is a fully managed caching service that makes it easy to set up, operate, and scale a cache in the cloud. With ElastiCache, you can accelerate application speed and unlock microsecond read and write latency by caching data from primary databases and data stores.

Amazon DocumentDB (with MongoDB compatibility) is a fully managed native JSON document database that scales enterprise workloads effortlessly. With the ability to store, query, index, and aggregate data in a flexible JSON format, you can develop and evolve applications faster than ever. A managed database eliminates the need for you to perform manual database management tasks, which increases productivity and streamlines development.

Get started with Redis and MongoDB on AWS by creating an account today.

Next Steps with AWS

Start building with Redis

Learn how to get started with Redis on AWS

Learn more 
Start building with MongoDB

Learn how to get started with MongoDB on AWS

Learn more 

Ending Support for Internet Explorer

Got it
AWS support for Internet Explorer ends on 07/31/2022. Supported browsers are Chrome, Firefox, Edge, and Safari. Learn more »