![Page 1: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/1.jpg)
Scalability and High Availability with ReplicaSet
@vparihar
Vivek PariharAVP Engineering,Weboinse Lab
![Page 2: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/2.jpg)
Who Am I?● A Weboniser and Rubyist● Blogger(vparihar01.github.com)● MongoDb user● Geek● DevOps● Mainly write Ruby, but have great passion for Javascript
and Cloud Platforms● ...
![Page 3: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/3.jpg)
Agenda● {10: Reasons, To: Love }● Scalability with ● What is Sharding?● What is Replica Set?● Replication Process● Advantaged of Replica Set vs Master/Slave ● How to set up replica set on production
![Page 4: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/4.jpg)
{10: Reasons , To: Love } I.RELATIVELY EASY TO SETUP
In simple 3 steps MongoDb is start running on your machineStep-1. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
Step-2. sudo apt-get install mongodb-10gen
Step-3. sudo /etc/init.d/mongodb start
![Page 5: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/5.jpg)
{10: Reasons , To: Love } II.It’s fast
On average 7 times faster
![Page 6: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/6.jpg)
{10: Reasons , To: Love } III. Easy Scalability
{ Does Anyone know about scaling MySql? }
![Page 7: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/7.jpg)
{10: Reasons , To: Love } IV. High Availability
![Page 8: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/8.jpg)
{10: Reasons , To: Love } V. High Performance
![Page 9: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/9.jpg)
{10: Reasons , To: Love } VI. Flexible Schema{no schema: no problem}
![Page 10: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/10.jpg)
{10: Reasons , To: Love MongoDb} VII. Built in Sharding and Replication
![Page 11: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/11.jpg)
{10: Reasons , To: Love } VIII. Courses are excellent to start working as a
developer/DBA with.
![Page 12: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/12.jpg)
{10: Reasons , To: Love } IX. Deploy New Instances on Demand
![Page 13: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/13.jpg)
{10: Reasons , To: Love } X. BASE Rather Than ACID
ACID BASE
Atomicity Basically Available
Consistency Soft State
Isolation Eventual Consistency
Durable
![Page 14: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/14.jpg)
Horizontal Scaling Vs Vertical Scaling
![Page 15: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/15.jpg)
Scalability with ● Horizontal Scaling● Auto-Sharding● Vertical Scaling● Replica Set● Performance {For: Read, For: Write}● Storage
![Page 16: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/16.jpg)
Horizontal Scaling● By adding more machines into the existing pool.
● In a database world horizontal-scaling is often based on partitioning of the data i.e. each node contains only part of the data.
● MongoDB achieves this through auto-sharding.
![Page 17: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/17.jpg)
Vertical Scaling● Typically refers to adding more processors ,ram and
storage to a Symmetric Multiple Processing to extend processing capability.
● In a database world vertical-scaling is done through multi-core i.e. spreading the load between the CPU and RAM resources of that machine.
![Page 18: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/18.jpg)
![Page 19: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/19.jpg)
What is Sharding?● Sharding is a method for storing data across multiple
machines.
● Also known as Horizontal Scaling
● Divides the data set and distributes the data over multiple servers, or shards.
![Page 20: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/20.jpg)
What is Sharding?Each shard is an independent database, and collectively, the shards make up a single logical database.
![Page 21: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/21.jpg)
Sharding offerings:● Automatic balancing for changes in load and data
distribution● Easy addition of new machines● Scaling out to one thousand nodes● No single points of failure● Automatic failover
![Page 22: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/22.jpg)
What is Replication?● Replication is the process of synchronizing data across
multiple servers.● Mongo achieves Replication through Replica Sets● Replica sets are a form of asynchronous master/slave
replication● A replica set consists of two or more nodes that are
copies of each other. (i.e.: replicas)
![Page 23: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/23.jpg)
Purpose of Replication Data Redundancy ● Replica sets provide an automated method
for storing multiple copies of your data.
![Page 24: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/24.jpg)
Purpose of Replication Automated Failover / High Avalability ● If primary fails then replica set will
attempt to select another member to become the new primary.● This means that the failure of a
primary can be handled by the client without any configuration changes● Use heartbeat signal to detect failure
![Page 25: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/25.jpg)
Purpose of Replication ● Distributed Read Load/Read Scaling
By default, the primary node of a replica set is accessed for all reads and writes.
● Disaster RecoveryReplica sets allows for a “delayed secondary” node. This node can provide a window for recovering from disastrous events such as:
○ bad deployments ○ dropped tables and collections
![Page 26: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/26.jpg)
Replication Process● Members of a replica set replicate data continuously● MongoDB applies database operations on the primary
and then records the operations on the primary’s oplog. ● All replica set members contain a copy of the oplog,
allowing them to maintain the current state of the database.
![Page 27: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/27.jpg)
Advantages of Replica Set vs Master/Slave
● Replica sets are basically just master-slave with automatic failover.
● So, you have a pool of servers with one primary (the master) and N secondaries (slaves). If the primary crashes or disappears, the other servers will hold an election to choose a new primary.
![Page 28: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/28.jpg)
Demo -: How to set up replica set on Production!
Click on below link to see the demo-:
http://youtu.be/BFSGcBHcirU
![Page 29: MongoDb scalability and high availability with Replica-Set](https://reader034.vdocuments.us/reader034/viewer/2022042512/54c7ceae4a7959ff238b468a/html5/thumbnails/29.jpg)
Thanks
Would Love to answer your queries...
Vivek Parihar@vparihar