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
Dubious Database Design
Search
Andrew Godwin
September 07, 2015
Programming
300
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Dubious Database Design
My talk from DjangoCon US 2015.
Andrew Godwin
September 07, 2015
More Decks by Andrew Godwin
See All by Andrew Godwin
Reconciling Everything
andrewgodwin
1
400
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
830
Taking Django's ORM Async
andrewgodwin
0
850
The Long Road To Asynchrony
andrewgodwin
0
770
The Scientist & The Engineer
andrewgodwin
1
860
Other Decks in Programming
See All in Programming
act1-costs.pdf
sumedhbala
0
170
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.7k
OS アップデート対応の取り組み方がもっと共有されてほしい
andpad
0
110
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
640
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
130
関数型プログラミングのメリットって何だろう?
wanko_it
0
140
The NotImplementedError Problem in Ruby
koic
1
1.1k
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
140
dRuby over BLE
makicamel
2
410
自作OSでスライド発表する
uyuki234
1
3.6k
Webフレームワークの ベンチマークについて
yusukebe
0
190
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
450
Featured
See All Featured
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
350
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
240
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.5k
How STYLIGHT went responsive
nonsquared
100
6.2k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
180
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.9k
Ruling the World: When Life Gets Gamed
codingconduct
0
270
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
220
Context Engineering - Making Every Token Count
addyosmani
9
1k
A Soul's Torment
seathinner
6
3k
Transcript
DUBIOUS Database DESIGN
Andrew Godwin Hi, I'm Author of 1.7 Django & South
migrations Senior Software Engineer at Only hates MySQL a little
“Do this. Don't ask why.”
Learning from failure.
Spacelog 1
Spacelog 1
“Redis is fast!”
None
Spacelog 1
Read-only, forever.
“Redis is fast!”
GET chapter-1 GET chapter-2
GET entry-123 GET entry-124 GET entry-125
ZRANGEBYSCORE .... GET entry-123 GET entry-124 GET entry-125
Request page Look up key range Multi-get key range Get
speaker details
SELECT ... JOIN ... WHERE ...
Ignoring JOIN 2
“Joins are slow!”
{"id": 11, "post": "abc", "author": 1} {"id": 12, "post": "def",
"author": 2} {"id": 13, "post", "ghi", "author": 3} {"id": 1, "name": "Andrew"} {"id": 2, "name": "Brenda"} {"id": 3, "name": "Carol"}
n number of authors m × number of posts
scan all posts build dict of author -> posts scan
all authors and emit with posts
HASH JOIN
{ "id": 11, "post":"abc", "author": {"name": "Andrew"} }
{ "id": 11, "post":"abc", "author": { "name": "Andrew", "last_seen": 120993013,
} }
The server's running, it's fine! 3
Write new save file Write new save file Delete old
save file
Write new save file Write new save file ?
Tell payment processor to send Mark as processing Find unpaid
clients Mark as paid
Tell payment processor to send Mark as processing Find unpaid
clients Mark as paid
The Fastidious Modeller 4
TwitterUser FacebookUser LinkedInUser EmailUser
SELECT ... FROM TwitterUser SELECT ... FROM EmailUser SELECT ...
FROM LinkedInUser
None
None
The database isn't magic.
The Table Lover 5
“How do I make tables at runtime?”
None
Tables/columns per language Tables/columns per customer Configurable CMS columns
Columns per language 300 - 400 language variants x A
couple of translated cols per table x
DDL is very expensive.
Use JSON, hstore, or EAV-style table!
6 The Cold Boot
Decent cache hit rate Application servers mostly utilised
Great engineering!
What would happen if I deleted the entire cache?
None
The Optimist 7
Sharded PostgreSQL ElasticSearch Riak Redis Flat files + + +
+
Don't forget redundancy. And backups.
What happens if just one dies?
n services = n points of failure
The Primary Optimist 8
“The highest value PK is the most recent”
“Autoincrement will work and scale forever”
“IDs are numbers we can do maths on”
The Function Lover 9
"Why waste time fetching columns and rendering them separately?"
CREATE FUNCTION
CREATE FUNCTION ... import jinja2
bit.ly/whynotpg
None
SELECT render(template, id) FROM pages WHERE %s ~ url;
None
There's a reason behind every rule.
Ask why, or try yourself. Don't write it off without
context.
Thanks. Andrew Godwin @andrewgodwin