# System Design Quiz

## Question 1

In the CAP theorem, partition tolerance means:

A) The system can split into multiple data centers
B) The system continues to operate despite network partitions
C) Data is partitioned across shards
D) You can choose between consistency and availability

<!-- ANSWER: B -->
<!-- EXPLANATION: Partition tolerance means the system still works when network links fail or messages are lost. In practice, you must assume partitions happen; you choose between CP (consistency + partition tolerance) or AP (availability + partition tolerance). -->

## Question 2

Cache-aside (lazy loading) means:

A) The cache is populated when the app starts
B) The app checks the cache first; on miss, fetches from DB and populates cache
C) Writes go to cache first, then DB
D) The cache sits alongside the database

<!-- ANSWER: B -->
<!-- EXPLANATION: Cache-aside: app reads from cache first. On miss, app fetches from DB, writes to cache, returns to client. The app is responsible for cache population. -->

## Question 3

When would you choose a message queue over synchronous HTTP calls?

A) When you need real-time responses
B) When you want to decouple services and handle traffic spikes asynchronously
C) When the database is too slow
D) When you need strong consistency

<!-- ANSWER: B -->
<!-- EXPLANATION: Message queues decouple producers and consumers. Async processing handles spikes, retries, and offloads heavy work. They trade latency for reliability and decoupling. -->

## Question 4

Consistent hashing is used to:

A) Encrypt data across nodes
B) Minimize key reassignment when nodes are added or removed
C) Balance load evenly across all nodes
D) Ensure data consistency in a distributed database

<!-- ANSWER: B -->
<!-- EXPLANATION: Consistent hashing maps keys to a ring. When a node joins/leaves, only keys in that node's range need to move. Used in CDNs, caches, and distributed storage. -->

## Question 5

For a URL shortener with 10:1 read:write ratio, the main scalability concern is:

A) Write throughput to the database
B) Read throughput — use caching aggressively
C) Storage capacity
D) Network latency between regions

<!-- ANSWER: B -->
<!-- EXPLANATION: With 10:1 read:write, reads dominate. Caching (CDN, app cache) for hot short URLs dramatically reduces DB read load. Writes are much lower volume. -->

## Question 6

Fan-out on write (precomputing feeds) is preferable when:

A) Most users have millions of followers
B) Most users have few followers and read frequently
C) Writes are more frequent than reads
D) You need real-time consistency

<!-- ANSWER: B -->
<!-- EXPLANATION: Fan-out on write: when a user posts, push to all followers' feeds. Good when followers are modest in number; reads are fast. Bad for celebrities (millions of followers). -->

## Question 7

<!-- VISUAL: quiz-drag-order -->

Put these system design interview steps in the recommended order:

A) Scale the design (bottlenecks, sharding, caching)
B) Clarify requirements and constraints
C) Design high-level components
D) Deep dive on 1–2 critical components
E) Identify and address trade-offs

<!-- ANSWER: B,C,A,D,E -->
<!-- EXPLANATION: Clarify requirements first. Design high-level components. Scale the design (handle load). Deep dive on critical parts. Discuss trade-offs and alternatives. -->

## Question 8

<!-- VISUAL: quiz-matching -->

Match each scaling technique to its description:

A) Horizontal scaling → 1) Add more machines to handle load
B) Vertical scaling → 2) Add more RAM, CPU to existing machines
C) Sharding → 3) Partition data across multiple databases by key
D) Load balancer → 4) Distribute requests across multiple servers

<!-- ANSWER: A1,B2,C3,D4 -->
<!-- EXPLANATION: Horizontal = add more nodes. Vertical = add resources to existing nodes. Sharding = partition data by key. Load balancer = distribute incoming requests. -->
