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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Andrew Godwin
September 07, 2015
Programming
290
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
390
Django Through The Years
andrewgodwin
0
310
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
810
Taking Django's ORM Async
andrewgodwin
0
840
The Long Road To Asynchrony
andrewgodwin
0
760
The Scientist & The Engineer
andrewgodwin
1
850
Other Decks in Programming
See All in Programming
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.5k
Composerを使ったサプライチェーン攻撃の様子を眺めてみる #phpstudy
o0h
PRO
2
250
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5k
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
5.6k
「エンジニアインターン、どうやって取った?」準備のリアルを語るLT会 Progate BAR
akiomatic
0
130
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
160
net-httpのHTTP/2対応について
naruse
0
480
Inside Stream API
skrb
1
700
JJUG CCC 2026 Spring: JSpecify で実現する Kotlin フレンドリーな Java API 設計
ternbusty
1
160
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.4k
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
520
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
160
Featured
See All Featured
Docker and Python
trallard
47
3.9k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
610
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
390
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
240
Visualization
eitanlees
152
17k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
220
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
540
Between Models and Reality
mayunak
4
330
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
170
Skip the Path - Find Your Career Trail
mkilby
1
150
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
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