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
議事録の要点整理を自動化! サーバレス Bot 構築術
penpeen
3
960
The Past, Present, and Future of Enterprise Java with ASF in the Middle
ivargrimstad
0
300
Local Peer-to-Peer APIはどのように使われていくのか?
hal_spidernight
1
210
より安全で効率的な Go コードへ: Protocol Buffers Opaque API の導入
shwatanap
3
1k
メモリ不足との戦い〜大量データを扱うアプリでの実践例〜
kwzr
1
250
Platformに“ちょうどいい”責務ってどこ? 関心の熱さにあわせて考える、責務分担のプラクティス
estie
2
380
Swiftビルド弾丸ツアー - Swift Buildが作る新しいエコシステム
giginet
PRO
0
280
意外と簡単!?フロントエンドでパスキー認証を実現する WebAuthn
teamlab
PRO
2
810
Tool Catalog Agent for Bedrock AgentCore Gateway
licux
7
2.7k
OWASP Kansai DAY 2025.09: OSINTにふれてみよう
deka_morita
0
120
今だからこそ入門する Server-Sent Events (SSE)
nearme_tech
PRO
3
280
ユーザーも開発者も悩ませない TV アプリ開発 ~Compose の内部実装から学ぶフォーカス制御~
taked137
0
210
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
27
1.9k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.1k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
131
19k
GraphQLの誤解/rethinking-graphql
sonatard
72
11k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.4k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
53k
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