Tutorials › Core Cloud Architecture › Databases: Relational and NoSQL

Core Cloud Architecture · Part 6 of 13

Databases: Relational and NoSQL

The decision comes down to what your queries look like.

A database is where data goes once it needs to be queried, filtered, joined, and updated transactionally. Relational and NoSQL are the two families that cover most of that territory, and they organize data around different assumptions about how it will be read. A handful of more specialized categories exist because even NoSQL's sub-types don't fit every access pattern well.

Relational databases

A relational database organizes data into tables with a fixed schema (every row in a table has the same columns, of a declared type) and lets you combine data across tables at query time with a join. Queries are written in SQL, a declarative language for describing what data you want rather than how to fetch it.

Relational databases guarantee ACID transactions: a group of operations either all succeed or all roll back together (atomicity), the database moves between valid states only (consistency), concurrent transactions don't see each other's half-finished work (isolation), and a committed transaction survives a crash (durability). This matters where correctness can't be approximate: moving money between two accounts, decrementing inventory when an order is placed, anywhere "half of this happened" is a bug.

An index lets the database find matching rows without scanning the whole table, at the cost of extra storage and slightly slower writes; choosing what to index is one of the most consequential performance decisions in a relational schema. A read replica is a copy of the database kept in sync with the primary, used to serve read queries so the primary isn't the only thing handling load. Partitioning (or sharding) splits a large table across multiple underlying stores, which becomes necessary once a single database instance can't hold or serve the data volume. The cost is complexity: queries spanning partitions, and transactions across partitions in particular, get considerably harder.

NoSQL databases

NoSQL is an umbrella term covering several different data models that all relax the fixed-schema, join-everything-at-query-time relational approach in exchange for something else: one access pattern served far faster, or scale characteristics a single relational instance struggles with.

ConceptAWSGCPAzure
Managed relational (standard engines)RDSCloud SQLAzure SQL Database / Azure Database for PostgreSQL
Cloud-native relational, high scaleAuroraAlloyDBAzure SQL Database (Hyperscale)
Globally distributed, strong consistencyAurora DSQLSpannerNo direct equivalent
Key-value / documentDynamoDBFirestoreCosmos DB
Wide-columnKeyspaces (Cassandra-compatible)BigtableCosmos DB (Cassandra API)
Several of these products (Cosmos DB especially) support more than one data model behind a single service.

SQL vs. NoSQL: start from the access patterns

The common shorthand, "NoSQL is for when you need to scale," is misleading. Relational databases scale to enormous size in production, and a badly modeled NoSQL database can fall over at modest scale just as easily as a badly modeled relational one. What holds up is a decision made on how the data will be queried.

Start from the queries. Write down the questions the application needs to ask of its data, such as "find all orders for this customer," "find this document by its ID," or "total revenue by region last quarter," before picking a database family. A data model chosen to fit those queries will outperform and outlast one chosen because "NoSQL scales better," a claim that holds for some access patterns and fails for others.

Most production systems past a certain size end up using more than one database, each serving the access pattern it fits best: a relational database as the system of record, alongside a key-value store for session data or a document store for one subsystem. That's a deliberate architecture as long as every choice traces back to an access pattern someone can name.