1. Gyanastra
  2. Database Systems
  3. UGC NET: NoSQL
  4. NoSQL Concepts and Data Models
Free lesson, no account needed 12 min read 26 practice questions after it

Database Systems · UGC NET: NoSQL

NoSQL Concepts and Data Models

Overview

NoSQL means “Not Only SQL”: a family of non-relational database systems designed for large-scale, schema-flexible, distributed data.
The topic belongs to DBMS extras and tests the CAP theorem, BASE, the four major NoSQL data models, sharding, replication, quorum consistency, and graph traversal.
Before studying it, you should know the relational model, ACID properties, primary/foreign keys, joins, and the idea of a distributed system.
UGC NET asks direct definitions, comparisons, match-list items, statement-based questions, and small numeric quorum or hashing problems.

Key concepts

  • CAP theorem (Eric Brewer): a distributed data store cannot simultaneously guarantee Consistency, Availability, and Partition tolerance in the presence of a network partition.
    During a partition, a system must choose between CP (reject some requests to stay consistent) and AP (serve requests with possibly stale data).
    CA is possible only when there is no partition, effectively a single-node or non-partitioned system.
  • Consistency in CAP means all nodes see the same value at the same time, formally linearizability or atomic consistency. It is not the “C” of ACID, though related.
  • Availability means every request receives a non-error response, but not necessarily the latest value.
  • Partition tolerance means the system continues to operate despite arbitrary message loss or delay between nodes.
    In an asynchronous network, partitions are unavoidable, so partition tolerance is mandatory for a distributed store.
  • BASE stands for Basically Available, Soft state, Eventually consistent. It is the relaxed consistency model used by many NoSQL systems.
    Soft state means the stored state may change over time without new external input, because replicas are converging.
  • ACID stands for Atomicity, Consistency, Isolation, Durability. It gives strong transactional guarantees; BASE trades temporary inconsistency for availability and scale.
  • Eventual consistency guarantees that if no new updates are made, all replicas eventually converge to the same value. It does not guarantee when, and it does not prevent stale reads meanwhile.
  • Tunable consistency: client chooses N replicas per item, W write acknowledgements required, and R read replicas contacted. Strong consistency is possible when W + R > N.
  • Sharding or horizontal partitioning splits data across nodes by a shard key. Hash sharding uses s=hash(k) mod Ss = \mathrm{hash}(k) \bmod S; range sharding keeps ordered ranges. Consistent hashing reduces data movement when nodes join or leave.
  • Replication copies the same data item to N nodes for fault tolerance.
    Vector clocks detect concurrent updates and conflicts; hinted handoff temporarily stores writes for a down replica; read repair fixes stale replicas during a read.
  • The four major NoSQL data models:
    • Key-value store: unique key maps to an opaque value. Query only by key. Examples: Redis, Riak, DynamoDB. Good for sessions, caches, preferences.
    • Document store: key maps to a self-contained document such as JSON/BSON/XML, with nested fields and schema flexibility. Query by document fields. Examples: MongoDB, CouchDB, Couchbase.
      Good for catalogs, user profiles, content.
    • Column-family store (wide-column store): rows with sparse, sorted columns grouped into column families; a column family is roughly a table. Examples: Cassandra, HBase, Bigtable.
      Good for time-series, sensor data, large sparse datasets.
    • Graph store: nodes and edges with properties, using index-free adjacency. Examples: Neo4j, Amazon Neptune. Good for social networks, friend-of-friend, shortest paths, fraud detection.
  • Schema-on-read: the application interprets structure while reading, so inconsistent documents can coexist. Schema-on-write enforces the schema when data is written, as in relational DBMS.
  • Denormalization by embedding child records inside a parent document reduces the number of reads needed to assemble a result, but it duplicates data and makes updates to embedded children rewrite the parent document.

How it works

  1. CAP during a partition. A client writes to one node; the network divides the cluster into two groups. A CP system refuses the write or read on the minority side to avoid returning inconsistent data.
    An AP system accepts the request on both sides and later reconciles versions. The theorem does not say “pick any two at all times”; without a partition, a well-designed system can provide C and A.
  2. Quorum read and write. The coordinator sends a write to N replicas and waits for W acknowledgements. A read contacts R replicas and returns the version with the highest timestamp or vector clock.
    If W+R>NW + R > N, every write set and read set must intersect, so at least one read replica has the latest write, assuming enough replicas are live.
  3. Dynamo-style write with hinted handoff.
    1. Coordinator receives the write and computes the N responsible replicas, often by consistent hashing.
    2. Coordinator sends the write to all N replicas.
    3. If a replica is down, another node stores a hint, a temporary copy of the write.
    4. When the down replica recovers, the hint is delivered and applied. This keeps writes available but may weaken consistency until handoff completes.
  4. Read repair. During a read, the coordinator contacts R replicas, compares versions, returns the newest value, and writes it back to any stale replica. This repairs inconsistency lazily.
  5. Graph traversal. In a graph store, each node stores direct pointers to its incident edges and neighbouring nodes. One hop costs O(1)O(1) on average because no global index lookup is needed.
    A k-hop traversal costs O(k)O(k) per path, proportional to the visited subgraph, while a relational DBMS may need k joins and large intermediate results.
  6. Sharding example. With four shards, s=hash(k) mod 4s = \mathrm{hash}(k) \bmod 4. A key whose hash is 10 goes to shard 2, because 10 mod 4=210 \bmod 4 = 2. The same key always maps to the same shard.
Figure. If no partition occurs, the store can satisfy consistency and availability. If a partition occurs, it either stays consistent by rejecting some requests or stays available by serving possibly stale data.

Formulas

  • Quorum consistency rule: W+R>NW + R > N
    • NN = number of replicas per data item
    • WW = number of replicas that must acknowledge a write
    • RR = number of replicas contacted for a read
    • Strong consistency is possible when the inequality holds; if W+R≤NW + R \le N, a read set and write set can be disjoint, so a stale read is possible.
  • Hash sharding: s=hash(k) mod Ss = \mathrm{hash}(k) \bmod S
    • kk = key, SS = number of shards, ss = shard index from 0 to S−1S-1.

Worked examples

Example 1 — CAP choice. A distributed store is configured as CP. During a network partition, which guarantee is sacrificed? Step 1: CP keeps Consistency and Partition tolerance.
Step 2: To keep consistency, the system must reject some requests on one side of the partition. Step 3: Therefore Availability is sacrificed. Answer: Availability.

Example 2 — BASE acronym. Geeta uses an online shopping cart that remains available during a network partition but may show a slightly old item count. Expand BASE. Answer: Basically Available, Soft state, Eventually consistent. The cart tolerates temporary inconsistency and converges later.

Example 3 — minimum read quorum. A Dynamo-style store has N=5N = 5 replicas and W=3W = 3. Find the minimum RR for guaranteed strong consistency. Step 1: Use W+R>NW + R > N. Step 2: 3+R>53 + R > 5. Step 3: R>2R > 2, so the smallest integer is R=3R = 3.
Answer: Rmin⁡=3R_{\min} = 3. With R=2R = 2, 3+2=53 + 2 = 5, which is not greater than 5, so a read set of size 2 and a write set of size 3 can be disjoint.

Example 4 — equality is not enough. A store has N=5N = 5, W=2W = 2, R=3R = 3. Is strong consistency guaranteed by the standard quorum rule? Step 1: Compute W+R=2+3=5W + R = 2 + 3 = 5. Step 2: Compare with N=5N = 5. Step 3: The rule requires W+R>NW + R > N, but 5>55 > 5 is false.
Answer: No; a read may miss the latest write because the read set and write set can be disjoint.

Example 5 — sharding count. A key-value store is sharded across 4 nodes by hash(k) mod 4\mathrm{hash}(k) \bmod 4. Keys 10, 14, 18, 22 are inserted. How many distinct shards receive at least one key? Step 1: 10 mod 4=210 \bmod 4 = 2. Step 2: 14 mod 4=214 \bmod 4 = 2. Step 3: 18 mod 4=218 \bmod 4 = 2. Step 4: 22 mod 4=222 \bmod 4 = 2.
All four keys map to shard 2. Answer: 1 distinct shard.

Comparison

FeatureACIDBASE
Full formAtomicity, Consistency, Isolation, DurabilityBasically Available, Soft state, Eventually consistent
ConsistencyStrong, immediateEventual, temporary inconsistency allowed
AvailabilityMay reduce availability to protect consistencyFavours availability
Typical useBanking, billing, strict transactionsSocial feeds, catalogs, session stores, large-scale web data
NoSQL modelPrimary structural unitTypical queryExamplesIdeal use case
Key-valueKey → opaque valueGet/put by keyRedis, Riak, DynamoDBCache, session, preferences
DocumentKey → nested documentQuery on document fieldsMongoDB, CouchDBProduct catalog, user profile
Column-familyColumn family / row with sparse columnsRow key, column rangeCassandra, HBaseTime-series, sensor data, sparse tables
GraphNode and edge with propertiesMulti-hop traversal, shortest pathNeo4j, NeptuneSocial network, recommendation, fraud detection
System choiceBehavior during partitionCommon examples often cited
CPRejects some requests to keep consistencyHBase, MongoDB
APServes possibly stale data to stay availableCassandra, Riak, DynamoDB
ConceptMeaning
Vector clockVersion vector per node used to detect concurrent updates and conflicts
Hinted handoffTemporarily stores a write for an unavailable replica and delivers it later
Read repairOn read, compares replicas and writes the latest value back to stale replicas
Tunable consistencyClient chooses W and R per operation to trade consistency against latency
Scaling termMeaning
Horizontal scalingAdd more nodes; sharding and replication; scale-out
Vertical scalingAdd CPU, RAM, or disk to one node; scale-up
ShardingPartition different data across nodes
ReplicationCopy the same data to multiple nodes for fault tolerance

Revision summary

  • CAP: you cannot have C, A, and P together during a partition; partition tolerance is mandatory in a distributed network.
  • CP sacrifices availability; AP sacrifices immediate consistency.
  • BASE = Basically Available, Soft state, Eventually consistent.
  • Strong quorum needs W+R>NW + R > N; W+R=NW + R = N is not enough.
  • For N=5,W=3N=5, W=3, minimum R=3R=3; for N=3,W=2,R=2N=3, W=2, R=2, 4>34>3 so strong consistency is possible.
  • Key-value queries only by key; document stores query by document fields; column-family stores use row key and column ranges; graph stores traverse edges.
  • A column family in Cassandra is roughly a table.
  • Graph stores are fast for deep multi-hop traversal because of index-free adjacency.
  • Schema-on-read means the application interprets structure; it does not mean “no structure”.
  • Embedding child records reduces reads but can hurt write performance if the embedded collection is large and frequently updated.
  • Sharding splits data; replication copies data; they solve different problems.
  • Vector clock detects conflicts; hinted handoff handles down replicas; read repair fixes stale replicas.

Previous-year exam insights

  • UGC NET often asks a direct concept: expand BASE, state the three CAP guarantees, or identify the data model for nested catalogs, social networks, or sparse time-series data.
  • Statement I/II questions test whether W+R>NW + R > N is strict, whether CP sacrifices availability, and whether eventual consistency guarantees convergence only when updates stop.
  • Match List-I with List-II expects exact pairs: key-value with key lookup, document with JSON-like document, column-family with sparse wide rows, graph with multi-hop traversal.
  • Assertion–Reason questions test the embedding trade-off: embedding reduces reads because a document is fetched as a whole, but updates to embedded children rewrite the parent.
  • Numeric questions give N,W,RN, W, R and ask for minimum RR, or give N,W,RN, W, R and ask whether strong consistency holds.
    Always compute W+RW + R and compare strictly with NN.
  • Sharding questions use hash(k) mod S\mathrm{hash}(k) \bmod S; compute each remainder carefully and count distinct shards.
  • Order questions on Dynamo-style writes test the sequence: coordinator selects replicas, sends write, stores hint if a replica is down, delivers hint on recovery.
  • Common traps: calling CP “partition-tolerant and consistent but available”, treating W+R=NW + R = N as sufficient, confusing column family with graph, and assuming a key-value store can query inside an opaque value.

Practice at PARIKSHA

You are ready for the PARIKSHA tests of this sub-topic when you can:

  • State the CAP theorem and explain why a CP system sacrifices availability during a partition.
  • Expand BASE and compare it with ACID in a table.
  • Classify a given use case into key-value, document, column-family, or graph storage with a reason.
  • Compute the minimum read quorum RR for given NN and WW, and test whether W+R>NW + R > N holds.
  • Explain why graph databases traverse multi-hop relationships faster than relational joins.
  • Trace a Dynamo-style write with hinted handoff in the correct order.
  • Distinguish vector clocks, hinted handoff, and read repair.
  • Explain schema-on-read and the read-versus-write trade-off of embedding child documents.
  • Compute shard indices using hash(k) mod S\mathrm{hash}(k) \bmod S and count distinct shards.
  • Identify traps in statement, match-list, assertion-reason, and numeric questions on NoSQL.

Attempt the sub-topic test first, then the subject test.

Pages 1–2 of 2