NO SQL IA-01_MICRO
NO SQL IA-01_MICRO
Weak support; relationships are typically Strong support with JOIN operations.
handled by the application.
MySQL, PostgreSQL, Oracle, SQL Server.
MongoDB, Cassandra, DynamoDB,
CouchDB.
Module -02
Sharding
o Itis storing the di erent parts of data onto di erent sets of data nodes, clusters
or servers. For example, university students huge database, on sharding divides
in databases, called shards. Each shard may correspond to a database for an
individual course and year. Each shard stores at di erent nodes or servers
o It Distributes di erent data across multiple servers so each server acts as the
single source for a subset of data
o Its Follows SN Architecture,Horizontal Scalability, Multiple server, Performance
Improves in SN Architecture , Large Data, Makes large data into small data in
separate Servers, Splitting Data Reduces Load on single server improves read
write performance
o Data Partitioning
Replication
o Replication is the process of copying and maintaining the same data on
multiple servers to improve availability, fault tolerance, and read performance.
o A primary (or master) server handles all write operations and replicates data to
secondary (or replica) servers.
o Secondary servers can handle read requests, while the primary focuses on
writes.
Advantages of Replication
o High Availability: If the primary server fails, a replica can take over (failover).
o Load Balancing: Read operations can be distributed among replicas, reducing
the load on the primary server.
o Data Redundancy: Reduces the risk of data loss due to hardware failure.
Draw Backs
o Consistency: Ensuring data is synchronized across replicas in real-time can be
challenging, especially in systems with eventual consistency.
o Write Bottleneck: Since only the primary handles writes, the system may face
bottlenecks under heavy write loads.
Combining Sharding and Replication
o Combining sharding and replication provides the best of both worlds:
scalability through sharding and reliability through replication.
o Each shard is replicated across multiple servers.
o Advantages
Scalability: Sharding allows the database to scale horizontally by
distributing data across shards.
High Availability: Even if a server within a shard fails, replicas ensure
the shard remains accessible.
Load Distribution: Sharding distributes write operations across shards,
while replication distributes read operations across replicas.
Fault Tolerance: Replicas ensure data redundancy, reducing the risk of
data loss within a shard.
Explain Update Consistency with respect to NOSQL taking suitable examples
o update consistency refers to how changes to data are handled and when they
become visible to users or applications. Unlike traditional relational databases,
which often prioritize strong consistency (ensuring updates are immediately
visible to all users), many NoSQL systems prioritize availability and partition
tolerance (as per the CAP theorem) over immediate consistency, opting for
eventual consistency instead.
o write-write conflict: two people updating the same data item at the same time.
o the server will serialize them—decide to apply one, then the other. Let’s
assume it uses alphabetical order and picks Martin’s update first, then
Pramod’s.
o Without any concurrency control, Martin’s update would be applied and
immediately overwritten by Pramod’s. In this case Martin’s is a lost update
o Approaches for maintaining consistency in the face of concurrency are often
described as pessimistic or optimistic.
o A pessimistic approach works by preventing conflicts from occurring; an
optimistic approach lets conflicts occur, but detects them and takes action to
sort them out.
o optimistic approach is a conditional update where any client that does an
update tests the value just before updating it to see if it’s changed since his last
read.
o In this case, Martin’s update would succeed but Pramod’s would fail
o Types of Update Consistency in NoSQL
Strong Consistency:Updates are immediately visible to all users and
systems.
Example: Banking Application
Eventual Consistency:Updates propagate to all nodes over time,
meaning some nodes may briefly hold stale data.
Example: E-Commerce Application
Tunable Consistency:Some NoSQL databases allow the user to choose
the level of consistency.
Example: Social Media Application
Read Consistency
o Read consistency refers to how up-to-date and accurate data is when it is read
from a NoSQL database, especially in distributed systems. NoSQL databases
o er di erent levels of read consistency based on how they balance
performance, availability, and consistency as per the CAP theorem.
o Ex: The danger of inconsistency is that Martin adds a line item to his order,
Pramod then reads the line items and shipping charge, and then Martin updates
the shipping charge. This is an inconsistent read or readwrite conflict
o Pramod has done a read in the middle of Martin’s write.
o We refer to this type of consistency as logical consistency: ensuring that
di erent data items make sense together. To avoid a logically inconsistent read-
write conflict, relational databases support the notion of transactions.
o Providing Martin wraps his two writes in a transaction, the system guarantees
that Pramod will either read both data items before the update or both after the
update.
o any update that a ects multiple aggregates leaves open a time when clients
could perform an inconsistent read. The length of time an inconsistency is
present is called the inconsistency window