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
Good Schema Design and Why It Matters
Search
Andrew Godwin
May 15, 2014
Programming
1.3k
12
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Good Schema Design and Why It Matters
A talk I gave at DjangoCon Europe 2014.
Andrew Godwin
May 15, 2014
More Decks by Andrew Godwin
See All by Andrew Godwin
Reconciling Everything
andrewgodwin
1
390
Django Through The Years
andrewgodwin
0
320
Writing Maintainable Software At Scale
andrewgodwin
0
520
A Newcomer's Guide To Airflow's Architecture
andrewgodwin
0
420
Async, Python, and the Future
andrewgodwin
2
740
How To Break Django: With Async
andrewgodwin
1
820
Taking Django's ORM Async
andrewgodwin
0
850
The Long Road To Asynchrony
andrewgodwin
0
770
The Scientist & The Engineer
andrewgodwin
1
850
Other Decks in Programming
See All in Programming
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
300
Contextとはなにか
chiroruxx
1
370
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
350k
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
さぁV100、メモリをお食べ・・・
nilpe
0
150
スマートグラスで並列バイブコーディング
hyshu
0
260
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
230
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
260
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
190
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
14
5.8k
はてなアカウント基盤 State of the Union
cockscomb
1
720
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
410
Featured
See All Featured
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
330
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.3k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.6k
Faster Mobile Websites
deanohume
310
32k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.6k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
480
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
240
Agile that works and the tools we love
rasmusluckow
331
22k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.7k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.7k
Transcript
Andrew Godwin @andrewgodwin GOOD SCHEMA DESIGN WHY IT MATTERS and
Andrew Godwin Core Developer Senior Engineer Author & Maintainer
Schemas Explicit & Implicit
Explicit PostgreSQL MySQL Oracle SQLite CouchDB MongoDB Redis ZODB Implicit
Explicit Schema ID int Name text Weight uint 1 2
3 Alice Bob Charles 76 84 65 Implicit Schema { "id": 342, "name": "David", "weight": 44, }
Explicit Schema Normalised or semi normalised structure JOINs to retrieve
related data Implicit Schema Embedded structure Related data retrieved naturally with object
Silent Failure { "id": 342, "name": "David", "weight": 74, }
{ "id": 342, "name": "Ellie", "weight": "85kg", } { "id": 342, "nom": "Frankie", "weight": 77, } { "id": 342, "name": "Frankie", "weight": -67, }
Schemas inform Storage
PostgreSQL
Adding NULLable columns: instant But must be at end of
table
CREATE INDEX CONCURRENTLY Slower, and only one at a time
Constraints after column addition This is more general advice
MySQL Locks whole table Rewrites entire storage No DDL transactions
Oracle / MSSQL / etc. Look into their strengths
Changing the Schema Databases aren't code...
You can't put your database in a VCS You can
put your schema in a VCS But your data won't always survive.
Django Migrations Codified schema change format
None
Migrations aren't enough You can't automate away a social problem!
What if we got rid of the schema? That pesky,
pesky schema.
The Nesting Problem { "id": 123, "name": "Andrew", "friends": [
{"id": 456, "name": "David"}, {"id": 789, "name": "Mazz"}, ], "likes": [ {"id": 22, "liker": {"id": 789, "name", "Mazz"}}, ], }
You don't have to use a document DB (like CouchDB,
MongoDB, etc.)
Schemaless Columns ID int Name text Weight uint Data json
1 Alice 76 { "nickname": "Al", "bgcolor": "#ff0033" }
But that must be slower... Right?
Comparison (never trust benchmarks) Loading 1.2 million records PostgreSQL MongoDB
76 sec 8 min Sequential scan PostgreSQL MongoDB 980 ms 980 ms Index scan (Postgres GINhash) PostgreSQL MongoDB 0.7 ms 1 ms
Load Shapes
Read-heavy Write-heavy Large size
Read-heavy Write-heavy Large size Wikipedia TV show page Minecraft Forums
Amazon Glacier Eventbrite Logging
Read-heavy Write-heavy Large size Offline storage Append formats In-memory cache
Many indexes Fewer indexes
Your load changes over time Scaling is not just a
flat multiplier
General Advice Write heavy → Fewer indexes Read heavy →
Denormalise Keep large data away from read/write heavy data Blob stores/filesystems are DBs too
Lessons They're near the end so you remember them.
Re-evaulate as you grow Different things matter at different sizes
Adding NULL columns is great Always prefer this if nothing
else
You'll need more than one DBMS But don't use too
many, you'll be swamped
Indexes aren't free You pay the price at write/restore time
Relational DBs are flexible They can do a lot more
than JOINing normalised tables
Thanks! Andrew Godwin @andrewgodwin eventbrite.com/jobs are hiring: