0% found this document useful (0 votes)
2 views9 pages

No SQL

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

No SQL

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

NoSQL

 A database management system designed to handle and store large volumes of


unstructured and semi-structured data.
 It uses flexible data models unlike traditional relational databases and supports
horizontal scaling.
 Originally referred to "non-SQL" or "non-relational," now meaning "not only SQL,"
reflecting a broader range of database architectures.
When to Use NoSQL
 When managing large volumes of data that grows continuously.
 When relationships between data are not a key concern.
 When data is unstructured or semi-structured and evolves over time.
 When database-level support for constraints and joins is unnecessary.
 When high scalability and performance for large-scale data retrieval and storage are
required.
Advantages
 High availability
 High scalability
 flexibility
Disadvantages
 Lack of ACID compliance
 Lack of standardization
 Large document size
Cap theorem

The CAP Theorem says that in a distributed system, you can only guarantee two out of three
things:
1. Consistency (C): Every node sees the same data at the same time.
2. Availability (A): Every request gets a response, even if some parts of the system are
down.
3. Partition Tolerance (P): The system keeps working even if parts of it can’t
communicate with each other.
 CA: Guarantees consistency and availability, but no tolerance for network issues.
 CP: Guarantees consistency and partition tolerance, but may sacrifice availability.
 AP: Guarantees availability and partition tolerance, but may have inconsistent data
during network issues.
ACID Transactions (Simplified)
ACID is a set of rules that ensure data is handled correctly in a database, especially when
making changes.
1. Atomicity:
o Everything in a transaction happens together or nothing happens. If
something goes wrong, all changes are undone.
o Example: If you transfer money between accounts, it either happens fully or
not at all.
2. Consistency:
o The database must always be in a valid state. After a transaction, all rules (like
no negative balances) must be followed.
o Example: If a rule says no account can go below zero, the transaction won’t
complete if it causes that.
3. Isolation:
o Transactions don’t interfere with each other. Changes made in one
transaction are not seen by others until it's fully done.
o Example: If two people are transferring money at the same time, one’s
change won’t overwrite the other.
4. Durability:
o Once a transaction is completed, its changes are saved permanently, even if
the system crashes.
o Example: After you transfer money, the record stays in the system even if the
computer crashes.
ACID ensures data stays correct, safe, and consistent during transactions.
Aggregate Data models
 In NoSQL databases, aggregate data models refer to the way data is grouped or
organized into collections or units that are treated as a single entity for storage and
retrieval.
 This model is designed to improve performance and make it easier to handle
complex data structures.
Types of Data Models in NoSQL Databases
1. Column-Based Database

 Description:
o Stores data in tables with rows and flexible columns.
o Different rows can have different columns, making it highly adaptable.
o Uses compression for space-saving and improved speed.
o Suitable for retrieving large amounts of sparse data.
 Example:
o Apache HBase: A distributed database designed to handle large-scale data
quickly.
 Advantages:
o Highly efficient data compression and partitioning.
o Scalable and suitable for big data and data warehousing.
 Disadvantages:
o Inefficient for updates and deletions due to column-oriented storage.
o Slower performance for queries involving multiple attributes.
2. Document-Oriented Databases
 Description:
o Stores data in JSON-like documents containing field-value pairs.
o Supports complex and nested data structures, ideal for unstructured data.
 Example:
o MongoDB: A document-based database supporting replication and dynamic
schemas.
 Advantages:
o Flexible schema allows easy modification of data structures.
o Fast retrieval and storage of hierarchical data.
o Good for applications requiring varying or unstructured attributes.
 Disadvantages:
o No support for complex transactions across multiple documents.
o Relationships between data are not well-defined.
[Link]-Based Database
 Description:
o Stores data as nodes (entities like people or places) and edges (relationships).
o Designed to uncover patterns in highly interconnected data.
 Example:
o Neo4j: A popular graph database for analyzing complex relationships.
 Advantages:
o Excellent for traversing and querying relationships between data.
o Flexible schema for dynamic data models.
o Suitable for applications like recommendation engines and fraud detection.
 Disadvantages:
o Difficult to scale for large datasets.
o Lack of a standard query language.
[Link]-Value Databases
 Description:
o Simplest type of NoSQL database, storing data as key-value pairs.
o Optimized for fast data retrieval, commonly used for caching and session
management.
 Example:
o Amazon DynamoDB: A widely-used key-value database that popularized
NoSQL.
 Advantages:
o Extremely fast due to its simple structure.
o Easy to scale horizontally across distributed systems.
o No complex query optimization required.
 Disadvantages:
o Limited to basic operations like GET, PUT, and DELETE.
o No support for complex queries, joins, or foreign key constraints.
5. MongoDB
 Definition: Open-source document database with dynamic schema, high
performance, and scalability.
 Key Features:
o Stores data in BSON documents.
o Supports ad-hoc queries, replication, and sharding.
o Schema-less and JSON-like storage.
 Sharding Components:

o Shards (replicas): Store data and ensure consistency.


o Configuration Servers: Manage cluster metadata.
o Query Routers: Interface for applications to query data.
 Advantages:
o Flexible and schema-less.
o Easy to scale.
o Supports indexes and replication.
o Faster due to internal memory usage.
o Can function as a file storage system (GridFS).
 Disadvantages:
o Limited for complex transactional systems.
o No explicit database creation commands.
6. Schemaless Databases in NoSQL
Schemaless databases in NoSQL don't require a fixed structure or schema for storing data.
They allow data to be stored and retrieved without following a specific format, offering
flexibility for changing data over time.
How They Work
 Storage Types:
o On-the-disk: Uses B-Trees with the top stored in RAM.
o In-memory: Uses RB-Trees, with only data appends stored on disk.
 No Fixed Schema:
o No strict rules for data structure. The database adapts as needed.
Data Storage
 Data is stored in JSON-style documents where each document can have different
fields and data types.
o Example:
o {name: "Joe", age: 30, interests: 'football'}
o {name: "Kate", age: 25}
 Even though it's "schemaless," databases like MongoDB still have some structure
(e.g., collections and indexes).
Types of NoSQL Databases Supporting Schemaless Models
 Key-Value Store
 Document Store (e.g., MongoDB)
 Column-Oriented Database
 Graph Databases
Benefits
1. Flexibility
2. Scalability
3. Simplicity
Disadvantages
1. Inconsistencies
2. Management Complexity

You might also like