0% found this document useful (0 votes)
6 views14 pages

Understanding CAP Theorem in NoSQL Systems

The CAP theorem outlines the limitations of distributed systems, stating that it's impossible to guarantee consistency, availability, and partition tolerance simultaneously. NoSQL databases adopt various combinations of these properties, leading to different types like document-based, key-value, column-oriented, and graph databases, each with unique characteristics. Major business drivers for NoSQL include the need for scalability, high-speed data processing, flexible schema requirements, and rapid adaptation to change.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views14 pages

Understanding CAP Theorem in NoSQL Systems

The CAP theorem outlines the limitations of distributed systems, stating that it's impossible to guarantee consistency, availability, and partition tolerance simultaneously. NoSQL databases adopt various combinations of these properties, leading to different types like document-based, key-value, column-oriented, and graph databases, each with unique characteristics. Major business drivers for NoSQL include the need for scalability, high-speed data processing, flexible schema requirements, and rapid adaptation to change.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

NoSQL

What is CAP Theorem? How it is applicable to NOSQL systems?


The CAP theorem, also called Brewer’s Theorem, is a fundamental principle in distributed
systems. It states that in a distributed data store, it is impossible to simultaneously
guarantee all three of the following properties:
CAP theorem states that there are three basic requirements which exist in a special relation
when designing applications for a distributed architecture.
Consistency –

• This means that the data in the database remains consistent after the execution of an
operation.
• For example, after an update operation all clients see the same data.
Availability –

• This means that the system is always on (service guarantee availability), no


downtime.
Partition Tolerance –

• This means that the system continues to function even the communication among the
servers is unreliable i.e., the servers may be partitioned into multiple groups that
cannot communicate with one another.
In theoretically it is impossible to fulfil all 3 requirements. CAP provides the basic
requirements for a distributed system to follow 2 of the 3 requirements. Therefore, all the
current NoSQL database follow the different combinations of the C, A, P from the CAP
theorem.
Here i is the brief description of three combinations CA, CP, AP:

• CA - Single site cluster, therefore all nodes are always in contact. When a partition
occurs, the system blocks.
• CP -Some data may not be accessible, but the rest is still consistent/accurate.
• AP - System is still available under partitioning, but some of the data returned may be
inaccurate.
The use of the word consistency in CAP and its use in ACID do not refer to the same
identical concept.
Describe characteristics of a NoSQL database
Characteristics of NoSQL Databases
1. Non-Relational:
Unlike traditional RDBMS, NoSQL databases do not follow the relational model of
rows, columns, and fixed schemas. They use flexible models like key-value,
document, column-family, and graph.
2. Open Source & Cost-Effective:
Most NoSQL databases are open source, requiring no heavy licensing fees, and can
run efficiently on inexpensive commodity hardware.
3. Schema-Free / Flexible Schema:
NoSQL databases are schema-free or schema-relaxed, allowing storage of structured,
semi-structured, and unstructured data without rigid table definitions.
4. Simple API Access:
They provide simple APIs for data access and manipulation, often using standard
programming languages instead of complex SQL.
5. Distributed & Scalable:
NoSQL databases are designed to run on distributed systems. They support automatic
partitioning, replication, and fail-over with high scalability (horizontal & vertical
scaling).
6. High Scalability & Performance:
Optimized for handling large-scale data and real-time workloads, making them
suitable for big data applications, IoT, and large-scale web apps.
7. Flexible Data Models:
Support for multiple data models such as Key-Value stores, Document stores,
Column-family databases, and Graph databases, enabling flexible and efficient
data representation.
8. Relaxation of ACID Properties:
To achieve higher scalability and performance, NoSQL databases often relax strict
ACID (Atomicity, Consistency, Isolation, Durability) rules. Instead, they rely on
BASE (Basically Available, Soft state, Eventual consistency).
9. Eventual Consistency:
Instead of strict immediate consistency, many NoSQL databases use eventual
consistency, meaning data will synchronize across nodes after some time.
10. High Availability:
Designed with features like replication, load balancing, and automatic failover,
ensuring minimal downtime and maximum uptime.
11. Low Latency:
Optimized for fast reads and writes, making them highly suitable for real-time
applications.

Difference between RDBMS and NoSQL


List and Explain the core business drivers behind the NoSQL movement
Major Business Drivers for NoSQL Databases
The rapid growth of Big Data and the limitations of traditional RDBMS have led to the
adoption of NoSQL databases. There are four major business drivers behind this shift:
1. Volume (Scalability of Large Data)
• Traditional RDBMS struggle to handle massive data volumes.
• Earlier, performance was improved by faster processors (scale up). But due to the
power wall (limit on CPU speeds because of overheating), the industry moved to
scale out (horizontal scaling).
• NoSQL databases allow data to be distributed across clusters of commodity
hardware, making them ideal for big data storage and processing.
2. Velocity (High-Speed Data Processing)
• Businesses today need to process real-time data with high read/write throughput
(e.g., social media, IoT, e-commerce).
• RDBMS indexing and schema rigidity often slow down performance during high-
traffic workloads.
• NoSQL databases are optimized for fast ingestion and retrieval of data, supporting
real-time analytics and web-scale applications.
3. Variability (Flexible Schema Requirements)
• Traditional RDBMS use rigid schemas, which create challenges when data structures
change frequently.
• Adding new fields (ALTER TABLE) in RDBMS can cause downtime and high costs.
• NoSQL databases provide schema-free or schema-flexible models, allowing
businesses to easily store diverse, semi-structured, and unstructured data (e.g.,
JSON, XML).
• This flexibility helps organizations capture custom data fields without affecting
overall availability.
4. Agility (Rapid Adaptation to Change)
• Modern applications need agility in terms of scaling, operations, and development.
• RDBMS-based applications often require an ORM (Object-Relational Mapping)
layer, which makes development complex and slow.
• NoSQL databases simplify development by directly supporting nested, hierarchical,
and unstructured data models, reducing overhead.
• They also support elastic scalability, enabling systems to quickly handle more users,
data, and connections.

Write a short Notes on different Architecture Pattern in No SQL Database


[Key value Store, Column store, Document database base, Graph database]
or Explain NoSQL architecture patterns.
Types of NoSQL Databases
NoSQL (Not Only SQL) databases are non-relational databases designed for handling
large-scale, unstructured or semi-structured data. They provide high scalability, flexible
schema, and faster data access, making them suitable for big data, real-time analytics,
distributed systems, and cloud applications.
The major types of NoSQL databases are as follows:

1. Document-Based Databases
• Definition:
Document databases store data in the form of documents rather than rows and
columns. These documents are commonly formatted as JSON, BSON, or XML.
• Explanation:
Each document contains key-value pairs and can represent complex hierarchical data.
Documents are grouped into collections, but unlike relational databases, there is no
fixed schema, so documents in the same collection may have different structures.
• Key Features:
o Flexible Schema: No need for a predefined schema.
o Faster Development & Maintenance: Easy to create and manage.
o No Foreign Keys: Documents are independent of each other.
o Open Formats: Uses JSON, BSON, or XML for compatibility.
• Examples & Use Cases:
o MongoDB: Content management, product catalogs, user profiles.
o CouchDB: Offline-first applications, mobile synchronization.
o Firebase Firestore: Real-time chat apps and collaborative apps.

2. Key-Value Stores
• Definition:
A key-value store is the simplest form of NoSQL database that stores data as a
collection of key-value pairs, where the key is unique and directly retrieves the
value.
• Explanation:
Values can be simple (string, number) or complex (JSON objects, lists). Since
retrieval happens through the key, queries are extremely fast. It behaves like a hash
table or dictionary.
• Key Features:
o Simplicity: Very easy to understand and use.
o High Scalability: Supports distributed storage and horizontal scaling.
o Speed: Ideal for caching and real-time applications.
• Examples & Use Cases:
o Redis: Session storage, leaderboards, real-time caching.
o Memcached: In-memory caching for high-speed performance.
o Amazon DynamoDB: Cloud-based, highly scalable applications.
3. Column-Oriented Databases
• Definition:
Column-oriented databases store data in columns instead of rows, which makes them
efficient for analytical queries and aggregation operations.
• Explanation:
Since only required columns are read (instead of entire rows), memory and I/O usage
are reduced. These databases are widely used in big data and analytics applications
where performance and scalability are critical.
• Key Features:
o High Scalability: Handles large, distributed datasets efficiently.
o Efficient Compression: Columnar storage reduces memory space.
o Faster Query Performance: Best for analytical queries and data mining.
• Examples & Use Cases:
o Apache Cassandra: IoT applications, real-time analytics.
o Google Bigtable: Time-series data, large-scale ML tasks.
o HBase: Works in the Hadoop ecosystem for distributed storage.
4. Graph-Based Databases
• Definition:
A graph-based database stores data as nodes (entities) and edges (relationships). It
focuses on relationships between data items, which are as important as the data itself.
• Explanation:
Graph traversal algorithms make it possible to explore relationships quickly. This type
of database is highly useful where data is interconnected, such as social networks,
recommendation engines, and fraud detection.
• Key Features:
o Relationship-Centric Storage: Optimized for relationship-heavy data.
o Real-Time Query Processing: Provides near-instant query results.
o Schema Flexibility: Can easily adapt to evolving relationships.
• Examples & Use Cases:
o Neo4j: Social networks, fraud detection.
o Amazon Neptune: Knowledge graphs, AI-based recommendations.
o ArangoDB: Multi-model database used in cybersecurity.
Describe the four ways by which Big Data problems are handled by NoSQL
systems
NoSQL systems are specially designed to handle large-scale, distributed, and unstructured
data. They use several techniques to improve performance, scalability, and fault tolerance.
The four major techniques are:

1. Moving Queries to the Data (Not Data to Queries)


• Concept: Instead of transferring large amounts of data to a central processor, NoSQL
systems send the query directly to the nodes where data is stored.
• Why?
o In RDBMS, data from multiple nodes must be moved across the network,
serialized, transmitted, and then compared. This causes delay.
o In NoSQL, only the query and final result move across the network → much
faster.
• Benefit:
o Minimizes network traffic.
o Increases query performance.
• Example: MongoDB and Cassandra allow queries to be executed locally on the node
where data resides.

2. Using Hash Rings for Even Data Distribution


• Concept: Data in NoSQL is divided across many nodes using a hashing technique
called consistent hashing or hash rings.
• How it works:
o Each data item (document/key) is assigned a random hash value (e.g., 40-
character key).
o Hash ring decides which node stores that data.
o As new nodes are added, hash ranges are reassigned automatically.
• Benefits:
o Ensures even load balancing.
o Easy scalability → just add a new node, and keys get redistributed.
o Provides fault tolerance → same data can be stored on multiple nodes
(replication in hash ring).
• Example: Apache Cassandra and Amazon DynamoDB use consistent hashing.

3. Using Replication to Scale Reads


• Concept: Replication means maintaining multiple copies of the same data on
different nodes.
• How it helps:
o When multiple clients send read requests, they can be distributed to different
replicas → increases read throughput.
o Provides fault tolerance: if one node fails, another replica can serve data.
• Challenge:
o Sometimes inconsistent reads occur (if replica is not updated immediately
after a write).
• Solution:
o Read from the primary write node immediately after a write.
o Or handle consistency at the application layer.
• Benefit:
o High availability.
o Horizontal scaling of read queries.
• Example: MongoDB replica sets, Cassandra replication.

4. Database-Driven Query Distribution


• Concept: NoSQL databases themselves manage the distribution of queries across
multiple nodes instead of leaving it to the application.
• How it works:
o A query is broken into smaller sub-queries.
o Each sub-query is sent to the data node holding relevant data.
o Results are aggregated and sent back to the client.
• Comparison: Similar to federated search, where a single query is distributed across
multiple systems and results are merged.
• Benefits:
o Better query performance.
o Application developers don’t need to worry about query distribution logic.
• Example: Couchbase and Cassandra handle distributed queries internally.

You might also like