Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MongoDB sharded cluster. How to design your topology ?

170 views

Published on

This slides was presented at Mydbops Database Meetup 4 on Aug-03 2019 by Vinodh Krishnaswamy ( Percona ). This talk focuses on when to go for sharing topology in MongoDB and their benefits and impact.

Published in: Technology
  • Don't fear hair loss - fight it! Try Profollica� natural two-step hair loss system for visible results you'll see and love! ■■■ https://tinyurl.com/y49r9d8j
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

MongoDB sharded cluster. How to design your topology ?

  1. 1. © 2019 Percona1 Vinodh Krishnaswamy MongoDB Sharded Cluster - How to design your topology Support Engineer - MongoDB & MySQL Percona
  2. 2. © 2019 Percona2 ◆ Started as MySQL DB DBA ◆ Support for MongoDB ◆ Trainer ◆ Scripting, Reading, Driving ◆ “Guruji” - who shares knowledge ◆ Now here I am - Perconian!!! Who am I
  3. 3. © 2019 Percona3 Agenda ▪ Sharded Cluster - components ▪ Ranged Sharding ▪ Hashed Sharding ▪ Zones / Tags
  4. 4. © 2019 Percona4 Agenda ▪ ReplicaSet - Key points ▪ Topology ▪ Q&A
  5. 5. © 2019 Percona5 Sharded Cluster
  6. 6. © 2019 Percona6 Sharded Cluster ▪ Horizontal Scaling • Data across multiple nodes • Reduce stress for larger working set • Ability to add more servers • HA
  7. 7. © 2019 Percona7 Architecture mongos
  8. 8. © 2019 Percona8 Sharded Cluster ▪ Shard Key ▪ Chunks ▪ Balancer - Chunk distribution
  9. 9. © 2019 Percona9 POINTS TO NOTE TARGET vs BROADCAST
  10. 10. © 2019 Percona10 Primary Shard A A
  11. 11. © 2019 Percona11 Primary Shard sh.status()
  12. 12. © 2019 Percona12 Primary Shard ▪ Routing - sharded vs unsharded ▪ Keep at right shard db.adminCommand( { movePrimary: <databaseName>, to: <newPrimaryShard> } )
  13. 13. © 2019 Percona13 Ranged Sharding
  14. 14. © 2019 Percona14 Strategy ▪ Ranged Sharding
  15. 15. © 2019 Percona15 Strategy ▪ Ranged Sharding sh.shardCollection( "database.collection", { <shard key> } ) Example: sh.shardCollection( "vinodh.testData", { empNo: 1 } )
  16. 16. © 2019 Percona16 Monotonically Changing Shard Key
  17. 17. © 2019 Percona17 Ranged Sharding ▪ Contiguous ranges determined by Shard Key ▪ Default method ▪ Efficient when • High cardinality • Low Shard Key frequency • Non-Monotonically Changing Shard key
  18. 18. © 2019 Percona18 Hashed Sharding
  19. 19. © 2019 Percona19 Strategy ▪ Hashed Sharding
  20. 20. © 2019 Percona20 Strategy ▪ Hashed Sharding uses hashed index sh.shardCollection( "database.collection", { <field> : “hashed” } ) Example: sh.shardCollection( "vinodh.testData", { UUIDfield: “hashed” } )
  21. 21. © 2019 Percona21 Monotonically Changing Shard Key - Hash
  22. 22. © 2019 Percona22 Hashed Sharding ▪ Provides equal distribution ▪ Target vs Broadcast operations ▪ Ideal for fields that changes monotonically like ObjectID, timestamp etc
  23. 23. © 2019 Percona23 Zones
  24. 24. © 2019 Percona24 Why Zones? ▪ Isolate data set ▪ Geographically closest ▪ Route data to desired Shard h/w ▪ Distribute Writes based on DC
  25. 25. © 2019 Percona25 How to... ▪ First create tagRange with Shards sh.addShardTag("shard01", "tag1") sh.addShardTag("shard02", "tag2") ▪ Assign tagRanges to collections sh.addTagRange( "<database>.<collection>", { "gender" : "Male", "userid" : MinKey }, { "gender" : "Male", "userid" : MaxKey }, "tag1")
  26. 26. © 2019 Percona26 Zone
  27. 27. © 2019 Percona27 Zone
  28. 28. © 2019 Percona28 ReplicaSet - Key Points
  29. 29. © 2019 Percona29 Replicaset
  30. 30. © 2019 Percona30 Replicaset
  31. 31. © 2019 Percona31 Replicaset - ARBITER
  32. 32. © 2019 Percona32 Replicaset - Election+Priority ELECTION - VOTING & CHOOSING Priority: 5Priority: 1 Priority: 1 Priority: 5
  33. 33. © 2019 Percona33 Points to Note ▪ Set proper {Priority:n} to elect a member as Primary • Avoid setting Priority for all members ▪ Set {writeConcern:majority} to avoid data loss ▪ Set readPreference for reads
  34. 34. © 2019 Percona34 Topology- Application Servers
  35. 35. © 2019 Percona35 Applications and mongos in one server
  36. 36. © 2019 Percona36 mongos/router in each Application servers
  37. 37. © 2019 Percona37 Sharded Cluster in Private network
  38. 38. © 2019 Percona38 Topology- Shards
  39. 39. © 2019 Percona39 Shard instances deployed in dedicated servers design
  40. 40. © 2019 Percona40 Multiple Shard members in each Server + HA design
  41. 41. © 2019 Percona41 Production DC and DR DC + HA design
  42. 42. © 2019 Percona42 Using Zones / Tags + HA design
  43. 43. © 2019 Percona43 Points to Note
  44. 44. © 2019 Percona44 POINTS TO NOTE ▪ SHARD KEY - Pain Point! • Monotonically increased key • Do your tests! ▪ SHARD EARLY! ▪ ZONES
  45. 45. © 2019 Percona45 POINTS TO NOTE BACKUP + RESTORE https://www.percona.com/blog/2018/12/13/mong odb-backup-how-and-when-to-use-psmdb-hotbac kup-and-mongodb_consistent_backup/
  46. 46. © 2019 Percona46 Question? vinodh.krishnaswamy@percona.com https://in.linkedin.com/in/vinodhkrish
  47. 47. © 2019 Percona47 THANK YOU

×