Legacy Archive (2013): Originally written in Chinese on doubixie.com and translated into English for this edition. All archive posts · Home

Deep Dive into NoSQL: Reading Notes

Original Chinese title: 深入nosql读书笔记

Section 1: NoSQL — Not Only SQL

A broad term for databases and data stores that do not follow classic RDBMS principles and are often associated with large, web-scale datasets.

An RDBMS assumes that data has a well-defined schema, is dense, and is largely consistent.

  • Big data: how much data counts as “big”?
    Right now, any dataset larger than a few terabytes can be classified as big data.

  • Sources of big data

    (1) Sensor data: Sensors distributed across different geographic locations continuously sense their environment and generate data. Even after filtering to keep only useful records, the volume accumulated over time is astonishing.
    
    (2) Website clickstream data: For effective marketing and promotion, every click a user makes online—along with its timestamp—is recorded. Using this data, service providers can carefully analyze user access patterns and deliver more targeted services.
    
    (3) Mobile device data: Through mobile electronics such as mobile phones, PDAs, and navigation devices, we can obtain information about the location, movement, and behavior of devices and people. Timely analysis of this data enables effective decision-making, such as in traffic monitoring and guidance systems.
    
    (4) RFID data: RFID tags can be embedded into products to track physical objects. Once RFID is widely adopted, it will become one of the primary sources of massive data.

Section 4

  • HBase column families

  • Column family: Some keys have highly sparse values while others behave differently; separating them into column families makes indexing easier and speeds up access.

  • Google’s main key themes:

    1. Data storage uses a distributed network file system so the system can scale across multiple machines. Files themselves can be very large and are stored across different nodes, each running on a separate machine.
    2. The storage structure should support multiple properties: efficiently storing massive sparse data and adapting to evolving schemas without modifying the underlying tables.
    3. The data processing model should support running computations on isolated subsets of data and then merging the results.
  • Column-oriented databases

    LRU algorithm (Least Recently Used)
    Consistent hashing
        Naive key assignment strategy: modulo function. E.g., assigning 50 keys to 7 nodes: key 18 goes to node 4 since 18 mod 7 = 4. Drawback: adding or removing a node forces keys to be reshuffled, which is very inefficient.
    With consistent hashing, adding or removing nodes does not cause a massive impact.
    Object versioning
    Vector clocks

Section 9: Transaction and Data Integrity Management

  • 9.1 ACID and RDBMS

    1. A (Atomicity): A transaction either succeeds completely or fails completely.
    2. C (Consistency): If predefined constraints or rules are violated, data will not be persisted.
    3. I (Isolation): Data concurrency—if two independent processes or threads operate on the same dataset, they can potentially affect each other.
    4. D (Durability): Once a transaction is committed, its persistence is guaranteed.
  • The strictness of the isolation level directly affects concurrency.

  • Using higher isolation levels increases the likelihood of starvation and deadlocks.

    Starvation occurs when one transaction locks resources needed by other transactions, while a deadlock occurs when two concurrent transactions are each waiting for the other to release resources.
  • Three factors affecting distributed systems

    1. Consistency (C): Means consistent reads and writes so that concurrent operations see the same valid, consistent state of the data—or at least never stale data.
    2. Availability (A): A system that is busy, unreachable, or unresponsive when accessed is considered unavailable.
    3. Partition tolerance (P): Parallel processing and horizontal scaling, as opposed to scaling up and building massive supercomputers.
  • Vertical scaling vs. horizontal scaling (individual capability vs. team capability)

  • Fallacies of distributed computing (things developers take for granted that often don’t hold)

    1. The network is reliable.
    2. Latency is zero.
    3. Bandwidth is infinite.
    4. The network is secure.
    5. Topology doesn't change.
    6. There is one administrator.
    7. Transport cost is zero.
    8. The network is homogeneous.
  • The three pillars of Brewer’s theorem, which encapsulates the thinking on transaction integrity for this generation of large, scalable distributed systems.

    A distributed system cannot simultaneously guarantee all three properties. The system must make trade-offs, sacrificing at least one to achieve the other two.
  • Gilbert and Lynch’s proof

  • Trade-offs to make

    • Traditional RDBMSs compromise availability, choosing consistency and partition tolerance

      For example, bank transfers.
      In extreme cases, the entire system may become completely unavailable after a node fails.
      In many cases, systems support backups, fast replication, and failure recovery.
    • Compromising partition tolerance, choosing consistency and availability

      Difference between partition tolerance and fault tolerance:
      If a system cannot serve a partition isolated by the network, but can instantly fail over to other nodes, it is fault-tolerant, though not partition-tolerant.
      Classic example: Google Bigtable.
      Primary-replica model: when a failure occurs, ZooKeeper determines which is the primary partition and which is the replica. Based on that decision, all reads and writes are routed to the primary, while the replica switches to read-only until the issue is resolved.
      Bigtable and HBase store three copies of each dataset, so if one of the three copies fails or falls out of sync, consistency can be maintained through consensus.
    • Compromising consistency (weak consistency)

      Classic examples: still allowing orders when inventory is zero; Redis not returning 100% of requests.
  • R = read quorum, W = write quorum, N = number of nodes in the cluster

  • Three cases

    R + W > N: In the extreme case R + W = 2N, consistency is easy to establish because the read and write node sets overlap. In the extreme case the system is strictly consistent and can provide ACID.
    R = 1, W = N: Reads far outnumber writes. High read concurrency needs to be spread across every node in the cluster. For reads, each node is independent of the others; every write updates all nodes.
    R = N, W = 1: Writes far outnumber reads; data inconsistency is very high.
    R = W = Ceiling((N + 1) / 2): Roughly equal reads and writes; requires efficient election.
  • BASE (Eventually Consistent)

    Section 11

  • Operating on big data: methods and tools should run in parallel with as few interaction points as possible, while minimizing the volume of data transferred (to reduce I/O overhead).

Over