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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Juan Patten
January 24, 2013
Programming
370
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Practical Tips from 2 Years of Growing on MongoDB
The talk I gave at Mongo Boulder 2013
Juan Patten
January 24, 2013
Other Decks in Programming
See All in Programming
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
260
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
210
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
230
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
920
Agentic UI
manfredsteyer
PRO
0
190
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
300
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
170
dRuby over BLE
makicamel
2
390
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.5k
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
4
1.5k
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
7.7k
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
Featured
See All Featured
Color Theory Basics | Prateek | Gurzu
gurzu
0
370
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
540
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
Documentation Writing (for coders)
carmenintech
77
5.4k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
340
HDC tutorial
michielstock
2
720
Faster Mobile Websites
deanohume
310
32k
The Curious Case for Waylosing
cassininazir
1
400
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
Making the Leap to Tech Lead
cromwellryan
135
9.9k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
340
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