NoSQL Databases
NoSQL Databases
By,
Dr. Zartasha Baloch
[email protected]
OBJECTIVES
In this lecture we will learn about:
❖ What is NoSQL
❖ Types of Databases
❖ Document oriented database
❖ Graph based database
❖ Column based database
❖ Key value database
UNDERSTANDING SQL AND NOSQL
DATABASES
When it comes to managing data, there are two main types of databases:
🢝 SQL
🢝 NoSQL.
While both types of databases are used to store and organize data, they differ in
their structure, scalability, and query complexity.
ACID transactions ensure data integrity, with properties that guarantee Atomicity,
Consistency, Isolation, and Durability.
🢝 Atomicity ensures that all parts of a transaction are completed or none are,
🢝 Consistency ensures that the database remains in a valid state before and after a transaction,
🢝 Isolation ensures that concurrent transactions do not interfere with each other, and
🢝 Durability ensures that once a transaction is committed, it will remain committed even if there is a
system failure.
5
CHALLENGES OF RDBMS
RDBMS assumes a well-defined structure of data and assumes that the data is
largely uniform.
It needs the schema of your application and its properties (columns, types, etc.)
to be defined up-front before building the application. This does not match well
with the agile development approaches for highly dynamic applications.
As the data starts to grow larger, you have to scale your database vertically, i.e.
adding more capacity to the existing servers.
6
KEY DIFFERENCES BETWEEN SQL AND
NOSQL DATABASES
The main differences between SQL and NoSQL databases include data structure, scalability, and
query complexity.
SQL databases are highly structured and use a strict schema to define the relationships between
tables. This makes them ideal for handling complex queries and supporting ACID transactions.
However, SQL databases can be less flexible than NoSQL databases, as changing the schema
can be time-consuming and difficult.
NoSQL databases, on the other hand, do not enforce a schema, and data can be added or
changed easily. This makes them ideal for handling large and varied data sets that require high
scalability and availability. However, NoSQL databases can be less suitable for complex queries,
as they do not have the same level of support for joins and other advanced query operations.
Ultimately, the choice between SQL and NoSQL databases depends on the specific needs of your
application. If you need to handle complex queries and require ACID transactions, a SQL
database may be the best choice. If you need to handle large and varied data sets with high
scalability and availability, a NoSQL database may be the way to go.
Type SQL database is generally classified as a Relational database While NOSQL database is known as non-relational or
1 i.e. RDBMS. distributed database.
Language As we already know SQL uses structured query language for its NoSQL database on other hand has dynamic schema for
CRUD operation which is defined as SQL. This makes SQL unstructured data.Data stored in this type of database is not
2 database to store data in more structured form and also structured and could be stored in either of forms such as
preferred for more complex operations which could get document-oriented, column-oriented, graph-based or organized
completed with complex SQL queries. as a KeyValue store. This syntax can be varied from DB to DB.
Scalability SQL database can extends its capacity on single server by In order to increase the capacity of NOSQL dbs we required to
increasing things like RAM, CPU or SSD i.e we can say that SQL install new servers parallel to the parent server i.e NOSQL dbs
3 DBs could be scalable in vertical as their storage could be could be scalable in horizontal and this made them more
increase for the same server by enhancing its storage preferable choice for large or ever-changing data sets.
components.
Internal implementation SQL follows ACID properties for its operations which is On other hand NOSQL is based on Brewers CAP theorem which
4 abbreviation of Atomicity, Consistency, Isolation and Durability. mainly focus on Consistency, Availability and Partition tolerance.
Performance and suited for SQL databases are best suited for complex queries but are not NoSQL databases are not so good for complex queries because
preferred for hierarchical large data storage. these are not as powerful as SQL queries but are best suited for
5
hierarchical large data storage.
Examples SQL dbs is implemented in both open source and commercial On other hand NOSQL is purely open source and MongoDB,
6 Database such as like Postgres & MySQL as open source and BigTable, Redis, RavenDB, Cassandra, Hbase, Neo4j, CouchDB
Oracle and Sqlite as commercial. are the main implementation of it.
10
BENEFITS OF NOSQL OVER RDBMS
Schema Less
🢝 NoSQL databases being schema-less do not define any strict data structure.
Scales Horizontally
🢝 In contrast to SQL databases which scale vertically, NoSQL scales horizontally by adding more servers and using
concepts of sharding and replication. This behavior of NoSQL fits with the cloud computing services such as Amazon
Web Services (AWS) which allows you to handle virtual servers which can be expanded horizontally on demand.
Better Performance
🢝 All the NoSQL databases claim to deliver better and faster performance as compared to traditional RDBMS
implementations.
Talking about the limitations, since NoSQL is an entire set of databases (and not a single database), the
limitations differ from database to database. Some of these databases do not support ACID transactions
while some of them might be lacking in reliability. But each one of them has their own strengths due to
which they are well suited for specific requirements.
11
WHAT D O NOSQL DATABASES HAVE IN COMMON?
Each NoSQL database has its own unique features. At a high level, many NoSQL
databases have the following features:
The key of a key/value pair is a unique value in the set and can be easily looked
up to access the data.
Key/value pairs are of varied types: some keep the data in memory, and some
provide the capability to persist the data to disk.
A simple, yet powerful, key/value store is Oracle’s Berkeley DB.
14
KEY VALUE DATABASES
Key-value databases are the simplest type of NoSQL database.
These NoSQL databases have a dictionary data structure that consists of a set of
objects that represent fields of data.
🢝 Each object is assigned a unique key.
🢝 To retrieve data stored in a particular object, you need to use a specific key.
🢝 In turn, you get the value assigned to the key. This value can be a number, a string, or even
another set of key-value pairs.
23
COLUMN BASED DATABASES
24
25
COLUMN BASED DATABASES
26
GRAPH BASED DATABASES
A graph database uses graph structures with nodes, edges, and properties to
represent and store data. By definition, a graph database is any storage system
that provides index-free adjacency.
This means that every element contains a direct pointer to its adjacent element
and no index lookups are necessary.
General graph databases that can store any graph are distinct from specialized
graph databases such as triple-stores and network databases.
Indexes are used for traversing the graph.
Some examples include Amazone Neptune, Neo4j, OrientDB, and RedisGraph.
27
28
GRAPH BASED DATABASES
29
POPULAR NOSQL DATABASES
Let us summarize some popular NoSQL databases that falls in the above
categories respectively.
Document Oriented Databases − MongoDB, HBase, Cassandra, Amazon
SimpleDB, Hypertable, etc.
Graph Based Databases − Neo4j, OrientDB, Facebook Open Graph, FlockDB,
etc.
Column Based Databases − CouchDB, OrientDB, etc.
Key Value Databases − Membase, Redis, MemcacheDB, etc.
30
CAP THEOREM
❖ It can be used to explain some of the competing requirements in a distributed
system with replication.
❖ a distributed system can deliver only two of three desired characteristics:
consistency, availability, and partition tolerance (the ‘C,’ ‘A’ and ‘P’ in CAP).
❖ Basically Available: Guarantees the availability of the data . There will be a response to
any request (can be failure too).
❖ Soft state: The state of the system could change over time.
❖ Eventual consistency: The system will eventually become consistent once it stops
receiving input.
❖ NoSQL databases give up the A, C and/or D requirements, and in return they improve
scalability.
DEPARTMENT OF COMPUTER SYSTEMS ENGINEERING, MUET JAMSHORO. 35
CONCLUSION
In this lecture, we learnt about what NoSQL database technology is and how it
primarily differs from a RDBMS implementation. We then explored various
types of NoSQL databases, their applications and some of the most popular
databases of each type.
A lot of organizations today are adapting to such databases for their huge
datasets and high-scale applications. This shows that NoSQL is definitely going
to be the next big thing in web and database technologies which has the
potential to break the years long legacy of RDBMS.
53