Understanding NoSQL Databases and Architecture
Understanding NoSQL Databases and Architecture
NoSQL
Contents
3
◻ Introduction
◻ Business drivers
◻ NoSQL Data Architecture Pattern
Key-Value Store
Graph Store
Column Family store
Document Store
◻ NoSQL solution for Big Data
4
What is RDBMS
2
▪ Attributes
▪ Tuples Name
5
Issues with RDBMS- Scalability
3
NoSQL
◻Stands for Not Only SQL.
◻ “NoSQL is a set of concepts that allows the rapid and
efficient processing of datasets with a focus on
scalability, performance, reliability, and agility. “
❑ Provide mechanism for storage and retrieval of
unstructured data in distributed environment.
❑ Work for unpredictable dynamic data
❑ Developed to handle large amount of data that need to be
frequently accessed and processed.
2/5 marks
8
Need of
6
NoSQL
▪ Explosion of social media sites (Facebook, Twitter, Google etc.) with large data
needs.
▪ The system response time becomes slow when you use RDBMS for massive
volumes of data.
▪ Solution:
▪ "scale up" our systems by upgrading our existing hardware. This process is
expensive.
▪ "scaling out" is to
distribute database
load on multiple hosts
whenever the load
increases.
4 Marks
CAP Theorem
9
◻ Consistency –
All the servers in the system will have the same data so
anyone using the system will get the same copy
regardless of which server answers their request.
◻ Availability –
The system will always respond to a request (even if it's
not the latest data or consistent across the system or just
a message saying the system isn't working)
◻ Partition Tolerance –
The system continues to operate as a whole even if
individual servers fail or can't be reached..
10 Marks
◻ 1. Scalability
◻ 2. Big Data & Real-Time Analytics
◻ 3. Flexible Data Models
◻ 4. High Availability & Global Distribution
◻ 5. Support for Modern Applications
◻ 6. Cost Efficiency
◻ 7. Cloud & Micro services Architecture
NoSQL Business Drivers:
14
1. Scalability
Businesses with rapidly growing data volumes require systems that can handle
more data and more users without performance degradation.
NoSQL advantage:
Businesses evolve quickly; schema changes in relational databases are costly and time-consuming.
● NoSQL advantage:
Mobile apps, social networks, gaming platforms, IoT solutions require speed, scalability, and flexible data handling.
● NoSQL advantage:
6. Cost Efficiency
● NoSQL advantage:
● NoSQL advantage:
18
NoSQL Data Architecture Pattern
7
◻ Example:
Value
Key
Key-value stores (Cont.)
23
▪ Properties:
▪ Key may be a simple ID which is never used or seen
▪ Can query any value or content within the document
▪ Everything inside a document is automatically indexed when a new document is
added.
DB?
{ {
"name": "Phil", "age": 26,
"name": "Phil",
"status": "A",
"age": 26,
"citiesVisited" : ["Chicago", "LA", "San Francisco"]
"status": "A"
} }
❑ Documents can have differences in their attributes
❑ But belongs to the same collection
❑ A document can be
❑ PDF
❑ Microsoft word doc
❑ XML
❑ JSON file.
Document Store….eg.
38
Document Store
39
• Document stores can tell not only that your search item is in the
document, but also the search item’s exact location by using the
document path, a type of key, to access the leaf values of a tree
structure.
Document Store Basics
40
◻ Examples:
? MongoDB
? CouchDB
? DocumentDB
45
Use Case:An e-commerce platform (like Amazon, Flipkart, eBay) sells:
46
◻ Millions of products.
◻ Products from different categories — electronics, clothing, furniture,
groceries, etc.
◻ Each category has different attributes:
A shirt → size, color, fabric.
A laptop → CPU, RAM, storage, battery life.
A book → author, ISBN, publication year.
◻ With a relational database, you’d need:
◻ Separate tables for each category, or
◻ A huge table with many NULL columns for irrelevant attributes.
◻ Schema changes whenever a new product type is introduced.
47
• Content management :- Store web content and photos and use tools such as
geolocation indexes to find items.
• Real-time operational intelligence :-Ad targeting, real-time sentiment analysis,
customized customer-facing dashboards, and social media monitoring.
• Product data management :-Store and query complex and highly variable
product data.
• User data management :-Store and query user-specific data on highly scalable
web applications. Used by video games and social network applications.
• High-volume data feeds :-Store large amounts of real-time data into a central
database for analysis characterized by asynchronous writes to RAM.
54
Column family (Bigtable)
Overview
✔
stores Column family basics
✔
column
column
valu
row
e
key
Relational databases
56
table
column typ column type column type column typ column type
row e e
key value value value value value
row
Example rows: key value value value value value
„foo“, „bar“, 25, 35.63
„bar“, „baz“, 42, -673.342
Row vs. columnar relational databases
57
In row-oriented databases, row value data is usually
stored contiguously:
row0 header column0 value column1 value column2 value column3 value
row1 header column0 value column1 value column2 value column3 value
row2 header column0 value column1 value column2 value column3 value
Indexes
Key RowID Indexes on high-cardinality columns
1 0001B008D23A671A
2 0001B008D23A671B make accessing a single row very fast
3 0001B008D23A671C
Key Fname Lname State Zip Phone Age Sex
4 0001B008D23A671D
1 Bugs Bunny NY 11217 (718) 938-3235 34 M
5 0001B008D23A671E
2 Yosemite Sam CA 95389 (209) 375-6572 52 M ABC calls
3 Daffy Duck NY 10013 (212) 227-1810 35 M customer service
4 Elmer Fudd ME 04578 (207) 882-7323 43 M
WHERE key=4 5 Witch Hazel MA 01970 (978) 744-0991 57 F
column0 values
column0
r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 r16 r17
filesize
column1 values
column1
r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 r16 r17
filesize
Column-Oriented Storage
62
Column stores can greatly improve the performance of queries that only
touch a small amount of columns
This is because they will only access these columns' particular data
Simple math: table t has a total of 10 GB data, with
column a: 4 GB
column b: 2 GB
column c: 3 GB
column d: 1 GB
If a query only uses column d, at most 1 GB of data will be processed by a
column store
In a row store, the full 10 GB will be processed
Column family
64
◻ Each rows
contains different
number of
columns
Benefits of Column Family Systems
66
✔ Higher Scalability
✔ Higher Availability
✔ Easy to Update
Benefits of Column Family Systems ….Higher
67
Scalability
❑ Bigtable-inspired column family systems are designed to scale
beyond a single processor.
❑ As you add more data to your system, your investment will be in
the new nodes added to the computing cluster.
❑ By keeping the interface simple, the back-end system can
distribute queries over a large number of processing nodes
without performing any join operations.
❑ With careful design of row IDs and columns, the system get
enough hints to tell where to get related data and avoid
unnecessary network traffic crucial to system performance.
Benefits of Column Family Systems …. Higher
68
Availability
❑ By building a system that scales on distributed networks,
gain the ability to replicate data on multiple nodes in a
network.
❑ Due to efficient communication, the cost of replication is
lower.
❑ Due to lack of join operations allows you to store any
portion of a column family matrix on remote computers.
Benefits of Column Family Systems …. Easy to
69
Add New Data
❑ A key feature of the column family store is that you don’t need to fully
design data model before inserting data.
❑ Rules :
• Your groupings of column families should be known in advance.
• Row IDs and column names can be created at any time.
Benefits of Column Family Systems …. Easy to
70
Add New Data
❑ Row-oriented: Usually requires rebuilding table
Key Fname Lname State Zip Phone Age Sex Golf Addition of
1 Bugs Bunny NY 11217 (718) 938-3235 34 M Y
2 Yosemite Sam CA 95389 (209) 375-6572 52 M N column shifts
3 Daffy Duck NY 10013 (212) 227-1810 35 M Y
4 Elmer Fudd ME 04578 (207) 882-7323 43 M Y every row
5 Witch Hazel MA 01970 (978) 744-0991 57 F N
70
Benefits of Column Family Systems …. Easy to
71
Update
Row-oriented: value replaced
Key Fname Lname State Zip Phone Age Sex
1 Bugs Bunny NY 11217 (718) 852-2352 34 M
2 Yosemite Sam CA 95389 (209) 375-6572 52 M
3 Daffy Duck NY 10013 (212) 227-1810 35 M
4 Elmer Fudd ME 04578 (207) 882-7323 43 M
5 Witch Hazel MA 01970 (978) 744-0991 57 F
❑ Graph stores are ideal when you have many items that are related to each other in
complex ways and these relationships have properties.
Overview (Cont.)
78
❑ You’ll often see links on a page that take you to another page.
❑ These links can be represented by a graph or triple.
o The current web page is the first or source node Property: URL
o The link is the arc that “points to” the second page
o The second or destination page is the second node Source
web page
o”
“Poi
Source web page Destination web page
tt
oin
nt to
“P
”
Destination
web page Destination
web page
Property: URL
Property: URL
82
Linking external data
❑ When stored in a graph store, the two statements are independent and
may even be stored on different systems around the world.
Link metadata
✔ Group ID the graph belongs to
✔ The date and time the node was
created or last updated
Use cases for graph stores
83
❑ Link analysis is used when you want to perform searches and look for
patterns and relationships in situations such as social networking,
telephone, or email records.
❑ Rules and inference are used when you want to run queries on
complex structures such as class libraries, taxonomies and rule-based
systems.
❑ Integrating linked data is used with large amounts of open linked data
to do realtime integration and build mashups without storing data.
Link analysis
84
• Graph stores can perform these operations much faster by using techniques
that consolidate and remove unwanted nodes from memory.
• Though graph stores would clearly be much faster for link analysis tasks, they
usually require enough RAM to store all the links during analysis.
❑ Rules:
❑ That relate to an understanding of objects in a system, and how the
object properties allow you to gain insight into and better use large
datasets.
❑ An inference:
❑ discover other facts about a system
Rules and inference
87