SlideShare ist ein Scribd-Unternehmen logo
1 von 53
Downloaden Sie, um offline zu lesen
Charles Sarrazin, MongoDB
Raiders of the Anti-Patterns:
A journey towards fixing schema mistakes in MongoDB
@csarrazi
Charles Sarrazin
Principal Consulting Engineer, Professional Services, Paris, FR
Our Journey
§ Packing
§ Anti-Patterns
§ Fixing schema issues
gracefully
§ Conclusion
Packing
Our backpack
§ Design Patterns
§ Monitoring tools
§ Log analysis
§ Additional tools
Design Patterns
Representation
§ Attribute
§ Schema Versioning
§ Document Versioning
§ Tree
§ Polymorphism
§ Pre-allocation
Access Frequency
§ Subset
§ Approximation
§ Extended Reference
Grouping
§ Computed
§ Bucket
§ Outlier
https://www.mongodb.com/blog/post/building-with-patterns-a-summary
Data Modeling
Patterns
Use Cases
https://university.mongodb.com/courses/M320/about
Monitoring tools
For example
• Ops/Cloud Manager
• MongoDB Compass
Log Analysis
mtools
• mlogfilter
• mloginfo
• mplotqueries
https://github.com/rueckstiess/mtools
Additional tools
• Oplog analysis
• db.currentOp()
• Profiler
• db.collection.explain()
Anti-Patterns
Understanding your data model and identifying
mistakes
The Fauna
a.k.a « One Collection Fits All »
or « Schemaless »
The Squashed Database
Symptoms
§ Slow writes
§ High number of indexes (>20-25)
The Fauna
The Anti-Pattern
§ Access patterns are actually
different based on document type
§ Each document type depends on a
specific index
§ No common access patterns
The Actual Reason
§ While indexes improve reads, they
might negatively impact writes
§ You may only have up to 64
indexes in a single collection
§ If you don’t use Partial or Sparse
indexes, null or absent values will
still be indexed
The Fauna
Takeaways
§ Documents sharing different access pattern or business logic
should be stored in separate collections
§ You can temporarily rely on Partial Indexes in order to reduce the
size of indexes and performance impact
§ Spending a just a little time for schema design is important
The Squashed
Database
a.k.a « Flat documents » or
« The RDBMS schema »
The Squashed Database
Symptoms
§ High IOPS (random reads/writes)
§ Low throughput
§ High yields and/or nReturned
§ High index size
The Squashed Database
The Anti-Pattern
§ Flat documents stored in separate
collections
§ Only using root-level fields and no
hierarchy
The Actual Reason
§ In order to parse a flat document,
MongoDB will read each field
sequentially
§ Normalization also means
redundant data (relations)
§ Data needs to be consolidated
using JOINs ($lookup)
The Squashed Database
Takeaways
§ Simply transposing your data model from a RDBMS to MongoDB
won’t be as helpful for scaling up
§ Consider grouping data from multiple tables in a single collection,
by embedding the relations (1:1, 1:n) when data volume is
reasonable
$project the Elephant
a.k.a. « Bloated documents » or
« The $project »
$project the Elephant
Symptoms
§ High read IOPS
§ High cache activity (bytes read into cache)
§ High number of yields when reading a single document
§ Slow indexed queries when reading a single document
§ Result length lower than document size
§ Generally, big document size (> 200+ KB)
$project the Elephant
The Anti-Pattern
§ Using big document (>100kb)
while only projecting a few fields
The Actual Reason
§ Documents are the base level
transfer unit from disk to memory
§ Even when using a single field, the
whole document is loaded from
disk to the WiredTiger cache
$project the Elephant
Takeaways
§ Use smaller documents with more
frequently accessed data
§ Store less frequently accessed data
in another collection
Also known as the Subset Pattern
https://www.mongodb.com/blog/post/building-with-patterns-the-subset-pattern
The Single-Person
Bridge
a.k.a. « The Auto-Incrementing
Counter » or « SQL in
MongoDB »
The Single-Person Bridge
Symptoms
§ Some updates seem to take a long time
§ MongoDB logs show writeConflicts>0 for these updates
§ The application seems to perform write operations sequentially
The Single-Person Bridge
The Anti-Pattern
§ Simulating a SQL sequence by
using a counter document and
findOneAndModify
The Actual Reason
§ As WiredTiger uses a document-
level lock, concurrent updates to a
single document will block other
writes to the same document
The Single-Person Bridge
Takeaways
§ Do not try to simulate sequences in MongoDB
§ Instead, rely on ObjectIDs, UUIDs or GUIDs
Sorted Monkeys
a.k.a. « Sorted Array Push »
Sorted Monkeys
Symptoms
§ Very high Oplog churn (Oplog GB/Hour)
§ Low Oplog window with default Oplog size
§ Oplog size is very high compared to data size to ensure proper
operations (target Oplog window > 3 days)
Sorted Monkeys
The Anti-Pattern
§ Using $push on big arrays (>20
entries) with:
§ The $sort modifier
§ The $slice modifier
The Actual Reason
§ Oplog operations are idempotent,
meaning that these operations are
replaced with a $set statement,
replacing the full array.
Sorted Monkeys
Takeaways
§ Only rely on the $slice and $sort modifiers when manipulating
small arrays
§ You can rely on in-memory or application-level sorts for medium-
sized result sets
The Tree in the House
a.k.a. « Push until the End »
The Tree in the House
Symptoms
§ Your application worked fine for some period of time
§ After a while, some updates fail with:
Resulting document after update is larger than 16777216
The Tree in the House
The Anti-Pattern
§ Using unbounded arrays for
storing data (e.g. Audit logs for
tracing document updates)
The Actual Reason
§ MongoDB documents are limited
to 16MB
§ Depending on relationship, you
might reach maximum document
size if not careful
The Tree in the House
Takeaways
§ For 1:n relationships, you need to
consider cardinality
§ Differentiate 1 to few (<10k array
elements) from 1 to zillions
§ Consider using the Subset, Outlier
or Bucket patterns
Fixing schema
issues gracefully
Considerations
§ Availability
§ Can your business afford scheduled downtime?
§ Do you need to keep multiple versions of your app online?
§ Performance
§ How does the migration affect performance?
§ Rollback Strategy
§ How do we go back if we run into a problem?
§ Risk
§ What is the impact of a failed migration?
Migration Strategies
§ One-Time
§ Blue/Green
§ Y-Write
§ Read & Upgrade
One-Time
Principles Pros
§ Fastest migration path
§ Immediate economies of
scales
Cons
§ High risk
§ Requires tremendous
coordination
§ Complex parallel testing
§ Labor intensive
YOLO!
Blue/Green
Principles Pros
§ Always available
§ Easy rollback: change
router to point to
previous version
Cons
§ You need to be able to
sync the two DBs
§ Use ChangeStreams
§ You need double the
hardware or resources
Y-Write
Principles Pros
§ Always available
§ Easy rollback: stop
writing to new schema
§ Legacy applications can
still read from the old
schema
Cons
§ You need to be able to
sync the two DBs
§ Write logic needs to be
centralized and migrated
before read logic
Read & Upgrade
Principles Pros
§ Always available
§ Good performance
Cons
§ You need to consider
schema backward and
forward compatibility
§ Schema upgrade is part
of the application logic
§ Requires a depreciation
roadmap to remove
legacy code
Ensuring backward compatibility
Do
§ Insert data in existing collections
§ Add new field
§ Create a new collection/database
Don’t
§ Rename/Remove field
§ Remove data
§ Change field type or format
§ Remove/Rename
collection/database
Summary
Availability Performance Risk Cost
One Time ✗✗ ✓ ✗✗ ✓✓
Blue/Green ✓ ✗ ✓✓ ✗✗
Y-Write ✓✓ ✓ ✓✓ ✓✓
Read &
Upgrade
✓ ✓✓ ✗ ✓
Conclusion
Key takeaways
Regularly reassess your hypotheses
§ Your access patterns will change over time
§ Check your actual access patterns
Key takeaways
MongoDB provides flexible migration options
§ You can combine both online and offline schema migrations
§ Consider your development lifecycle and your release schedule to
choose your migration strategy
§ Use $jsonSchema to handle schema validation or check migration
status
But more importantly…
…Take some time to think
about your data model!
Questions?
Thank you for taking our FREE
MongoDB classes at
university.mongodb.com
Register Now!
https://university.mongodb.com/courses/M320/about
MongoDB World 2019: Raiders of the Anti-patterns: A Journey Towards Fixing Schema Mistakes in MongoDB

Weitere ähnliche Inhalte

Was ist angesagt?

MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentationHyphen Call
 
MongoDB Schema Design
MongoDB Schema DesignMongoDB Schema Design
MongoDB Schema DesignMongoDB
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Kai Zhao
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBNodeXperts
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBLee Theobald
 
Introduction to Sharding
Introduction to ShardingIntroduction to Sharding
Introduction to ShardingMongoDB
 
MongoDB Sharding
MongoDB ShardingMongoDB Sharding
MongoDB ShardingRob Walters
 
Deep Dive Into Elasticsearch
Deep Dive Into ElasticsearchDeep Dive Into Elasticsearch
Deep Dive Into ElasticsearchKnoldus Inc.
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architectureBishal Khanal
 
Writing Scalable Software in Java
Writing Scalable Software in JavaWriting Scalable Software in Java
Writing Scalable Software in JavaRuben Badaró
 
Faceted Search with Lucene
Faceted Search with LuceneFaceted Search with Lucene
Faceted Search with Lucenelucenerevolution
 

Was ist angesagt? (20)

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
 
MongoDB Schema Design
MongoDB Schema DesignMongoDB Schema Design
MongoDB Schema Design
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Angular
AngularAngular
Angular
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Json
JsonJson
Json
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDB
 
Introduction to Sharding
Introduction to ShardingIntroduction to Sharding
Introduction to Sharding
 
Json
JsonJson
Json
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
 
MongoDB Sharding
MongoDB ShardingMongoDB Sharding
MongoDB Sharding
 
Mongo db intro.pptx
Mongo db intro.pptxMongo db intro.pptx
Mongo db intro.pptx
 
Introduction To Apache Lucene
Introduction To Apache LuceneIntroduction To Apache Lucene
Introduction To Apache Lucene
 
Deep Dive Into Elasticsearch
Deep Dive Into ElasticsearchDeep Dive Into Elasticsearch
Deep Dive Into Elasticsearch
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
 
Writing Scalable Software in Java
Writing Scalable Software in JavaWriting Scalable Software in Java
Writing Scalable Software in Java
 
Faceted Search with Lucene
Faceted Search with LuceneFaceted Search with Lucene
Faceted Search with Lucene
 

Ähnlich wie MongoDB World 2019: Raiders of the Anti-patterns: A Journey Towards Fixing Schema Mistakes in MongoDB

MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...
MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...
MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...MongoDB
 
Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)Don Demcsak
 
MongoDB: How We Did It – Reanimating Identity at AOL
MongoDB: How We Did It – Reanimating Identity at AOLMongoDB: How We Did It – Reanimating Identity at AOL
MongoDB: How We Did It – Reanimating Identity at AOLMongoDB
 
Solving Your Backup Needs Using MongoDB Ops Manager, Cloud Manager and Atlas
Solving Your Backup Needs Using MongoDB Ops Manager, Cloud Manager and AtlasSolving Your Backup Needs Using MongoDB Ops Manager, Cloud Manager and Atlas
Solving Your Backup Needs Using MongoDB Ops Manager, Cloud Manager and AtlasMongoDB
 
Front Range PHP NoSQL Databases
Front Range PHP NoSQL DatabasesFront Range PHP NoSQL Databases
Front Range PHP NoSQL DatabasesJon Meredith
 
Introduction to NoSql
Introduction to NoSqlIntroduction to NoSql
Introduction to NoSqlOmid Vahdaty
 
MongoDB.local Austin 2018: Solving Your Backup Needs Using MongoDB Ops Manage...
MongoDB.local Austin 2018: Solving Your Backup Needs Using MongoDB Ops Manage...MongoDB.local Austin 2018: Solving Your Backup Needs Using MongoDB Ops Manage...
MongoDB.local Austin 2018: Solving Your Backup Needs Using MongoDB Ops Manage...MongoDB
 
MongoDB.local DC 2018: Solving Your Backup Needs Using MongoDB Ops Manager, C...
MongoDB.local DC 2018: Solving Your Backup Needs Using MongoDB Ops Manager, C...MongoDB.local DC 2018: Solving Your Backup Needs Using MongoDB Ops Manager, C...
MongoDB.local DC 2018: Solving Your Backup Needs Using MongoDB Ops Manager, C...MongoDB
 
The Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterThe Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterChris Henry
 
Lessons Learned Migrating 2+ Billion Documents at Craigslist
Lessons Learned Migrating 2+ Billion Documents at CraigslistLessons Learned Migrating 2+ Billion Documents at Craigslist
Lessons Learned Migrating 2+ Billion Documents at CraigslistJeremy Zawodny
 
Webinar: Enterprise Data Management in the Era of MongoDB and Data Lakes
Webinar: Enterprise Data Management in the Era of MongoDB and Data LakesWebinar: Enterprise Data Management in the Era of MongoDB and Data Lakes
Webinar: Enterprise Data Management in the Era of MongoDB and Data LakesMongoDB
 
Non Relational Databases
Non Relational DatabasesNon Relational Databases
Non Relational DatabasesChris Baglieri
 
MongoDB Aggregation Performance
MongoDB Aggregation PerformanceMongoDB Aggregation Performance
MongoDB Aggregation PerformanceMongoDB
 
Storage Systems for High Scalable Systems Presentation
Storage Systems for High Scalable Systems PresentationStorage Systems for High Scalable Systems Presentation
Storage Systems for High Scalable Systems Presentationandyman3000
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodbMohammed Ragab
 
Scaling a SaaS backend with PostgreSQL - A case study
Scaling a SaaS backend with PostgreSQL - A case studyScaling a SaaS backend with PostgreSQL - A case study
Scaling a SaaS backend with PostgreSQL - A case studyOliver Seemann
 
2010 mongo berlin-scaling
2010 mongo berlin-scaling2010 mongo berlin-scaling
2010 mongo berlin-scalingMongoDB
 
MongoDB Internals
MongoDB InternalsMongoDB Internals
MongoDB InternalsSiraj Memon
 

Ähnlich wie MongoDB World 2019: Raiders of the Anti-patterns: A Journey Towards Fixing Schema Mistakes in MongoDB (20)

MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...
MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...
MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...
 
MongoDB
MongoDBMongoDB
MongoDB
 
Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)
 
MongoDB: How We Did It – Reanimating Identity at AOL
MongoDB: How We Did It – Reanimating Identity at AOLMongoDB: How We Did It – Reanimating Identity at AOL
MongoDB: How We Did It – Reanimating Identity at AOL
 
Solving Your Backup Needs Using MongoDB Ops Manager, Cloud Manager and Atlas
Solving Your Backup Needs Using MongoDB Ops Manager, Cloud Manager and AtlasSolving Your Backup Needs Using MongoDB Ops Manager, Cloud Manager and Atlas
Solving Your Backup Needs Using MongoDB Ops Manager, Cloud Manager and Atlas
 
Front Range PHP NoSQL Databases
Front Range PHP NoSQL DatabasesFront Range PHP NoSQL Databases
Front Range PHP NoSQL Databases
 
Introduction to NoSql
Introduction to NoSqlIntroduction to NoSql
Introduction to NoSql
 
MongoDB.local Austin 2018: Solving Your Backup Needs Using MongoDB Ops Manage...
MongoDB.local Austin 2018: Solving Your Backup Needs Using MongoDB Ops Manage...MongoDB.local Austin 2018: Solving Your Backup Needs Using MongoDB Ops Manage...
MongoDB.local Austin 2018: Solving Your Backup Needs Using MongoDB Ops Manage...
 
MongoDB.local DC 2018: Solving Your Backup Needs Using MongoDB Ops Manager, C...
MongoDB.local DC 2018: Solving Your Backup Needs Using MongoDB Ops Manager, C...MongoDB.local DC 2018: Solving Your Backup Needs Using MongoDB Ops Manager, C...
MongoDB.local DC 2018: Solving Your Backup Needs Using MongoDB Ops Manager, C...
 
The Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterThe Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb Cluster
 
Lessons Learned Migrating 2+ Billion Documents at Craigslist
Lessons Learned Migrating 2+ Billion Documents at CraigslistLessons Learned Migrating 2+ Billion Documents at Craigslist
Lessons Learned Migrating 2+ Billion Documents at Craigslist
 
Webinar: Enterprise Data Management in the Era of MongoDB and Data Lakes
Webinar: Enterprise Data Management in the Era of MongoDB and Data LakesWebinar: Enterprise Data Management in the Era of MongoDB and Data Lakes
Webinar: Enterprise Data Management in the Era of MongoDB and Data Lakes
 
Non Relational Databases
Non Relational DatabasesNon Relational Databases
Non Relational Databases
 
MongoDB Aggregation Performance
MongoDB Aggregation PerformanceMongoDB Aggregation Performance
MongoDB Aggregation Performance
 
Storage Systems for High Scalable Systems Presentation
Storage Systems for High Scalable Systems PresentationStorage Systems for High Scalable Systems Presentation
Storage Systems for High Scalable Systems Presentation
 
NoSQL and MongoDB
NoSQL and MongoDBNoSQL and MongoDB
NoSQL and MongoDB
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
 
Scaling a SaaS backend with PostgreSQL - A case study
Scaling a SaaS backend with PostgreSQL - A case studyScaling a SaaS backend with PostgreSQL - A case study
Scaling a SaaS backend with PostgreSQL - A case study
 
2010 mongo berlin-scaling
2010 mongo berlin-scaling2010 mongo berlin-scaling
2010 mongo berlin-scaling
 
MongoDB Internals
MongoDB InternalsMongoDB Internals
MongoDB Internals
 

Mehr von MongoDB

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump StartMongoDB
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB
 

Mehr von MongoDB (20)

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
 

Kürzlich hochgeladen

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Kürzlich hochgeladen (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

MongoDB World 2019: Raiders of the Anti-patterns: A Journey Towards Fixing Schema Mistakes in MongoDB

  • 1. Charles Sarrazin, MongoDB Raiders of the Anti-Patterns: A journey towards fixing schema mistakes in MongoDB @csarrazi
  • 2. Charles Sarrazin Principal Consulting Engineer, Professional Services, Paris, FR
  • 3. Our Journey § Packing § Anti-Patterns § Fixing schema issues gracefully § Conclusion
  • 5. Our backpack § Design Patterns § Monitoring tools § Log analysis § Additional tools
  • 6. Design Patterns Representation § Attribute § Schema Versioning § Document Versioning § Tree § Polymorphism § Pre-allocation Access Frequency § Subset § Approximation § Extended Reference Grouping § Computed § Bucket § Outlier https://www.mongodb.com/blog/post/building-with-patterns-a-summary
  • 8. Monitoring tools For example • Ops/Cloud Manager • MongoDB Compass
  • 9. Log Analysis mtools • mlogfilter • mloginfo • mplotqueries https://github.com/rueckstiess/mtools
  • 10. Additional tools • Oplog analysis • db.currentOp() • Profiler • db.collection.explain()
  • 11. Anti-Patterns Understanding your data model and identifying mistakes
  • 12. The Fauna a.k.a « One Collection Fits All » or « Schemaless »
  • 13. The Squashed Database Symptoms § Slow writes § High number of indexes (>20-25)
  • 14. The Fauna The Anti-Pattern § Access patterns are actually different based on document type § Each document type depends on a specific index § No common access patterns The Actual Reason § While indexes improve reads, they might negatively impact writes § You may only have up to 64 indexes in a single collection § If you don’t use Partial or Sparse indexes, null or absent values will still be indexed
  • 15. The Fauna Takeaways § Documents sharing different access pattern or business logic should be stored in separate collections § You can temporarily rely on Partial Indexes in order to reduce the size of indexes and performance impact § Spending a just a little time for schema design is important
  • 16. The Squashed Database a.k.a « Flat documents » or « The RDBMS schema »
  • 17. The Squashed Database Symptoms § High IOPS (random reads/writes) § Low throughput § High yields and/or nReturned § High index size
  • 18. The Squashed Database The Anti-Pattern § Flat documents stored in separate collections § Only using root-level fields and no hierarchy The Actual Reason § In order to parse a flat document, MongoDB will read each field sequentially § Normalization also means redundant data (relations) § Data needs to be consolidated using JOINs ($lookup)
  • 19. The Squashed Database Takeaways § Simply transposing your data model from a RDBMS to MongoDB won’t be as helpful for scaling up § Consider grouping data from multiple tables in a single collection, by embedding the relations (1:1, 1:n) when data volume is reasonable
  • 20. $project the Elephant a.k.a. « Bloated documents » or « The $project »
  • 21. $project the Elephant Symptoms § High read IOPS § High cache activity (bytes read into cache) § High number of yields when reading a single document § Slow indexed queries when reading a single document § Result length lower than document size § Generally, big document size (> 200+ KB)
  • 22. $project the Elephant The Anti-Pattern § Using big document (>100kb) while only projecting a few fields The Actual Reason § Documents are the base level transfer unit from disk to memory § Even when using a single field, the whole document is loaded from disk to the WiredTiger cache
  • 23. $project the Elephant Takeaways § Use smaller documents with more frequently accessed data § Store less frequently accessed data in another collection Also known as the Subset Pattern https://www.mongodb.com/blog/post/building-with-patterns-the-subset-pattern
  • 24. The Single-Person Bridge a.k.a. « The Auto-Incrementing Counter » or « SQL in MongoDB »
  • 25. The Single-Person Bridge Symptoms § Some updates seem to take a long time § MongoDB logs show writeConflicts>0 for these updates § The application seems to perform write operations sequentially
  • 26. The Single-Person Bridge The Anti-Pattern § Simulating a SQL sequence by using a counter document and findOneAndModify The Actual Reason § As WiredTiger uses a document- level lock, concurrent updates to a single document will block other writes to the same document
  • 27. The Single-Person Bridge Takeaways § Do not try to simulate sequences in MongoDB § Instead, rely on ObjectIDs, UUIDs or GUIDs
  • 28. Sorted Monkeys a.k.a. « Sorted Array Push »
  • 29. Sorted Monkeys Symptoms § Very high Oplog churn (Oplog GB/Hour) § Low Oplog window with default Oplog size § Oplog size is very high compared to data size to ensure proper operations (target Oplog window > 3 days)
  • 30. Sorted Monkeys The Anti-Pattern § Using $push on big arrays (>20 entries) with: § The $sort modifier § The $slice modifier The Actual Reason § Oplog operations are idempotent, meaning that these operations are replaced with a $set statement, replacing the full array.
  • 31. Sorted Monkeys Takeaways § Only rely on the $slice and $sort modifiers when manipulating small arrays § You can rely on in-memory or application-level sorts for medium- sized result sets
  • 32. The Tree in the House a.k.a. « Push until the End »
  • 33. The Tree in the House Symptoms § Your application worked fine for some period of time § After a while, some updates fail with: Resulting document after update is larger than 16777216
  • 34. The Tree in the House The Anti-Pattern § Using unbounded arrays for storing data (e.g. Audit logs for tracing document updates) The Actual Reason § MongoDB documents are limited to 16MB § Depending on relationship, you might reach maximum document size if not careful
  • 35. The Tree in the House Takeaways § For 1:n relationships, you need to consider cardinality § Differentiate 1 to few (<10k array elements) from 1 to zillions § Consider using the Subset, Outlier or Bucket patterns
  • 37. Considerations § Availability § Can your business afford scheduled downtime? § Do you need to keep multiple versions of your app online? § Performance § How does the migration affect performance? § Rollback Strategy § How do we go back if we run into a problem? § Risk § What is the impact of a failed migration?
  • 38. Migration Strategies § One-Time § Blue/Green § Y-Write § Read & Upgrade
  • 39. One-Time Principles Pros § Fastest migration path § Immediate economies of scales Cons § High risk § Requires tremendous coordination § Complex parallel testing § Labor intensive YOLO!
  • 40. Blue/Green Principles Pros § Always available § Easy rollback: change router to point to previous version Cons § You need to be able to sync the two DBs § Use ChangeStreams § You need double the hardware or resources
  • 41. Y-Write Principles Pros § Always available § Easy rollback: stop writing to new schema § Legacy applications can still read from the old schema Cons § You need to be able to sync the two DBs § Write logic needs to be centralized and migrated before read logic
  • 42. Read & Upgrade Principles Pros § Always available § Good performance Cons § You need to consider schema backward and forward compatibility § Schema upgrade is part of the application logic § Requires a depreciation roadmap to remove legacy code
  • 43. Ensuring backward compatibility Do § Insert data in existing collections § Add new field § Create a new collection/database Don’t § Rename/Remove field § Remove data § Change field type or format § Remove/Rename collection/database
  • 44. Summary Availability Performance Risk Cost One Time ✗✗ ✓ ✗✗ ✓✓ Blue/Green ✓ ✗ ✓✓ ✗✗ Y-Write ✓✓ ✓ ✓✓ ✓✓ Read & Upgrade ✓ ✓✓ ✗ ✓
  • 46. Key takeaways Regularly reassess your hypotheses § Your access patterns will change over time § Check your actual access patterns
  • 47. Key takeaways MongoDB provides flexible migration options § You can combine both online and offline schema migrations § Consider your development lifecycle and your release schedule to choose your migration strategy § Use $jsonSchema to handle schema validation or check migration status
  • 49. …Take some time to think about your data model!
  • 51. Thank you for taking our FREE MongoDB classes at university.mongodb.com