Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
MongoDB's Replica Sets - Painless scaling and ...
Search
Viktor Petersson
August 30, 2012
Technology
3
2.6k
MongoDB's Replica Sets - Painless scaling and High Availability (HA)
Presentation for NoSQL Roadshow (Basel, Switzerland).
Viktor Petersson
August 30, 2012
Tweet
Share
More Decks by Viktor Petersson
See All by Viktor Petersson
Navigating the SBOM landscape: Formats, relevance, and tooling in 2024 @ BSides Bristol '24
vpetersson
0
59
State of Open Con '24
vpetersson
0
81
From Pets to Cattle
vpetersson
0
140
Beyond Just a Menu Display
vpetersson
0
83
The history of how Screenly OSE became the most popular digital signage project on GitHub
vpetersson
0
160
The DevSecOps Iceberg @ Cloud Native London
vpetersson
0
390
What's mtLS? @ Docker London
vpetersson
0
500
The "S" in "IoT" stands for "Security"
vpetersson
0
230
Living on the Edge @ Kubernetes London
vpetersson
0
130
Other Decks in Technology
See All in Technology
Oracle Cloud Infrastructure:2025年2月度サービス・アップデート
oracle4engineer
PRO
1
200
管理者しか知らないOutlookの裏側のAIを覗く#AzureTravelers
hirotomotaguchi
2
350
MC906491 を見据えた Microsoft Entra Connect アップグレード対応
tamaiyutaro
1
540
データの品質が低いと何が困るのか
kzykmyzw
6
1.1k
急成長する企業で作った、エンジニアが輝ける制度/ 20250214 Rinto Ikenoue
shift_evolve
3
1.3k
転生CISOサバイバル・ガイド / CISO Career Transition Survival Guide
kanny
3
970
エンジニアの育成を支える爆速フィードバック文化
sansantech
PRO
3
1k
技術負債の「予兆検知」と「状況異変」のススメ / Technology Dept
i35_267
1
1.1k
プロセス改善による品質向上事例
tomasagi
2
2.5k
個人開発から公式機能へ: PlaywrightとRailsをつなげた3年の軌跡
yusukeiwaki
11
3k
一度 Expo の採用を断念したけど、 再度 Expo の導入を検討している話
ichiki1023
1
160
関東Kaggler会LT: 人狼コンペとLLM量子化について
nejumi
3
570
Featured
See All Featured
Side Projects
sachag
452
42k
Build The Right Thing And Hit Your Dates
maggiecrowley
34
2.5k
GitHub's CSS Performance
jonrohan
1030
460k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.6k
Mobile First: as difficult as doing things right
swwweet
223
9.3k
Designing on Purpose - Digital PM Summit 2013
jponch
117
7.1k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
9
440
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
Navigating Team Friction
lara
183
15k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
133
33k
Faster Mobile Websites
deanohume
306
31k
Transcript
Replica Sets Painless scaling and High Availability (HA) Viktor Petersson
@vpetersson
Who am I? { name : ‘Viktor Petersson’, description :
[ ‘geek’, ‘entrepreneur’ ], founder_of : ‘wireload’, twitter : ‘@vpetersson’, email : ‘
[email protected]
’, } @vpetersson
What is MongoDB? @vpetersson • Key-value store • Schemas less
• Distributed file system (GridFS) • Built-in Map/Reduce • Built to scale
MongoDB 101 Relational Database MongoDB Database Database Table Collection Row
Document Database structure (simplified) @vpetersson
MongoDB 101 Relational Database MongoDB Master Primary Slave Secondary Arbiter
(Hidden) Node types @vpetersson
What are Replica Sets and why should I care? @vpetersson
Typical failover with relational databases Master Slave Failover IP Master
Slave Failover IP Master Normal Degraded @vpetersson (two servers, can lose one)
More complex failover with relational databases Failover IP Normal @vpetersson
Proxies Database servers Failover IP Degraded (four servers, can lose one of each kind)
Failover with MongoDB Primary Secondary Normal Degraded Secondary Driver Primary
Secondary Secondary Driver Primary @vpetersson (three servers, can lose two)
Primary Secondary Down -> Recovering Recovering -> Secondary Secondary Driver
Primary Secondary Secondary Driver Primary Secondary Primary Recovering Automatic recovery @vpetersson
Real life example: Taking down the primary for maintenance. No
dropped connections. Primary Secondary @vpetersson
Creating a Replica Set is dead simple. All it takes
is three servers (s0, s1, s2) and three commands¹. $ mongo > rs.initiate() > rs.add(‘s1’) > rs.add(‘s2’) 1. After adding “replSet=myRepSet” and “rest = true” to mongo.conf @vpetersson
Live demo! 3 servers with 1 client @vpetersson
Election @vpetersson 1. Most up to date 2. Highest priority
3. Less than 10s behind Primary
Configure node priority $ cfg = rs.conf() $ cfg.members[x].priority =
n $ rs.reconfig(cfg) x = Member id, n = Priority (0 - 100), default is 1. @vpetersson
Leverage your secondary-nodes Warning: Secondaries may be out-of-date. Read preference
• Primary (default) • Secondary • Secondary_only @vpetersson
What happens when I’ve outgrown my Replica Set? @vpetersson
@vpetersson mongos repset0 repset1 repsetN Sharding
Useful commands View server status $ db.serverStatus() View the replication
status $ rs.status() Step down as Primary $ rs.stepDown(n) @vpetersson
• Improved location awareness • Improved concurrent capacity • TTL
collections @vpetersson What’s new in MongoDB 2.2? Full release notes: http://docs.mongodb.org/manual/release-notes/2.2/ (released yesterday)
Summary @vpetersson • Replica Sets are extremely easy to set
up • Doesn’t require failover IPs or custom scripts • Minimal maintenance • Built to scale
Questions? @vpetersson
Thanks to @vpetersson
Contact me! email:
[email protected]
www: viktorpetersson.com twitter: @vpetersson Also visit
WireLoad.net YippieMove.com @vpetersson This deck will be available at ViktorPetersson.com.
• MongoDB: GridFS, sharding and deploying in the cloud (http://goo.gl/1QAV1)
• MongoDB Replica Set (http://goo.gl/D2pkq) • 10gen (http://goo.gl/3m4Kn) @vpetersson Useful resources