System Design Academy

Saving…

Lesson 5 of 10 in Module 30 of 54 lessons complete

SQL vs NoSQL: How to Choose

Module 3, lesson 5Concept10 min

Definition

Access pattern

In plain English
An access pattern is the way your app reads and writes data: which questions it asks, how often and how fast.
Think of it like
It is like knowing whether a kitchen mostly bakes bread or fries chips before buying equipment.

Polyglot persistence

In plain English
Polyglot persistence means using different databases for different parts of one system.
Think of it like
It is like a kitchen with both an oven and a deep fryer.

Why it exists

You choose a fashionable database before listing your app’s questions. Later, a basic account transfer needs complicated extra work.

The same system can contain very different jobs. Billing and a stream of charger readings need separate evaluation.

How it works

  1. List the questions

    Write down reads, writes, related changes, and required response times.

  2. Estimate demand

    Count records and requests per second, including peaks.

  3. Choose a starting point

    Prefer one relational database until a measured need supports another choice.

  4. Check a real workload

    Test representative data, failure recovery, and operating effort before splitting stores.

A decision tree considers multi-record rules, key lookups, grouped writes, and relationship chains before suggesting a database family.

Use the questions to shortlist candidates, then measure them.

A decision tree considers multi-record rules, key lookups, grouped writes, and relationship chains before suggesting a database family.

QuestionRelational starting pointNoSQL candidates
StructureDeclared tablesShape depends on family
TransactionsBroad support for related changesSupport differs by product
New questionsSQL combines existing factsOften needs planned access paths
More writesTune, measure, then distribute if neededSome products distribute writes
Typical fitRelated business recordsSpecific shapes and access patterns

Examples

Separate billing from readings

Your 10,000 chargers report every five seconds. Drivers also need correct bills and account balances.

The driver app sends billing work to SQL, while chargers send measurements to a wide-column store.

Choose storage separately for billing and charger measurements.

The driver app sends billing work to SQL, while chargers send measurements to a wide-column store.

10,000 ÷ 5 gives 2,000 readings per second. Compare a relational design with a wide-column candidate before deciding.

The insight

Choose per part of the system, with evidence for each choice.

Trade-offs

Pros

  • Each workload can use a suitable model.
  • Specialized storage can remove a measured limit.

Cons

  • More systems need backups and recovery practice.
  • Data copied between stores can disagree.
  • Staff must understand more tools.

Use when

  • Different workloads have proven needs.
  • The team can operate every chosen store.

Avoid when

  • One store already meets demand.
  • A small team cannot maintain extra systems.

Quick check

Account balances that must never go negative and transfers between accounts. Best default?
What is the main cost of polyglot persistence?

Takeaways

  • Choose by access pattern, not fashion.
  • Default to relational when unsure.
  • Mix databases when a measured workload warrants the extra work.

Try the quick check above whenever you feel ready.

Previous: NoSQL Families