SlideShare une entreprise Scribd logo
1  sur  33
Télécharger pour lire hors ligne
Evolution of MongoDB Sharding and Its Best Practices
Presenter by
Ranjith A
Database Engineer @ Mydbops
Mydbops 11th Webinar
www.mydbops.com info@mydbops.com
Ranjith A
MongoDB Database Engineer
ranjith@mydbops.com
linkedin.com/in/ranjith-a-70aab0157
About Me
Mydbops at a Glance
● Founded in 2015, HQ in Bangalore India, 70+ Employees.
● Mydbops is on Database Consulting with core specialization on MySQL, MongoDB and PostgreSQL
Administration and Support.
● Mydbops was created with a motto of developing a DevOPS model for Database Administration.
● We help organisations to scale in MySQL/Mongodb/postgresql and implement the advanced technologies in
MySQL/Mongodb/PostgreSQL.
Mydbops at a Glance
Happy Customers
4
Agenda
● Intro
● Sharding Overview
● Sharding Architecture
● Types of Sharding
● Things need to be taken care before choosing shard key
● Evolution of sharding from 3.6 to 5.0
● Q/A
Intro
Sharding Overview
● Sharding is a method for distributing data across multiple machines.
● By using MongoDB sharding, We can handle very large data sets and high throughput operations.
● Database systems with large data sets or high throughput applications can challenge the capacity of a single server.
● For example, If our system is a heavy read sensitive it will exhaust the CPU capacity of the server. Working set sizes
larger than the system's RAM stress the I/O capacity of disk drives.
Sharding Overview
We can scale the system in two engineering approach.
Vertical Scaling Horizontal sharding
Achieved by MongoDB replica set / standalone server Achieved by MongoDB Sharding
Data set in Single server Distribute the data set to Multiple servers
Increasing the server capacity of a single server. Adding additional servers to increase capacity as required.
There is a limitation for increasing the server capacity We can easily add or remove additional servers as required.
Sharding Architecture
Sharding Architecture - (Data Shard)
● MongoDB supports horizontal scaling through MongoDB Sharded Cluster.
● MongoDB shards data at the collection level, distributing the collection data across the shards in the cluster.
● MongoDB Sharded Cluster consists of the following components:
1. Shards
2. Mongos
3. Config server
Shard:
● Each shard contains a subset of the sharded data.
● Each shard can be deployed as a replica set.
Sharding Architecture-(Mongos)
Mongos:
● The mongos acts as a query router, providing an interface between client applications and the sharded cluster.
● Applications never connect or communicate directly with the shards.
● The mongos tracks what data is on which shard by caching the metadata from the config servers.
● The mongos uses the metadata to route operations from applications and clients to the mongod instances.
● The mongos receives responses from all shards, it merges the data and returns the result document.
Sharding Architecture-(Config)
Config Server:
● Config servers store metadata and configuration settings for the cluster. As of MongoDB 3.4, config servers must
be deployed as a replica set (CSRS).
● If your cluster has a single config server, then the config server is a single point of failure.
● If the config server is inaccessible, the cluster is not accessible.
● If you cannot recover the data on a config server, the cluster will be inoperable.
● Always use three config servers for production deployments
Types of Sharding-(Hashed Sharding)
MongoDB supports two sharding methods for distributing data across sharded clusters.
● Hashed sharding
● Ranged Sharding
Hashed sharding:
Hashed sharding
● Hashed Sharding involves computing a hash of the shard key field's value. We can use either a single field hashed index
or a compound hashed index (New in 4.4) as the shard key.
● MongoDB automatically computes the hashes when resolving queries using hashed indexes.
● Hashed sharding provides a more even data distribution across the sharded cluster.
● The fields which we chose the hashed shard key should have a good cardinality (more unique values).
● Default _id field is the best example for good cardinality (Objectid values).
Hashed sharding
Command to enable Sharding: (DB Level)
sh.enableSharding("databasename")
Hashed sharding
Command to enable Sharding: (Collection Level)
sh.shardCollection( "databasename.collectionname", { "field" : "hashed" } )
● Make sure before enabling sharding for a particular collection database must be sharded also the Index must be
available for the fields which we are going to use as a shard key.
Ranged sharding
Ranged sharding:
Ranged sharding
● In Range-based sharding, data's are splitted into contiguous ranges determined by the shard key values.
● Data with "close" shard key values are likely to be in the same chunk or shard.
● This will improve the performance of the read queries (target documents) within a contiguous range.
● Poor sharded key selection will affect both read and write performance.
Command to enable Sharding: (Collection Level)
sh.shardCollection( "databasename.collectionname", { "field" : 1 } )
● Make sure before enabling sharding for a particular collection, database must be sharded also the Index must be
available for the fields which we are going to use as a shard key.
Zone sharding
● In sharded clusters, you can create single or multiple zones in single shard as well as multiple shards.
● Zones represent a group of shards and associate one or more ranges of shard key values to that zone.
● Zone ranges are always inclusive of the lower boundary and exclusive of the upper boundary.
● From MongoDB 4.0.2, dropping a collection deletes its associated zone/tag ranges.
● Zones information are stored in config.shards & config.tags collection
● Starting from MongoDB 4.4 brings we can shard a collection and determine zones by compound keys, including
mixing a hashed key with non-hashed keys.
Zone sharding
Command to create Zone:
sh.addShardToZone("shardname", "zonename")
Zone sharding
Command to create Zone range:
sh.updateZoneKeyRange("dbname.collectionname", { fieldname: "minkey" }, { fieldname: "maxkey" },
"zonename")
Sharded key
Shard key is the key to evenly distribute the data among all shards. Good shared key always satisfies the below points.
● High Cardinality
● High Frequency
● Non Monotonically Changing Shard Keys
● Sharding Query patterns
Sharded key
High Cardinality:
● High cardinality shard key - More no. of chunks & evenly distributed data
● Low cardinality shard key - Less no. of chunks & low distributed data
● Each unique shard key value can exist on no more than a single chunk at any given time.
High Frequency:
● High frequency shard key - More evenly distributed data
● Low frequency shard key - Low distributed data
● Shard key cardinality & monotonically changing shard key also contribute to the distribution of the data.
Sharded key
Non Monotonically Changing Shard Keys:-
● monotonically increases or decreases shard key tends to distribute the data to a single chunk within the cluster.
● Each chunk has its own min & Max value.
Evolution of sharding from 3.6 to 5.0
Mongo
version
Modify shard
key field value
Refining
shard key
Change
shard key
New variables New features
3.6 NO NO NO orphanCleanupDelaySecs Shard must be a replica set
All shard members have chunk
metadata
4.2 YES NO NO sh.setBalancerState(true)
sh.setBalancerState(false)
Modify shard key field value except
immutable _id field
4.4 YES YES NO Hedged Reads Refinable shard keys
Hedged Reads
compound shard keys with a hashed
field
Remove multiple shard at a time
Remove shard key size limit
5.0 YES YES YES reshardCollection Change the shard key
Change the name of a sharded
collection
Sharding Features in 3.6
● Shards must be replica sets.
● All members of the shard replica set maintain the metadata regarding chunk metadata. This prevents reads from
the secondaries from returning orphaned data.
● Based on the orphanCleanupDelaySecs (New in 3.6) variable migrated chunk is deleted from the source shard.
● orphanCleanupDelaySecs - Default 900 (15 min)
Set the orphanCleanupDelaySecs value to 20 min during the mongo service start
mongod --setParameter orphanCleanupDelaySecs=1200 (20 min)
setParameter command:
db.adminCommand( { setParameter: 1, orphanCleanupDelaySecs: 1200 } )
Sharding Features in 4.2
● We can update a document's shard key value except the shard key field is the immutable _id field.
● In earlier version we can't change the document's shard key value.
Sharding Features in 4.2
New variables in 4.2:
● sh.startBalancer() - sh.setBalancerState(true) (Enable auto-splitting for the sharded cluster)
● sh.stopBalancer() - sh.setBalancerState(false) (Disable auto-splitting for the sharded cluster)
● sh.enableAutoSplit() - Enable auto-splitting when the balancer is disabled
Sharding Features in 4.4
● Refinable Shard Keys - refine a collection's shard key by adding a suffix field or fields to the existing key
db.employee.createIndex({"employeeid" : 1, "mailid": 1})
db.adminCommand( {refineCollectionShardKey: "mydbops.employee",
key: { "employeeid" : 1, "mailid": 1 }} )
● In 4.4, Shard key field can be missing in a sharded collection.
● In earlier versions, shard key fields must exist in every document for a sharded collection.
● Support Hedged Reads - To minimize latencies
● Support compound shard keys with a hashed field.
● More than one removeShard operation at a time.
● MongoDB removes the 512-byte limit on the shard key size.
Sharding Features in 5.0
● We have a option to change the shard key by using reshardCollection command.
● To change the name of a sharded collection by using renameCollection command.
Things need to be taken care before resharding:
● Initially MongoDB block writes to two seconds and begins the resharding operation.
● Available space should be 1.2x the size of the collection that you want to reshard.
● Ensure the Disk (50%) & CPU (80%) utilisation will be minimal.
● The new shard key cannot have a uniqueness constraint
● If a collection having uniqueness constraint is not supported for Resharding
Sharding Features in 5.0
The following commands are not supported on the collection, while the resharding operation is in progress.
● collMod
● convertToCapped
● createIndexes
● createIndex()
● drop()
● dropIndexes
● dropIndex()
● renameCollection
● renameCollection()
Sharding Features in 5.0
The following methods are not supported on the cluster, while the resharding operation is in progress.
● addShard
● removeShard
● db.createCollection()
● dropDatabase
Resharded commands:
● db.adminCommand({ reshardCollection: "mydbops.client", key: {"cperiod": 1} } )
Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops Team

Contenu connexe

Tendances

Basic Sharding in MongoDB presented by Shaun Verch
Basic Sharding in MongoDB presented by Shaun VerchBasic Sharding in MongoDB presented by Shaun Verch
Basic Sharding in MongoDB presented by Shaun VerchMongoDB
 
Sharding
ShardingSharding
ShardingMongoDB
 
Scaling with MongoDB
Scaling with MongoDBScaling with MongoDB
Scaling with MongoDBRick Copeland
 
MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...
MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...
MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...MongoDB
 
Mongodb sharding
Mongodb shardingMongodb sharding
Mongodb shardingxiangrong
 
Sharding Methods for MongoDB
Sharding Methods for MongoDBSharding Methods for MongoDB
Sharding Methods for MongoDBMongoDB
 
NoSQL Analytics: JSON Data Analysis and Acceleration in MongoDB World
NoSQL Analytics: JSON Data Analysis and Acceleration in MongoDB WorldNoSQL Analytics: JSON Data Analysis and Acceleration in MongoDB World
NoSQL Analytics: JSON Data Analysis and Acceleration in MongoDB WorldAjay Gupte
 
Mongodb - Scaling write performance
Mongodb - Scaling write performanceMongodb - Scaling write performance
Mongodb - Scaling write performanceDaum DNA
 
2014 05-07-fr - add dev series - session 6 - deploying your application-2
2014 05-07-fr - add dev series - session 6 - deploying your application-22014 05-07-fr - add dev series - session 6 - deploying your application-2
2014 05-07-fr - add dev series - session 6 - deploying your application-2MongoDB
 
MongoDB Best Practices in AWS
MongoDB Best Practices in AWS MongoDB Best Practices in AWS
MongoDB Best Practices in AWS Chris Harris
 
Development to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB ClustersDevelopment to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB ClustersSeveralnines
 
Sharding - Seoul 2012
Sharding - Seoul 2012Sharding - Seoul 2012
Sharding - Seoul 2012MongoDB
 
Replication and replica sets
Replication and replica setsReplication and replica sets
Replication and replica setsRandall Hunt
 
Sharding
ShardingSharding
ShardingMongoDB
 
MongoDB at Scale
MongoDB at ScaleMongoDB at Scale
MongoDB at ScaleMongoDB
 
Sharding
ShardingSharding
ShardingMongoDB
 
Everything You Need to Know About Sharding
Everything You Need to Know About ShardingEverything You Need to Know About Sharding
Everything You Need to Know About ShardingMongoDB
 
Webinar: Performance Tuning + Optimization
Webinar: Performance Tuning + OptimizationWebinar: Performance Tuning + Optimization
Webinar: Performance Tuning + OptimizationMongoDB
 
Setting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutesSetting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutesSudheer Kondla
 

Tendances (20)

Basic Sharding in MongoDB presented by Shaun Verch
Basic Sharding in MongoDB presented by Shaun VerchBasic Sharding in MongoDB presented by Shaun Verch
Basic Sharding in MongoDB presented by Shaun Verch
 
Sharding
ShardingSharding
Sharding
 
Scaling with MongoDB
Scaling with MongoDBScaling with MongoDB
Scaling with MongoDB
 
MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...
MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...
MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...
 
Mongodb sharding
Mongodb shardingMongodb sharding
Mongodb sharding
 
Sharding Methods for MongoDB
Sharding Methods for MongoDBSharding Methods for MongoDB
Sharding Methods for MongoDB
 
NoSQL Analytics: JSON Data Analysis and Acceleration in MongoDB World
NoSQL Analytics: JSON Data Analysis and Acceleration in MongoDB WorldNoSQL Analytics: JSON Data Analysis and Acceleration in MongoDB World
NoSQL Analytics: JSON Data Analysis and Acceleration in MongoDB World
 
Mongodb - Scaling write performance
Mongodb - Scaling write performanceMongodb - Scaling write performance
Mongodb - Scaling write performance
 
MongoDB Sharding Fundamentals
MongoDB Sharding Fundamentals MongoDB Sharding Fundamentals
MongoDB Sharding Fundamentals
 
2014 05-07-fr - add dev series - session 6 - deploying your application-2
2014 05-07-fr - add dev series - session 6 - deploying your application-22014 05-07-fr - add dev series - session 6 - deploying your application-2
2014 05-07-fr - add dev series - session 6 - deploying your application-2
 
MongoDB Best Practices in AWS
MongoDB Best Practices in AWS MongoDB Best Practices in AWS
MongoDB Best Practices in AWS
 
Development to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB ClustersDevelopment to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB Clusters
 
Sharding - Seoul 2012
Sharding - Seoul 2012Sharding - Seoul 2012
Sharding - Seoul 2012
 
Replication and replica sets
Replication and replica setsReplication and replica sets
Replication and replica sets
 
Sharding
ShardingSharding
Sharding
 
MongoDB at Scale
MongoDB at ScaleMongoDB at Scale
MongoDB at Scale
 
Sharding
ShardingSharding
Sharding
 
Everything You Need to Know About Sharding
Everything You Need to Know About ShardingEverything You Need to Know About Sharding
Everything You Need to Know About Sharding
 
Webinar: Performance Tuning + Optimization
Webinar: Performance Tuning + OptimizationWebinar: Performance Tuning + Optimization
Webinar: Performance Tuning + Optimization
 
Setting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutesSetting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutes
 

Similaire à Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops Team

Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding Mydbops
 
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...Mydbops
 
MongoDB : Scaling, Security & Performance
MongoDB : Scaling, Security & PerformanceMongoDB : Scaling, Security & Performance
MongoDB : Scaling, Security & PerformanceSasidhar Gogulapati
 
Sharding Overview
Sharding OverviewSharding Overview
Sharding OverviewMongoDB
 
Introduction to Sharding
Introduction to ShardingIntroduction to Sharding
Introduction to ShardingMongoDB
 
Sharding
ShardingSharding
ShardingMongoDB
 
MongoDB: Advance concepts - Replication and Sharding
MongoDB: Advance concepts - Replication and ShardingMongoDB: Advance concepts - Replication and Sharding
MongoDB: Advance concepts - Replication and ShardingKnoldus Inc.
 
DBVersity MongoDB Online Training Presentations
DBVersity MongoDB Online Training PresentationsDBVersity MongoDB Online Training Presentations
DBVersity MongoDB Online Training PresentationsSrinivas Mutyala
 
Advanced Sharding Features in MongoDB 2.4
Advanced Sharding Features in MongoDB 2.4 Advanced Sharding Features in MongoDB 2.4
Advanced Sharding Features in MongoDB 2.4 MongoDB
 
What We Need to Unlearn about Persistent Storage
What We Need to Unlearn about Persistent StorageWhat We Need to Unlearn about Persistent Storage
What We Need to Unlearn about Persistent StorageScyllaDB
 
Avoiding Data Hotspots at Scale
Avoiding Data Hotspots at ScaleAvoiding Data Hotspots at Scale
Avoiding Data Hotspots at ScaleScyllaDB
 
Scaling MongoDB - Presentation at MTP
Scaling MongoDB - Presentation at MTPScaling MongoDB - Presentation at MTP
Scaling MongoDB - Presentation at MTPdarkdata
 
MongoDB Sharding
MongoDB ShardingMongoDB Sharding
MongoDB ShardingRob Walters
 
Sharding in MongoDB Days 2013
Sharding in MongoDB Days 2013Sharding in MongoDB Days 2013
Sharding in MongoDB Days 2013Randall Hunt
 
How sitecore depends on mongo db for scalability and performance, and what it...
How sitecore depends on mongo db for scalability and performance, and what it...How sitecore depends on mongo db for scalability and performance, and what it...
How sitecore depends on mongo db for scalability and performance, and what it...Antonios Giannopoulos
 
MongoDB Europe 2016 - Big Data meets Big Compute
MongoDB Europe 2016 - Big Data meets Big ComputeMongoDB Europe 2016 - Big Data meets Big Compute
MongoDB Europe 2016 - Big Data meets Big ComputeMongoDB
 

Similaire à Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops Team (20)

Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding
 
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
 
MongoDB : Scaling, Security & Performance
MongoDB : Scaling, Security & PerformanceMongoDB : Scaling, Security & Performance
MongoDB : Scaling, Security & Performance
 
Sharding Overview
Sharding OverviewSharding Overview
Sharding Overview
 
Introduction to Sharding
Introduction to ShardingIntroduction to Sharding
Introduction to Sharding
 
Sharding
ShardingSharding
Sharding
 
MongoDB: Advance concepts - Replication and Sharding
MongoDB: Advance concepts - Replication and ShardingMongoDB: Advance concepts - Replication and Sharding
MongoDB: Advance concepts - Replication and Sharding
 
Tag based sharding presentation
Tag based sharding presentationTag based sharding presentation
Tag based sharding presentation
 
MongoDB
MongoDBMongoDB
MongoDB
 
DBVersity MongoDB Online Training Presentations
DBVersity MongoDB Online Training PresentationsDBVersity MongoDB Online Training Presentations
DBVersity MongoDB Online Training Presentations
 
Advanced Sharding Features in MongoDB 2.4
Advanced Sharding Features in MongoDB 2.4 Advanced Sharding Features in MongoDB 2.4
Advanced Sharding Features in MongoDB 2.4
 
Mongo sharding
Mongo shardingMongo sharding
Mongo sharding
 
What We Need to Unlearn about Persistent Storage
What We Need to Unlearn about Persistent StorageWhat We Need to Unlearn about Persistent Storage
What We Need to Unlearn about Persistent Storage
 
Avoiding Data Hotspots at Scale
Avoiding Data Hotspots at ScaleAvoiding Data Hotspots at Scale
Avoiding Data Hotspots at Scale
 
Mongodb Introduction
Mongodb IntroductionMongodb Introduction
Mongodb Introduction
 
Scaling MongoDB - Presentation at MTP
Scaling MongoDB - Presentation at MTPScaling MongoDB - Presentation at MTP
Scaling MongoDB - Presentation at MTP
 
MongoDB Sharding
MongoDB ShardingMongoDB Sharding
MongoDB Sharding
 
Sharding in MongoDB Days 2013
Sharding in MongoDB Days 2013Sharding in MongoDB Days 2013
Sharding in MongoDB Days 2013
 
How sitecore depends on mongo db for scalability and performance, and what it...
How sitecore depends on mongo db for scalability and performance, and what it...How sitecore depends on mongo db for scalability and performance, and what it...
How sitecore depends on mongo db for scalability and performance, and what it...
 
MongoDB Europe 2016 - Big Data meets Big Compute
MongoDB Europe 2016 - Big Data meets Big ComputeMongoDB Europe 2016 - Big Data meets Big Compute
MongoDB Europe 2016 - Big Data meets Big Compute
 

Plus de Mydbops

Efficient MySQL Indexing and what's new in MySQL Explain
Efficient MySQL Indexing and what's new in MySQL ExplainEfficient MySQL Indexing and what's new in MySQL Explain
Efficient MySQL Indexing and what's new in MySQL ExplainMydbops
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024Mydbops
 
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...Mydbops
 
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
Mastering Aurora PostgreSQL Clusters for Disaster RecoveryMastering Aurora PostgreSQL Clusters for Disaster Recovery
Mastering Aurora PostgreSQL Clusters for Disaster RecoveryMydbops
 
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...Mydbops
 
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15Mydbops
 
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE EventData-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE EventMydbops
 
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...Mydbops
 
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...Mydbops
 
Data Organisation: Table Partitioning in PostgreSQL
Data Organisation: Table Partitioning in PostgreSQLData Organisation: Table Partitioning in PostgreSQL
Data Organisation: Table Partitioning in PostgreSQLMydbops
 
Navigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
Navigating MongoDB's Queryable Encryption for Ultimate Security - MydbopsNavigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
Navigating MongoDB's Queryable Encryption for Ultimate Security - MydbopsMydbops
 
Data High Availability With TIDB
Data High Availability With TIDBData High Availability With TIDB
Data High Availability With TIDBMydbops
 
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...Mydbops
 
Enhancing Security of MySQL Connections using SSL certificates
Enhancing Security of MySQL Connections using SSL certificatesEnhancing Security of MySQL Connections using SSL certificates
Enhancing Security of MySQL Connections using SSL certificatesMydbops
 
Exploring the Fundamentals of YugabyteDB - Mydbops
Exploring the Fundamentals of YugabyteDB - Mydbops Exploring the Fundamentals of YugabyteDB - Mydbops
Exploring the Fundamentals of YugabyteDB - Mydbops Mydbops
 
Time series in MongoDB - Mydbops
Time series in MongoDB - Mydbops Time series in MongoDB - Mydbops
Time series in MongoDB - Mydbops Mydbops
 
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - MydbopsTiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - MydbopsMydbops
 
Achieving High Availability in PostgreSQL
Achieving High Availability in PostgreSQLAchieving High Availability in PostgreSQL
Achieving High Availability in PostgreSQLMydbops
 
MySQL Data Encryption at Rest
MySQL Data Encryption at RestMySQL Data Encryption at Rest
MySQL Data Encryption at RestMydbops
 

Plus de Mydbops (20)

Efficient MySQL Indexing and what's new in MySQL Explain
Efficient MySQL Indexing and what's new in MySQL ExplainEfficient MySQL Indexing and what's new in MySQL Explain
Efficient MySQL Indexing and what's new in MySQL Explain
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
 
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
 
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
Mastering Aurora PostgreSQL Clusters for Disaster RecoveryMastering Aurora PostgreSQL Clusters for Disaster Recovery
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
 
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
 
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
 
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE EventData-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
 
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
 
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
 
Data Organisation: Table Partitioning in PostgreSQL
Data Organisation: Table Partitioning in PostgreSQLData Organisation: Table Partitioning in PostgreSQL
Data Organisation: Table Partitioning in PostgreSQL
 
Navigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
Navigating MongoDB's Queryable Encryption for Ultimate Security - MydbopsNavigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
Navigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
 
Data High Availability With TIDB
Data High Availability With TIDBData High Availability With TIDB
Data High Availability With TIDB
 
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
 
Enhancing Security of MySQL Connections using SSL certificates
Enhancing Security of MySQL Connections using SSL certificatesEnhancing Security of MySQL Connections using SSL certificates
Enhancing Security of MySQL Connections using SSL certificates
 
Exploring the Fundamentals of YugabyteDB - Mydbops
Exploring the Fundamentals of YugabyteDB - Mydbops Exploring the Fundamentals of YugabyteDB - Mydbops
Exploring the Fundamentals of YugabyteDB - Mydbops
 
Time series in MongoDB - Mydbops
Time series in MongoDB - Mydbops Time series in MongoDB - Mydbops
Time series in MongoDB - Mydbops
 
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - MydbopsTiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
 
Achieving High Availability in PostgreSQL
Achieving High Availability in PostgreSQLAchieving High Availability in PostgreSQL
Achieving High Availability in PostgreSQL
 
MySQL Data Encryption at Rest
MySQL Data Encryption at RestMySQL Data Encryption at Rest
MySQL Data Encryption at Rest
 

Dernier

Introduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptxIntroduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptxProfASKolap
 
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...Christo Ananth
 
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...ssuserdfc773
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxMustafa Ahmed
 
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfInstruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfEr.Sonali Nasikkar
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfSkNahidulIslamShrabo
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxMustafa Ahmed
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
Dr Mrs A A Miraje C Programming PPT.pptx
Dr Mrs A A Miraje C Programming PPT.pptxDr Mrs A A Miraje C Programming PPT.pptx
Dr Mrs A A Miraje C Programming PPT.pptxProfAAMiraje
 
Independent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging StationIndependent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging Stationsiddharthteach18
 
Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2ChandrakantDivate1
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...archanaece3
 
Basics of Relay for Engineering Students
Basics of Relay for Engineering StudentsBasics of Relay for Engineering Students
Basics of Relay for Engineering Studentskannan348865
 
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024EMMANUELLEFRANCEHELI
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptamrabdallah9
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxMustafa Ahmed
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxkalpana413121
 
Fundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingFundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingChandrakantDivate1
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfJNTUA
 

Dernier (20)

Introduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptxIntroduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptx
 
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
 
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptx
 
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfInstruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdf
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Dr Mrs A A Miraje C Programming PPT.pptx
Dr Mrs A A Miraje C Programming PPT.pptxDr Mrs A A Miraje C Programming PPT.pptx
Dr Mrs A A Miraje C Programming PPT.pptx
 
Independent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging StationIndependent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging Station
 
Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...
 
Basics of Relay for Engineering Students
Basics of Relay for Engineering StudentsBasics of Relay for Engineering Students
Basics of Relay for Engineering Students
 
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptx
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
Fundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingFundamentals of Structure in C Programming
Fundamentals of Structure in C Programming
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
 

Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops Team

  • 1. Evolution of MongoDB Sharding and Its Best Practices Presenter by Ranjith A Database Engineer @ Mydbops Mydbops 11th Webinar www.mydbops.com info@mydbops.com
  • 2. Ranjith A MongoDB Database Engineer ranjith@mydbops.com linkedin.com/in/ranjith-a-70aab0157 About Me
  • 3. Mydbops at a Glance ● Founded in 2015, HQ in Bangalore India, 70+ Employees. ● Mydbops is on Database Consulting with core specialization on MySQL, MongoDB and PostgreSQL Administration and Support. ● Mydbops was created with a motto of developing a DevOPS model for Database Administration. ● We help organisations to scale in MySQL/Mongodb/postgresql and implement the advanced technologies in MySQL/Mongodb/PostgreSQL.
  • 4. Mydbops at a Glance Happy Customers 4
  • 5. Agenda ● Intro ● Sharding Overview ● Sharding Architecture ● Types of Sharding ● Things need to be taken care before choosing shard key ● Evolution of sharding from 3.6 to 5.0 ● Q/A
  • 7. Sharding Overview ● Sharding is a method for distributing data across multiple machines. ● By using MongoDB sharding, We can handle very large data sets and high throughput operations. ● Database systems with large data sets or high throughput applications can challenge the capacity of a single server. ● For example, If our system is a heavy read sensitive it will exhaust the CPU capacity of the server. Working set sizes larger than the system's RAM stress the I/O capacity of disk drives.
  • 8. Sharding Overview We can scale the system in two engineering approach. Vertical Scaling Horizontal sharding Achieved by MongoDB replica set / standalone server Achieved by MongoDB Sharding Data set in Single server Distribute the data set to Multiple servers Increasing the server capacity of a single server. Adding additional servers to increase capacity as required. There is a limitation for increasing the server capacity We can easily add or remove additional servers as required.
  • 10. Sharding Architecture - (Data Shard) ● MongoDB supports horizontal scaling through MongoDB Sharded Cluster. ● MongoDB shards data at the collection level, distributing the collection data across the shards in the cluster. ● MongoDB Sharded Cluster consists of the following components: 1. Shards 2. Mongos 3. Config server Shard: ● Each shard contains a subset of the sharded data. ● Each shard can be deployed as a replica set.
  • 11. Sharding Architecture-(Mongos) Mongos: ● The mongos acts as a query router, providing an interface between client applications and the sharded cluster. ● Applications never connect or communicate directly with the shards. ● The mongos tracks what data is on which shard by caching the metadata from the config servers. ● The mongos uses the metadata to route operations from applications and clients to the mongod instances. ● The mongos receives responses from all shards, it merges the data and returns the result document.
  • 12. Sharding Architecture-(Config) Config Server: ● Config servers store metadata and configuration settings for the cluster. As of MongoDB 3.4, config servers must be deployed as a replica set (CSRS). ● If your cluster has a single config server, then the config server is a single point of failure. ● If the config server is inaccessible, the cluster is not accessible. ● If you cannot recover the data on a config server, the cluster will be inoperable. ● Always use three config servers for production deployments
  • 13. Types of Sharding-(Hashed Sharding) MongoDB supports two sharding methods for distributing data across sharded clusters. ● Hashed sharding ● Ranged Sharding Hashed sharding:
  • 14. Hashed sharding ● Hashed Sharding involves computing a hash of the shard key field's value. We can use either a single field hashed index or a compound hashed index (New in 4.4) as the shard key. ● MongoDB automatically computes the hashes when resolving queries using hashed indexes. ● Hashed sharding provides a more even data distribution across the sharded cluster. ● The fields which we chose the hashed shard key should have a good cardinality (more unique values). ● Default _id field is the best example for good cardinality (Objectid values).
  • 15. Hashed sharding Command to enable Sharding: (DB Level) sh.enableSharding("databasename")
  • 16. Hashed sharding Command to enable Sharding: (Collection Level) sh.shardCollection( "databasename.collectionname", { "field" : "hashed" } ) ● Make sure before enabling sharding for a particular collection database must be sharded also the Index must be available for the fields which we are going to use as a shard key.
  • 18. Ranged sharding ● In Range-based sharding, data's are splitted into contiguous ranges determined by the shard key values. ● Data with "close" shard key values are likely to be in the same chunk or shard. ● This will improve the performance of the read queries (target documents) within a contiguous range. ● Poor sharded key selection will affect both read and write performance. Command to enable Sharding: (Collection Level) sh.shardCollection( "databasename.collectionname", { "field" : 1 } ) ● Make sure before enabling sharding for a particular collection, database must be sharded also the Index must be available for the fields which we are going to use as a shard key.
  • 19. Zone sharding ● In sharded clusters, you can create single or multiple zones in single shard as well as multiple shards. ● Zones represent a group of shards and associate one or more ranges of shard key values to that zone. ● Zone ranges are always inclusive of the lower boundary and exclusive of the upper boundary. ● From MongoDB 4.0.2, dropping a collection deletes its associated zone/tag ranges. ● Zones information are stored in config.shards & config.tags collection ● Starting from MongoDB 4.4 brings we can shard a collection and determine zones by compound keys, including mixing a hashed key with non-hashed keys.
  • 20. Zone sharding Command to create Zone: sh.addShardToZone("shardname", "zonename")
  • 21. Zone sharding Command to create Zone range: sh.updateZoneKeyRange("dbname.collectionname", { fieldname: "minkey" }, { fieldname: "maxkey" }, "zonename")
  • 22. Sharded key Shard key is the key to evenly distribute the data among all shards. Good shared key always satisfies the below points. ● High Cardinality ● High Frequency ● Non Monotonically Changing Shard Keys ● Sharding Query patterns
  • 23. Sharded key High Cardinality: ● High cardinality shard key - More no. of chunks & evenly distributed data ● Low cardinality shard key - Less no. of chunks & low distributed data ● Each unique shard key value can exist on no more than a single chunk at any given time. High Frequency: ● High frequency shard key - More evenly distributed data ● Low frequency shard key - Low distributed data ● Shard key cardinality & monotonically changing shard key also contribute to the distribution of the data.
  • 24. Sharded key Non Monotonically Changing Shard Keys:- ● monotonically increases or decreases shard key tends to distribute the data to a single chunk within the cluster. ● Each chunk has its own min & Max value.
  • 25. Evolution of sharding from 3.6 to 5.0 Mongo version Modify shard key field value Refining shard key Change shard key New variables New features 3.6 NO NO NO orphanCleanupDelaySecs Shard must be a replica set All shard members have chunk metadata 4.2 YES NO NO sh.setBalancerState(true) sh.setBalancerState(false) Modify shard key field value except immutable _id field 4.4 YES YES NO Hedged Reads Refinable shard keys Hedged Reads compound shard keys with a hashed field Remove multiple shard at a time Remove shard key size limit 5.0 YES YES YES reshardCollection Change the shard key Change the name of a sharded collection
  • 26. Sharding Features in 3.6 ● Shards must be replica sets. ● All members of the shard replica set maintain the metadata regarding chunk metadata. This prevents reads from the secondaries from returning orphaned data. ● Based on the orphanCleanupDelaySecs (New in 3.6) variable migrated chunk is deleted from the source shard. ● orphanCleanupDelaySecs - Default 900 (15 min) Set the orphanCleanupDelaySecs value to 20 min during the mongo service start mongod --setParameter orphanCleanupDelaySecs=1200 (20 min) setParameter command: db.adminCommand( { setParameter: 1, orphanCleanupDelaySecs: 1200 } )
  • 27. Sharding Features in 4.2 ● We can update a document's shard key value except the shard key field is the immutable _id field. ● In earlier version we can't change the document's shard key value.
  • 28. Sharding Features in 4.2 New variables in 4.2: ● sh.startBalancer() - sh.setBalancerState(true) (Enable auto-splitting for the sharded cluster) ● sh.stopBalancer() - sh.setBalancerState(false) (Disable auto-splitting for the sharded cluster) ● sh.enableAutoSplit() - Enable auto-splitting when the balancer is disabled
  • 29. Sharding Features in 4.4 ● Refinable Shard Keys - refine a collection's shard key by adding a suffix field or fields to the existing key db.employee.createIndex({"employeeid" : 1, "mailid": 1}) db.adminCommand( {refineCollectionShardKey: "mydbops.employee", key: { "employeeid" : 1, "mailid": 1 }} ) ● In 4.4, Shard key field can be missing in a sharded collection. ● In earlier versions, shard key fields must exist in every document for a sharded collection. ● Support Hedged Reads - To minimize latencies ● Support compound shard keys with a hashed field. ● More than one removeShard operation at a time. ● MongoDB removes the 512-byte limit on the shard key size.
  • 30. Sharding Features in 5.0 ● We have a option to change the shard key by using reshardCollection command. ● To change the name of a sharded collection by using renameCollection command. Things need to be taken care before resharding: ● Initially MongoDB block writes to two seconds and begins the resharding operation. ● Available space should be 1.2x the size of the collection that you want to reshard. ● Ensure the Disk (50%) & CPU (80%) utilisation will be minimal. ● The new shard key cannot have a uniqueness constraint ● If a collection having uniqueness constraint is not supported for Resharding
  • 31. Sharding Features in 5.0 The following commands are not supported on the collection, while the resharding operation is in progress. ● collMod ● convertToCapped ● createIndexes ● createIndex() ● drop() ● dropIndexes ● dropIndex() ● renameCollection ● renameCollection()
  • 32. Sharding Features in 5.0 The following methods are not supported on the cluster, while the resharding operation is in progress. ● addShard ● removeShard ● db.createCollection() ● dropDatabase Resharded commands: ● db.adminCommand({ reshardCollection: "mydbops.client", key: {"cperiod": 1} } )