NoSQL databases: types and when to take them
Introduction
NoSQL is not “without SQL” but “not just SQL”: Bases without a hard tabular schemes sharpened for horizontal scaling and flexible structure data. Relational bases like PostgreSQL NoSQL is simpler and faster for some tasks.
Four types of NoSQL
Documentary (MongoDB): JSON-like documents, convenient for directories and profiles. Key-value (Redis): ultra-fast key storage, cache and sessions. Column (Cassandra): huge sparse tables and writing Millions of lines. Graph (Neo4j): Links as First Class Data Social graphs and recommendations.
When to take NoSQL
Three honest signals: the data structure changes more than once a quarter.
the load grows horizontally and it hurts to shard the relational base;
records are more important than complex joins (tapes, catalogs, telemetry).
A separate case is cache: Redis before
SQL
The database removes up to 90% of readings with one line of code.
And when SQL
Money, warehouse and anything that needs a transaction through multiple entities,
They remain behind relational bases. ACID, foreign keys and declarative
Queries are something that SQL has loved for fifty years.
Frequent working hybrid: SQL writing system, reading showcases
on NoSQL, between them queue or replication.
Modeling without tables
The main mistake of beginners to drag relational thinking: normalize
documents and collect them in joins on the application. Design from
One screen is one document, denormalization is the norm.
sin. Duplicate address in a thousand orders cheaper than a thousand joins
every show.
Version schema in code (field v: 2) to read old and new
Documents with one reader, and migrate lazily while recording.
Operation
Distributed databases require you to think about consistency in advance: eventual consistency means that the newly recorded is not visible to everyone Design the UI with this assumption. Monitor lag replication and growth of compacts, and backups remove from secondary nodes, so as not to strangle the master.