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
Practical Tips from 2 Years of Growing on MongoDB
Search
Juan Patten
January 24, 2013
Programming
2
370
Practical Tips from 2 Years of Growing on MongoDB
The talk I gave at Mongo Boulder 2013
Juan Patten
January 24, 2013
Tweet
Share
Other Decks in Programming
See All in Programming
Apache Iceberg V3 and migration to V3
tomtanaka
0
170
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
7.5k
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
210
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
470
Best-Practices-for-Cortex-Analyst-and-AI-Agent
ryotaroikeda
1
110
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
180
CSC307 Lecture 07
javiergs
PRO
1
560
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
200
生成AIを活用したソフトウェア開発ライフサイクル変革の現在値
hiroyukimori
PRO
0
100
OSSとなったswift-buildで Xcodeのビルドを差し替えられるため 自分でXcodeを直せる時代になっている ダイアモンド問題編
yimajo
3
630
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
Featured
See All Featured
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
260
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
68
HDC tutorial
michielstock
1
390
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
67
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.9k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
170
Darren the Foodie - Storyboard
khoart
PRO
2
2.4k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
57
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.1k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
240
Transcript
Practical Tips from 2 Years of Growing on MongoDB Juan
Patten – Rafflecopter
I’m J.R. www.Rafflecopter.com @rafflecopter @runningskull
❤
What We Talkin’ Bout? • Practical lessons learned from 3
iterations of schema design • A few clever(?) tricks • Our approach to no-downtime schema migration
Mongo Is... “Web-scale for dummies!” “Schema-free, man. w00t!”
Mongo Is... “Web-scale for dummies!” “Schema-free, man. w00t!” structured data
== schema! You still have to think!
Users Raffles Entries Entrants Rafflecopter
Users Raffles Entries Entrants Rafflecopter
Schema #1 Raffle = { _id: <string> [ ... ]
entries: [ {...}, {...}, ... ] } • Tough to access • Padding Factor • Max Document Size LESSONS
Schema #2 • “Denormalize!” • Each entry in own document
• _id is UUID() • Indexes for each access pattern • Documents (almost) never grow • Cache results of expensive queries
Schema #2 – Lessons • Complex queries for simple things
• Indexes gigantic - killed performance • Old data “lingered” • _id unused
Schema #3 – Goals • Minimal indexes • One document
per entrant per raffle • _id derivable from known data • Old data should “expire” naturally
ObjectID’s – A (not so) Secret Weapon 24-byte string →
12-byte binary value new ObjectId() new ObjectId("47cc67093475061e3d95369d") or
B-TREES ObjectID’s – A (not so) Secret Weapon
_id = UUID() RAM ObjectID’s – A (not so) Secret
Weapon
_id = new ObjectId() RAM ObjectID’s – A (not so)
Secret Weapon
_id = new ObjectId() timestamp (seconds since epoch) “misc” ID
info (machine_id | pid | incr) not derivable later! ObjectID’s – A (not so) Secret Weapon
timestamp (raffle_date_created) “misc” ID info md5(entrant_id | raffle_id | salt)
_id = new ObjectId(X) X = “1234567890abcdefabcdef” ObjectID’s – A (not so) Secret Weapon
Schema #3 – Results ✓Minimal indexes (5 large → 2
small) ✓One document per entrant per raffle ✓_id derivable from known data ✓Old data should “expire” naturally • write lock % cut by 9x • page faults cut by 10x • open cursor size cut by 5x
Schema Takeaways • access patterns == indexes. design the schema
around them • save queries and index space by deriving ID’s from known data • denormalize in moderation
Painless Schema Migration { [ ... ] _legacy: [ ‘flag_a’,
‘flag_b’, ‘flag_c’ ] }
Thanks! @runningskull JuanPatten.com Need cheap, effective marketing? Try giveaways! www.Rafflecopter.com