SQL vs NoSQL: How to Choose
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
- List the questions
Write down reads, writes, related changes, and required response times.
- Estimate demand
Count records and requests per second, including peaks.
- Choose a starting point
Prefer one relational database until a measured need supports another choice.
- 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.
| Question | Relational starting point | NoSQL candidates |
|---|---|---|
| Structure | Declared tables | Shape depends on family |
| Transactions | Broad support for related changes | Support differs by product |
| New questions | SQL combines existing facts | Often needs planned access paths |
| More writes | Tune, measure, then distribute if needed | Some products distribute writes |
| Typical fit | Related business records | Specific 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.
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.
Keep a small system understandable
Your charity has 20,000 records and three staff. Donations, volunteers, and deliveries share one relational database.
Linked tables answer daily questions without moving data between stores. One backup and recovery process is easier to practise.
- Measure slow queries before adding another database.
- Keep operations manageable for the people available.
The insight
One well-understood database can serve a small team well.
Count the position writes
Your 2,000 robots each report position 25 times per second. The live map fetches the latest position by robot ID.
2,000 robots × 25 reports per second = 50,000 writes/s
Key: robot:42
Value: latest position and report time
Orders: related rows in the relational databaseA key-value store fits this lookup pattern. Test whether it meets peak demand and how it handles missing reports.
The insight
Let the workload estimate guide the 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
Takeaways
- Choose by access pattern, not fashion.
- Default to relational when unsure.
- Mix databases when a measured workload warrants the extra work.