Lesson 2 · Unit 02
Scaling the database
Indexes, a bigger box, replicas, then shards, in that order
What you practise
- Vertical first, read replicas and their lag, partitioning, choosing SQL or NoSQL per workload, indexes before hardware
Try a question from this lesson
Pick one
Finding one user by email scans 50 million rows and takes 4 seconds. What do you try first?
Hint
The problem is not how many rows exist. It is how many of them the query has to look at.
Correct answer
Add an index on the email column
Why
An index turns a scan of 50 million rows into a tree lookup of a few steps. It is one statement and costs nothing to operate. Sharding or new hardware would make a wasteful query run in more places.
The idea
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
The scaling ladder
Climb one rung at a time. Each rung buys capacity and costs more to run than the one before.
1. Fix queries, add indexes. 2. A bigger machine. 3. A cache for hot reads. 4. Read replicas: copies that answer reads. 5. Partitioning (sharding): split the data across machines.
Replicas multiply reads. Only partitioning multiplies writes, and it is the rung you cannot easily climb back down.
11 more exercises in the app
- 5× multiple choice
- 1× order the lines
- 2× type the answer
- 1× true or false
- 1× fill the blanks
- 1× match the pairs
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.