0% found this document useful (0 votes)
52 views

MongoDB's Performance Over RDBMS - MongoDB

This document summarizes how MongoDB provides superior performance compared to relational database management systems (RDBMS). It discusses three main factors: 1) MongoDB's embedded data model avoids expensive joins and allows for more efficient storage and retrieval of complex data, 2) Its WiredTiger storage engine provides advanced caching and configurable compression to optimize memory usage and storage efficiency, and 3) MongoDB offers advanced indexing capabilities like compound, multikey, and text indexes that enable fast retrieval of data. Overall, MongoDB is designed and optimized to handle complex, nested data structures faster than traditional RDBMS systems.

Uploaded by

Tagore u
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

MongoDB's Performance Over RDBMS - MongoDB

This document summarizes how MongoDB provides superior performance compared to relational database management systems (RDBMS). It discusses three main factors: 1) MongoDB's embedded data model avoids expensive joins and allows for more efficient storage and retrieval of complex data, 2) Its WiredTiger storage engine provides advanced caching and configurable compression to optimize memory usage and storage efficiency, and 3) MongoDB offers advanced indexing capabilities like compound, multikey, and text indexes that enable fast retrieval of data. Overall, MongoDB is designed and optimized to handle complex, nested data structures faster than traditional RDBMS systems.

Uploaded by

Tagore u
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

MongoDB Developer

MONGODB DEVELOPER CENTER DEVELOPER TOPICS

PRODUCTS MONGODB ARTICLES

MongoDB's Performance over


RDBMS
Srinivas Mutyala GUEST CONTRIBUTOR

6 min read • Published Feb 14, 2024 • Updated Feb 14, 2024

MongoDB

Rate this article

Someone somewhere might be wondering why we get superior

https://www.mongodb.com/developer/products/mongodb/mongodb-performance-over-rdbms/ 14/02/24, 7 02 PM
Page 1 of 15
:
Someone somewhere might be wondering why we get superior
performance with MongoDB over RDBMS databases. What is the
secret behind it? I too had this question until I learned about the
internal workings of MongoDB, especially data modeling, advanced
index methods, and Mnally, how the WiredTiger storage engine works.

I wanted to share my learnings and experiences to reveal the secret of


it so that it might be helpful to you, too.

Data modeling: embedded structure (no


JOINs)
MongoDB uses a document-oriented data model, storing data in
JSON-like BSON documents. This allows for eScient storage and
retrieval of complex data structures.

MongoDB's model can lead to simpler and more performant queries


compared to the normalization requirements of RDBMS.

The initial phase of enhancing performance involves comprehending


the query behaviors of your application. This understanding enables
you to tailor your data model and choose suitable indexes to align

https://www.mongodb.com/developer/products/mongodb/mongodb-performance-over-rdbms/ 14/02/24, 7 02 PM
Page 2 of 15
:
with these paVerns eWectively.

Always remember MongoDB's optimized document size (which is 16


MB) so you can avoid embedding images, audio, and video Mles in the
same collection, as depicted in the image below.

Customizing your data model to match the query paVerns of your


application leads to streamlined queries, heightened throughput for
insert and update operations, and beVer workload distribution across
a sharded cluster.

While MongoDB oWers a \exible schema, overlooking schema design


is not advisable. Although you can adjust your schema as needed,
adhering to schema design best practices from the outset of your
project can prevent the need for extensive refactoring down the line.

A major advantage of BSON documents is that you have the \exibility


to model your data any way your application needs. The inclusion of
arrays and subdocuments within documents provides signiMcant
versatility in modeling intricate data relationships. But you can also

https://www.mongodb.com/developer/products/mongodb/mongodb-performance-over-rdbms/ 14/02/24, 7 02 PM
Page 3 of 15
:
model \at, tabular, and columnar structures, simple key-value pairs,
text, geospatial and time-series data, or the nodes and edges of
connected graph data structures. The ideal schema design for your
application will depend on its speciMc query paVerns.

How is embedding within collections in MongoDB


diWerent from storing in multiple tables in RDBMS?
An example of a best practice for an address/contact book involves
separating groups and portraits information in a diWerent collection
because as they can go big due to n-n relations and image size,
respectively. They may hit a 16 MB optimized document size.

https://www.mongodb.com/developer/products/mongodb/mongodb-performance-over-rdbms/ 14/02/24, 7 02 PM
Page 4 of 15
:
Embedding data in a single collection in MongoDB (or minimizing the
number of collections, at least) versus storing in multiple tables in
RDBMS oWers huge performance improvements due to the data
locality which will reduce the data seeks, as shown in the picture
below.

https://www.mongodb.com/developer/products/mongodb/mongodb-performance-over-rdbms/ 14/02/24, 7 02 PM
Page 5 of 15
:
Data locality is the major reason why MongoDB data seeks are faster.

Di=erence: tabular vs document

Tabular MongoDB

Steps to 1 - deMne schema. 2 - 1 - identifying the


create the develop app and queries queries 2- deMne
model schema

Initial schema 3rd normal form. One Many possible solutions


possible solution

Final schema Likely denormalized Few changes

Schema DiScult and not optimal. Easy. No downtime


evolution Likely downtime

Performance Mediocre Optimized

https://www.mongodb.com/developer/products/mongodb/mongodb-performance-over-rdbms/ 14/02/24, 7 02 PM
Page 6 of 15
:
WiredTiger’s cache and compression
WiredTiger is an open-source, high-performance storage engine for
MongoDB. WiredTiger provides features such as document-level
concurrency control, compression, and support for both in-memory
and on-disk storage.

Cache:

WiredTiger cache architecture: WiredTiger utilizes a sophisticated


caching mechanism to eSciently manage data in memory. The cache
is used to store frequently accessed data, reducing the need to read
from disk and improving overall performance.

Memory management: The cache dynamically manages memory


usage based on the workload. It employs techniques such as eviction
(removing less frequently used data from the cache) and promotion
(moving frequently used data to the cache) to optimize memory
utilization.

ConMguration: WiredTiger allows users to conMgure the size of the


cache based on their system's available memory and workload
characteristics. Properly sizing the cache is crucial for achieving
optimal performance.

Durability: WiredTiger ensures durability by \ushing modiMed data


from the cache to disk. This process helps maintain data consistency
in case of a system failure.

Compression
Compression:

https://www.mongodb.com/developer/products/mongodb/mongodb-performance-over-rdbms/ 14/02/24, 7 02 PM
Page 7 of 15
:
Data compression: WiredTiger supports data compression to reduce
the amount of storage space required. Compressing data can lead to
signiMcant disk space savings and improved I/O performance.

ConMgurable compression: Users can conMgure compression options


based on their requirements. WiredTiger supports diWerent
compression algorithms, allowing users to choose the one that best
suits their workload and performance goals.

Trade-oWs: While compression reduces storage costs and can improve


read/write performance, it may introduce additional CPU overhead
during compression and decompression processes. Users need to
carefully consider the trade-oWs and select compression seVings that
align with their application's needs.

Compatibility: WiredTiger's compression features are transparent to


applications and don't require any changes to the application code.
The engine handles compression and decompression internally.

Overall, WiredTiger's cache and compression features contribute to


its eSciency and performance characteristics. By optimizing memory
usage and providing conMgurable compression options, WiredTiger
aims to meet the diverse needs of MongoDB users in terms of both
speed and storage eSciency.

Few RDBMS systems also employ caching, but the performance


beneMts may vary based on the database system and conMguration.

Advanced indexing capabilities

https://www.mongodb.com/developer/products/mongodb/mongodb-performance-over-rdbms/ 14/02/24, 7 02 PM
Page 8 of 15
:
MongoDB, being a NoSQL database, oWers advanced indexing
capabilities to optimize query performance and support eScient data
retrieval. Here are some of MongoDB's advanced indexing features:

Compound indexes

MongoDB allows you to create compound indexes on multiple Melds. A


compound index is an index on multiple Melds in a speciMc order. This
can be useful for queries that involve multiple criteria.

The order of Melds in a compound index is crucial. MongoDB can use


the index eSciently for queries that match the index Melds from lee to
right.

Multikey indexes

MongoDB supports indexing on arrays. When you index an array Meld,


MongoDB creates separate index entries for each element of the
array.

Multikey indexes are helpful when working with documents that


contain arrays, and you need to query based on elements within those
arrays.

Text indexes

MongoDB provides text indexes to support full-text search. Text


indexes tokenize and stem words, allowing for more \exible and
language-aware text searches.

Text indexes are suitable for scenarios where users need to perform

https://www.mongodb.com/developer/products/mongodb/mongodb-performance-over-rdbms/ 14/02/24, 7 02 PM
Page 9 of 15
:
text search operations on large amounts of textual data.

Geospatial indexes

MongoDB supports geospatial indexes to optimize queries that


involve geospatial data. These indexes can eSciently handle queries
related to location-based information.

Geospatial indexes support 2D and 3D indexing, allowing for the


representation of both \at and spherical geometries.

Wildcard indexes

MongoDB supports wildcard indexes, enabling you to create indexes


that cover only a subset of Melds in a document. This can be useful
when you have speciMc query paVerns and want to optimize for those
paVerns without indexing every Meld.

Partial indexes

Partial indexes allow you to index only the documents that satisfy a
speciMed Mlter expression. This can be beneMcial when you have a
large collection but want to create an index for a subset of documents
that meet speciMc criteria.

Hashed indexes

Hashed indexes are useful for sharding scenarios. MongoDB


automatically hashes the indexed Meld's values and distributes the
data across the shards, providing a more even distribution of data
and queries.

https://www.mongodb.com/developer/products/mongodb/mongodb-performance-over-rdbms/ 14/02/24, 7 02 PM
Page 10 of 15
:
TTL (time-to-live) indexes

TTL indexes allow you to automatically expire documents from a


collection aeer a certain amount of time. This is helpful for managing
data that has a natural expiration, such as session information or log
entries.

These advanced indexing capabilities in MongoDB provide developers


with powerful tools to optimize query performance for a wide range of
scenarios and data structures. Properly leveraging these features can
signiMcantly enhance the eSciency and responsiveness of MongoDB
databases.

In conclusion, the superior performance of MongoDB over traditional

https://www.mongodb.com/developer/products/mongodb/mongodb-performance-over-rdbms/ 14/02/24, 7 02 PM
Page 11 of 15
:
RDBMS databases stems from its adept handling of data modeling,
advanced indexing methods, and the eSciency of the WiredTiger
storage engine. By tailoring your data model to match application
query paVerns, leveraging MongoDB's optimized document structure,
and harnessing advanced indexing capabilities, you can achieve
enhanced throughput and more eWective workload distribution.

Remember, while MongoDB oWers \exibility in schema design, it's


crucial not to overlook the importance of schema design best
practices from the outset of your project. This proactive approach
can save you from potential refactoring eWorts down the line.

For further exploration and discussion on MongoDB and database


optimization strategies, consider joining our Developer Community.
There, you can engage with fellow developers, share insights, and stay
updated on the latest developments in database technology.

Keep optimizing and innovating with MongoDB to unlock the full


potential of your applications.

Rate this article

Related

TUTORIAL

Install & ConMgure MongoDB on the Raspberry Pi

https://www.mongodb.com/developer/products/mongodb/mongodb-performance-over-rdbms/ 14/02/24, 7 02 PM
Page 12 of 15
:

You might also like