Chapter 35 — Quiz

13 questions. Answers at the bottom.


Multiple choice

Q1. Replication means: - A) Splitting data across nodes - B) Keeping copies of the database on multiple servers - C) Encrypting data - D) Indexing

Q2. In primary-replica replication: - A) All nodes accept writes - B) The primary accepts writes; replicas serve reads and enable failover - C) Replicas accept writes - D) There is no primary

Q3. Asynchronous replication: - A) Waits for replicas before commit (no lag) - B) Commits without waiting; replicas lag slightly (fast, possible small loss on failover) - C) Is always safer - D) Doesn't copy data

Q4. Sharding: - A) Copies the whole database to each node - B) Splits the data itself across nodes (each holds a subset) - C) Encrypts shards - D) Is the same as replication

Q5. Sharding helps with what replication does not: - A) Read scaling - B) Scaling writes/storage beyond one machine - C) High availability - D) Backups

Q6. The CAP theorem says during a network partition you can have at most two of: - A) Cost, Availability, Performance - B) Consistency, Availability, Partition tolerance - C) Concurrency, Atomicity, Persistence - D) Cache, API, Pooling

Q7. Since partitions are inevitable, the real choice during one is: - A) C vs P - B) C vs A - C) A vs P - D) None

Q8. A "CP" system during a partition: - A) Stays available but may serve stale data - B) Stays consistent but some requests fail (unavailable) - C) Loses all data - D) Ignores the partition

Q9. Eventual consistency is acceptable for: - A) A bank account balance - B) A social media like-count - C) Inventory you sell against - D) A payment confirmation

Q10. NewSQL databases (Spanner, CockroachDB) aim to provide: - A) NoSQL with no SQL - B) Horizontal scale-out WITH relational/ACID guarantees - C) Only caching - D) Single-server only

Q11. For most applications, the right default is: - A) Shard immediately - B) Managed PostgreSQL + read replicas - C) A NoSQL store - D) Multi-primary across continents


True/False

Q12. Distributed transactions (two-phase commit) are fast and simple. (True / False)

Q13. You should shard early, before you have scale problems, to be safe. (True / False)


Short answer

Q14. Explain CAP's practical meaning for a system choosing how to behave during a network partition, with one CP and one AP example.

---

Answer key

Q1 — B. Copies on multiple servers.

Q2 — B. Primary writes; replicas read + failover.

Q3 — B. Fast, slight lag, possible small loss on failover.

Q4 — B. Splits the data (subset per node).

Q5 — B. Scaling writes/storage beyond one machine.

Q6 — B. Consistency, Availability, Partition tolerance.

Q7 — B. C vs A (P is mandatory).

Q8 — B. Consistent but some requests fail.

Q9 — B. A like-count tolerates brief staleness.

Q10 — B. Distributed scale + relational/ACID.

Q11 — B. Managed PostgreSQL + replicas.

Q12 — False. 2PC is slow (round trips) and fragile (coordinator failure). Avoid when possible.

Q13 — False. Premature sharding adds huge complexity for scale you don't have; a big server + replicas goes far.

Q14. During a partition (nodes can't communicate), a system can't be both perfectly consistent and fully available, so it must choose. CP (e.g., a banking ledger): refuse/error requests it can't make consistent, staying correct but partly unavailable — better to reject a transaction than process it on stale data. AP (e.g., a social feed or shopping cart): keep serving possibly-stale data and reconcile when the partition heals — better to stay up than to show an error. The choice follows whether correctness or uptime matters more for that data.

Scoring: 12–14 you can reason about distribution; 9–11 review CAP and replication vs sharding; below 9, redo Exercises B–D.