Databases
Relational versus non-relational databases
SQL (relational) | NoSQL (non-relational) |
---|---|
Tables / schema | Humongous data, collections, documents, duplication of data |
Structured | Semi/no structure, flexible |
Relations | Less dependence on relations, quick reads |
Atomic | Eventually consistent |
Monolithic | Distributed |
Scaling
- Horizontal: add more servers, difficult for SQL (cannot split relational databases)
- Vertical: add more resources
Considerations
- Consistency versus scale
- Internal versus public
SQL -- "Structured Query Language"
Relational databases are "Excel on steroids"
- MySql
- Oracle
- Sqlite
- Postgres
- MS-SQL
- Amazon Aurora (part of RDS)
PostgreSQL -- AKA Postgres
- psql
- pgAdmin
- MVCC -- Multiversion concurrency control
- Non-blocking indexes
- Partial indexes
- Normalisation
- ACID
- JSONB
Examples
SELECT -- id, name, price -- FROM -- product
SELECT -- fields -- FROM -- table
Commands
- INSERT
- JOIN
Every new row has the same fields: schema.
NoSQL - Not only SQL
- Two processes ensure that the distributed databases remain up-to-date and current: replication and duplication
mongoDB
mongoDB comes form "humongous". Instead of tables we have collections which contain documents -- looks a bit like JSON. Each document can use a different structure (schema). Generally there are no relations.
Less relation merging therefore fast queries. At the expense of duplication of data.
- Schema-less
- Big data
- Clusters
- Real time web applications
- Mongo shell
- BSON -- Binary JSON
- Sharding -- horizontal partitioning)
Types of NoSQL database
- Document database (mongoDB, CouchDB)
- Column databases (Apache Cassadra)
- Key-value (Redis, Couchbase Server)
- Cache system (Redis, Memcached)
- Graph DB (Neo4J)
ACID
- Atomicity
- Consistency
- Isolation
- Durability