0%

14. NoSQL

NoSQL

Non-relational databases

  • don’t enforce a predeifend structure on data
  • main families are: document, key-value, and graph
  • offer a lot of flexibility, but less guarantees

Document Databases

  • document looks like JSON
  • don’t need constraints
  • id: automatically generated
  • each document can be represented as a row, BUT document is document inside the collection!
  • structured to store big data
  • mongoDB
  • faster than SQL

Key-Value Databases

key-value pair

  • faster than any other dbs
  • set as a pair and get right away
  • used for caching
  • Redis
    You can run atomic operations on these types, like appending to a string;incrementing the value in a hash; pushing an element to a list; computing set intersection, union and difference; or getting the member with highest ranking in a sorted set.

To achieve top performance, Redis works with an in-memory dataset. Depending on your use case, you can persist your data either by periodically dumping the dataset to disk or by appending each command to a disk-based log. You can also disable persistence if you just need a feature-rich, networked, in-memory cache.
Redis also supports asynchronous replication, with very fast non-blocking first synchronization, auto-reconnection with partial resynchronization on net split.

Graph Databases

  • arrow: who follows whom
  • similar to ASCII Art
  • graph structure: map, social network

Relational vs. Non-relational

Dimension Relational Non-relational
Schema Predefined Flexible
Scaling Vertical Horizontal
ACID Yes No guarantees

In database systems, ACID (Atomicity, Consistency, Isolation, Durability) refers to a standard set of properties that guarantee database transactions are processed reliably. ACID is especially concerned with how a database recovers from any failure that might occur while processing a transaction.

  • Non-relational => covers the relational databases’ constraints
    SQL: MySQL is a relational database management system (RDBMS) from the Oracle Corporation. Like other relational systems, MySQL stores data in tables and uses structured query language (SQL) for database access. When MySQL developers need to access data in an application, they merge data from multiple tables together in a process called a join. In MySQL, you predefine your database schema and set up rules to govern the relationships between fields in your tables.

NoSQL: MongoDB is a NoSQL database that stores data as JSON-like documents. Documents store related information together and use the MongoDB query language (MQL) for access. Fields can vary from document to document - there is no need to declare the structure of documents to the system, as documents are self-describing. Optionally, schema validation can be used to enforce data governance controls over each collection.