CAP Theorem and Database Sharding Fundamentals Quiz Quiz

Explore the essentials of the CAP Theorem and its role in database sharding strategies. This quiz helps you understand the principles of consistency, availability, and partition tolerance in distributed database systems while clarifying their impact on real-world sharding scenarios.

  1. Defining CAP Theorem

    Which three properties form the core of the CAP Theorem in distributed databases?

    1. Correctness, Accessibility, Partitioning
    2. Connectivity, Accuracy, Persistence
    3. Concurrency, Atomicity, Performance
    4. Consistency, Availability, Partition Tolerance

    Explanation: Consistency, Availability, and Partition Tolerance are the three fundamental properties described by the CAP Theorem. The other options either use unrelated terms or use words that sound similar but have different meanings. For example, Concurrency and Atomicity belong to ACID properties, not CAP. Correctness and Connectivity are not part of the CAP model.

  2. Consistency in the CAP Theorem

    In the context of the CAP Theorem, what does consistency mean when accessing replicated data shards?

    1. Consistency means data never changes
    2. Every read returns the most recent write or an error
    3. Data is always split across servers
    4. All requests receive immediate responses

    Explanation: In CAP, consistency ensures that every read reflects the latest write or returns an error if that is not possible. Immediate responses are more related to availability. Data splitting across servers relates to partitioning, not consistency, and data not changing is incorrect since databases are expected to update entries.

  3. Availability in CAP Systems

    If a sharded database is designed to prioritize availability, what is a key guarantee it provides according to the CAP Theorem?

    1. Data is updated only once per day
    2. Every request receives a response, whether successful or not
    3. Network partitions never occur
    4. All nodes always have the same data at all times

    Explanation: Availability in the CAP Theorem requires that the system responds to every request, even during failures or partitions, though it may return outdated data. The idea that all nodes always have the same data refers to consistency, not availability. Network partitions can occur, and the last option about daily updates is unrelated.

  4. Partition Tolerance Explained

    What does partition tolerance refer to in the context of the CAP Theorem and distributed sharding?

    1. The system continues to operate despite lost or delayed network messages
    2. All data is stored on a single server
    3. Users can always see their own recent changes only
    4. Data access is always fast, even under heavy load

    Explanation: Partition tolerance means the distributed system works correctly even if communications are lost or delayed between parts of the network. Fast data access under heavy load is about performance, not partition tolerance. Storing all data on one server is not sharding, and seeing only one's own changes does not define partition tolerance.

  5. Choosing Trade-offs

    During a temporary network partition, which two properties must a distributed sharded system choose between according to the CAP Theorem?

    1. Partitioning and Performance
    2. Durability and Consistency
    3. Scalability and Accuracy
    4. Consistency and Availability

    Explanation: When partition tolerance is required, the CAP Theorem states that a system can only guarantee either consistency or availability, not both. Durability and scalability are unrelated to CAP's three key properties, and performance or accuracy are not part of the theorem.

  6. Example Scenario: Sharded Chat Application

    A chat application uses sharding for user messages. Due to a network issue, users see old messages for a few minutes but the app remains responsive. Which CAP property did this system prioritize along with partition tolerance?

    1. Performance
    2. Availability
    3. Encryption
    4. Consistency

    Explanation: The system prioritized availability, permitting users to keep interacting even though the data may be outdated. Consistency is compromised here, as shown by the stale messages. Performance and encryption are not relevant to the choice described in the scenario.

  7. Impact of Sharding on the CAP Theorem

    How does sharding data across multiple servers affect the relevance of the CAP Theorem?

    1. It limits partition tolerance to only two servers
    2. Sharding prevents any network issues from occurring
    3. It eliminates the need to consider consistency and availability
    4. It makes the CAP Theorem more important, as distributed systems face network partitions

    Explanation: Sharding increases the number of nodes and network links, making network partitions more likely and thus raising the importance of the CAP Theorem. Sharding does not eliminate the need for consistency or availability. Partition tolerance is not limited by the number of servers. Sharding also cannot prevent network issues entirely.

  8. Consistency Example in Sharding

    Suppose a sharded database always waits for all shards to confirm a data update before responding to the client. Which CAP property does this behavior demonstrate?

    1. Availability
    2. Consistency
    3. Partitioning
    4. Scalability

    Explanation: Waiting for all shards to confirm updates ensures that reads after a write see the most recent value, which demonstrates consistency. Availability would mean responding even if not all shards agree. Partitioning refers to splitting the database, and scalability involves handling growth, not data correctness.

  9. Effects of Network Partition on Sharded Data

    What could happen to a sharded database during a network partition if it chooses availability over consistency?

    1. All servers immediately go offline
    2. Data is merged with an unrelated system
    3. Some users may see outdated information until the partition is resolved
    4. No changes can be written to the database

    Explanation: Choosing availability means the system continues to answer requests, which can lead to some parts serving stale data until the network issues are fixed. Going offline is the opposite of availability. Data merging with unrelated systems is not a typical outcome of partition tolerance, and refusing all writes occurs if a system chooses consistency over availability.

  10. Misconception of the CAP Theorem

    Which statement about the CAP Theorem is NOT correct?

    1. Partition tolerance is essential for practical distributed databases
    2. Distributed systems must choose trade-offs among consistency, availability, and partition tolerance
    3. The CAP Theorem applies equally to centralized single-node systems
    4. All three CAP properties cannot be fully achieved at the same time in a distributed system

    Explanation: The CAP Theorem is specifically about distributed systems dealing with network partitions, so it does not apply equally to single-node (centralized) setups. The other options correctly reflect the CAP Theorem's core principles regarding trade-offs and the necessity of partition tolerance.