Choose and scale a database
Pick SQL or NoSQL by access pattern, then add indexes and replicas.
- Choose between relational and NoSQL stores based on requirements.
- Explain what an index trades.
- Describe leader-follower replication and replication lag.
Choosing a data store is about access patterns and guarantees, not fashion. Relational databases (PostgreSQL, MySQL) offer ACID transactions, joins, and a strict schema - a strong default. NoSQL stores trade some of that for a specific shape: key-value (Redis, DynamoDB) for lookups by key, document (MongoDB) for flexible nested records, wide-column (Cassandra) for huge write-heavy datasets partitioned by key, and graph databases for relationship traversal.
Indexes and replication
An index (usually a B-tree) lets the database find rows without scanning the whole table, and supports range queries such as “posts from the last week.” The cost: extra storage, and every write must also update each index.
In leader-follower replication, one leader accepts writes and streams them to followers, which serve reads. This scales reads and adds redundancy. With asynchronous replication, followers can lag behind, so a read from a follower may return stale data.
A common fix for lag is read-your-writes consistency: for a short window after a user writes, route that user’s reads to the leader. Failover promotes a follower when the leader dies; with asynchronous replication, writes the old leader acknowledged but had not yet replicated can be lost. Multi-leader and leaderless replication accept writes in several places, at the cost of resolving conflicts.
Practice: choose a data store
Try it
Up to 15 XPWhat fits this access pattern?
Start from how the data is read and written, not from what’s fashionable.
“Orders and payments that need transactions.”
“Sessions looked up by session id.”
“Billions of chat messages, read by conversation.”
“Profile photos and videos.”
“Reports that join customers, orders and products.”
Practice: see replication lag
Try it
Up to 15 XPBreak a leader and its followers
The lab calls the leader the primary, and the followers replicas. Try this:
- Write twice, then read from a replica. What would a user see?
- Crash the primary before replicating. What happened to the writes it confirmed?
- Turn on synchronous replication and try again. What did you gain, and what did it cost?
- Primaryv1
- Replica 1v1
- Replica 2v1
The primary and both replicas are at v1.
Key takeaways
Choose the store by access pattern and guarantees; relational is a strong default.
Indexes speed reads at the cost of writes and space.
Read replicas scale reads but introduce lag; route recent writers to the leader.
Lesson quiz
6 questions · pass with 5 correct · up to 50 XP
Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.
Questions about this lesson
Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.
Loading posts…