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
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
300
今から始めるClaude Code超入門
448jp
8
9.1k
余白を設計しフロントエンド開発を 加速させる
tsukuha
7
2.1k
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
750
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
140
CSC307 Lecture 03
javiergs
PRO
1
490
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
470
並行開発のためのコードレビュー
miyukiw
0
1.1k
AgentCoreとHuman in the Loop
har1101
5
240
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
140
Featured
See All Featured
Balancing Empowerment & Direction
lara
5
900
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
0
2.4k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
100
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Why Our Code Smells
bkeepers
PRO
340
58k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
0
440
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.3k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
150
Facilitating Awesome Meetings
lara
57
6.8k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
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