Skip to content

Relational vs. NoSQL

Introduction

Databases fall roughly into relational ones with a strict schema, and NoSQL tuned for specific scenarios; most products should start with relational.

Why think it through

The database is the hardest part of a system to replace. Bad code can be rewritten; bad data shapes mean moving millions of rows.

  • Relational (PostgreSQL, MySQL, SQL Server, and so on): data lives in tables linked by “relations”; they support transactions (a group of operations either all succeed or all fail—see transactions) and strong consistency. A good fit for orders, accounts, inventory, and similar business data.
  • NoSQL: an umbrella term. Common kinds include:
    • Document (MongoDB): stores whole JSON-like documents with a flexible shape.
    • Key-value (Redis): get/set by key, extremely fast, often used as a cache—see Redis.
    • Search (Elasticsearch): built for full-text search.

How to do it

  1. Default to PostgreSQL (or the MySQL / SQL Server your team already knows). It also supports JSON columns, which covers many “flexible shape” needs.
  2. Add NoSQL only with a clear reason: full-text search, ultra-fast caching, or data that is naturally “one whole document” with almost no relational queries.
  3. The common pattern is mixing: relational as the system of record, Redis for cache, a search engine for search—each does its job.

Component comparison

PostgreSQL

Self-hosted open sourceOpen sourceOpsMedium

A powerful open-source relational database, regarded as the "all-rounder".

Best forThe first choice for most new projects, especially those with complex business logic that need many kinds of data capabilities.

Avoid whenThe team only knows MySQL and the project is very simple, or there are existing systems strongly dependent on another database.

Pros

Rich features: full-text search, JSON columns, extensions and more

Very good support for complex queries and data integrity

Fully open source, with no licensing fees

Cons

Defaults are conservative, so production needs tuning

Some older tutorials and ops experience in China center on MySQL

Needs periodic maintenance such as VACUUM, and long neglect can hurt performance

Official docs ↗

MySQL

Self-hosted open sourceOpen sourceOpsMedium

The most widely used open-source relational database in China, with plenty of documentation and talent.

Best forRegular business systems, e-commerce, and projects where the team already has MySQL experience.

Avoid whenYou need complex analytical queries or lots of advanced features such as JSON/full-text search.

Pros

It is very widely used, with lots of material, experience, and hosted versions

Simple workloads read and write well, and the barrier to starting is low

The major clouds already offer a ready, mature managed service

Cons

Complex queries are less rich than in PostgreSQL

Engines and SQL modes differ, and a wrong setting can truncate data

Some editions belong to Oracle, so compatibility has to be checked

Official docs ↗

SQL Server

Commercial self-hostedSubscriptionOpsMedium

Microsoft's commercial database, most tightly integrated with the .NET / C# ecosystem.

Best forC# projects on an existing Microsoft stack, internal enterprise systems, or with licenses already purchased.

Avoid whenIndividual or startup projects with limited budgets, or stacks centered on Python.

Pros

It works smoothly with C#, EF Core, and the toolchain

The management tools are graphical, so day-to-day work is convenient

For enterprise use, the docs, the support, and the people are all there

Cons

Production use needs a purchased license, which costs more than open source

It can run on Linux, but the Windows ecosystem is the more familiar one

Outside the Microsoft stack, material and community are thinner

Official docs ↗

SQLite

Built into the frameworkOpen sourceOpsLow

One file is one database: no database service to install, and the program reads and writes the file directly.

Best forPersonal blogs, prototypes, local tools, small single-machine apps.

Avoid whenMany users write frequently at the same time, or multiple servers need to access the same database.

Pros

Zero deployment: one file is the whole database

Backup and moving it are just copying that one file

For a small project that reads much more than it writes, performance is enough

Cons

Only one writer can run at a time, so concurrent writes have to queue

Several servers cannot share the same database file

It lacks features such as stored procedures, so moving to another database takes extra work

Official docs ↗

MongoDB

Self-hosted open sourceFree tier + paidOpsMedium

A document database: data is stored as JSON-like documents, with no need to design a fixed table structure beforehand.

Best forData with varying structure, such as content management, logs and IoT data.

Avoid whenBusinesses like orders and payments that need strong consistency and complex relations; prefer a relational database.

Pros

When fields change often, adjusting the shape is convenient

Nested documents are intuitive to store and read, with fewer join tables

Sharding is already mature, which makes scaling out easier

Cons

Joins and transactions across collections are less natural than in a relational database

A structure that is too loose invites dirty data, so you have to constrain it yourself

The commercial license differs from pure open source, so read it when you choose

Official docs ↗

Checklist

  • Core business data lives in a relational database
  • Before introducing NoSQL, you can name a concrete reason a relational database cannot solve
  • Someone owns backups and restore drills for every database
  • Schema changes go through migrations