SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
  • Relational Databases
  • Document Databases
  • Key-Value Databases
  • Full-Text Search Engines
  • Wide Column Databases
  • Time Series Databases
  • Graph Databases
  • Vector Databases
  • NewSQL Databases
  • Columnar Databases
  • In-Memory Databases
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Data and Storage/Database Types (Deep Dive)

NewSQL Databases

SQL and transactions like a classic database, with scale-out like NoSQL (Spanner, CockroachDB).

⏱ 14 min readAdvancedInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

A NewSQL database keeps what people like about a classic database (SQL and safe ACID transactions) and adds what they like about NoSQL: it can grow across many machines and survive failures.

  • The data is split into pieces (shards or ranges) automatically, and every piece is copied to several machines.
  • The copies agree with each other using a consensus method such as Raft or Paxos, so a write is safe once a majority has it.
  • A transaction that touches several pieces uses a commit protocol (like two-phase commit), so it is still all-or-nothing.
  • The price: writes are slower than on one machine, especially when the copies are in different regions.

02Concept: What is it?

For many years you had two choices. A classic relational database (like PostgreSQL or MySQL on one big server) gives you SQL, joins and strong transactions, but one machine can only grow so far. A NoSQL database spreads over many machines easily, but often gives up joins or strong transactions to do it.

NewSQL is the attempt to get both. You still write SQL and still get "all or nothing" transactions. Under the surface, the table is cut into ranges of rows. Each range is stored as a small group of copies (often three or five). One copy is the leader. A write goes to the leader, which sends it to the followers and waits until a majority has stored it. Then it is committed.

If one machine dies, the other copies still hold the data and choose a new leader. No committed write is lost, and the database keeps answering, as long as a majority of each group is alive.

Classic database vs NewSQL
Classic relational
👩‍💻SQL
↓
🗄️One big servergrow by buying a bigger one
NewSQL
👩‍💻SQL
↓
Range A
🖥️leader
🖥️copy
🖥️copy
Range B
🖥️copy
🖥️leader
🖥️copy
The same SQL on top. The difference is underneath: many machines, with every piece replicated by consensus.
🧠NewSQL is not magic
It does not break the CAP rules. When the network splits, a NewSQL database chooses consistency: the side without a majority stops accepting writes. What you get is a good, practical balance, not a free lunch.

03Real-Life Example

🍵A Bank with Many Branches and One Rule Book
Imagine a bank with branches in three cities. Every account page is written in a ledger, and three copies of each ledger are kept in three different branches. To record a payment, the head clerk of that ledger writes it down and phones the other two. Only when at least two of three have written it down does the clerk say "done". If one branch burns down, the other two still agree on the whole history, and they pick a new head clerk. If a payment moves money between two ledgers, both clerks must agree to the same decision before it counts.
The bank
A NewSQL database
A ledger of account pages
A range (shard) of table rows
Three copies in three branches
Replicas of the range
The head clerk of a ledger
The leader of the range
“Done” only after two of three wrote it
Commit after a majority acknowledges (consensus)
A branch burns down, books still safe
A node fails, the data survives
A payment between two ledgers
A transaction across shards (commit protocol)
Phoning another city takes longer
Cross-region writes have higher latency
One write, step by step
📝SQL write
→↓
👑Leaderlogs the change
→↓send to copies
🖥️Followersstore and reply
→↓majority
✅Committed

04Why Do We Need It?

📈Scale out, not up
When data or traffic grows, add machines. You do not have to keep buying a bigger single server.
🧾Keep SQL and ACID
Developers keep joins, constraints and transactions, and avoid writing complex “fix it later” code in the app.
🛡️Survive failures
Every piece has several copies, so a machine, a rack or even a data centre can fail without losing committed data.
🌍Global apps
Copies can sit in several regions, so data stays safe if a whole region goes down, and can be placed near users.
🤖Less manual sharding
The database splits and moves ranges for you, so the app does not need its own sharding code.
🎯Strong consistency
Readers see the latest committed data, so money and inventory logic stays simple.
When you need real transactions and more room than one machine can give, NewSQL is built for that job.

05Where Do We Use It?

💳Payments and ledgers
Money moves must be exact and survive failures, at a size one server cannot hold.
🛒Large e-commerce
Orders, stock and payments need transactions, with traffic that keeps growing.
🎮Global games and apps
Player accounts and purchases that must be correct in every region.
🏢Replacing a sharded MySQL
Teams with hand-made sharding sometimes move to NewSQL to stop maintaining it.
📦Inventory systems
Many writers change the same counts, so correct transactions matter.
🔐Always-on services
Services that must not stop for a machine failure or an upgrade.
📝Note
Examples include Google Spanner, CockroachDB, TiDB and YugabyteDB. Each makes its own design choices, so read the current docs of the product you pick.

06Types / Parts / How It Works

The main building blocks

PartWhat it doesWhy it is there
Ranges (shards)The table is cut into pieces by key, and the database splits and moves them as data growsSo no single machine holds everything
Replication per rangeEvery range has several copies, often three or fiveSo a failure does not lose data
Consensus (Raft or Paxos)The copies agree on the order of writes. A write commits when a majority has itSo all copies tell the same story, even with crashes
Leader per rangeOne copy takes the writes and tells the othersGives a clear order and avoids conflicts
Distributed transactionsA commit protocol similar to two-phase commit across the ranges involvedSo a transaction touching several ranges is still all-or-nothing
Clocks and timestampsTransactions get timestamps so the database can order them. Some systems use special clock hardware or bounded clock uncertaintySo readers see a consistent snapshot
A write that touches two ranges
🧾Transactionupdate A and B
→↓prepare
🅰️Range Amajority stores it
🅱️Range Bmajority stores it
→↓commit
✅Both visible
Range A copies Range B copies
Each range commits with its own majority, and a commit step ties the two together.

How it compares

Classic relationalTypical NoSQLNewSQL
Query languageSQLOften its own APISQL
TransactionsStrong, on one nodeOften limited to one itemStrong, across nodes
Scale outHard (manual sharding)EasyBuilt in
Failure survivalNeeds extra set-upBuilt inBuilt in
Write latencyLowestLowHigher (consensus and cross-node commits)
VisualizerCommit a write: regions, shards and failuresSwitch between one region and three regions, touch one shard or two, then kill nodes (the leader, or followers) and see when the majority is lost.
Where do the copies live?
What does the write touch?
Which nodes die first?
Shard 1: 3 copies
🖥️N1leader
🖥️N2follower
🖥️N3follower

A write can commit: every shard it touches still has a majority.

Majority needed
2 of 3
per shard
Alive in shard 1
3
of 3
Consensus rounds
1
one shard
Write latency
4 ms
illustrative
One shard: the leader sends the change to its followers and waits until a majority (2 of 3) has it. That is one consensus round, about 4 ms here.

A simplified model. A round is 4 ms inside one region and 70 ms when the majority must be reached in another region. These numbers are illustrative, not measurements. Real systems also use leases, follower reads and other tricks.

07How to Use It / Steps / Implementation

Using a NewSQL database well

  1. 1
    Check you really need it
    If one well-sized database and a few read replicas will do, a simpler system is cheaper and faster. NewSQL is for data or availability needs that outgrow that.
  2. 2
    Design keys with care
    Rows are split by key. Avoid keys that grow in order (like a plain counter or timestamp) for every insert, or one range gets all the writes (a hot spot).
  3. 3
    Keep transactions small and local
    A transaction that touches one range commits faster than one that touches many. Group data that is used together under related keys.
  4. 4
    Place copies on purpose
    Choose where leaders and copies live. Keeping the majority close to your users cuts the write latency a lot.
  5. 5
    Plan for retries
    Under heavy contention a transaction may be aborted and must be retried. Write the app so a retry is safe.
  6. 6
    Test failures
    Kill a node and a zone in a test. Check that latency, errors and recovery look the way you expect.
  7. 7
    Watch the numbers
    Track commit latency, retries, range hot spots and replica health, not only CPU.
💡Read from nearby, write with care
Many NewSQL systems offer slightly stale reads from the nearest copy for speed. Use them for screens that can be a few seconds old, and keep the strongest reads for the places that need them.
⚠️Do not expect single-node speed
A write needs a network round trip to a majority. Inside one data centre that can be a few milliseconds. Across continents it can be many times that. This is the physics of agreeing, not a bug.

08Key Terms to Know

TermMeaning in easy words
NewSQLA database that offers SQL and ACID transactions together with horizontal scaling
Range / shardA slice of a table, stored and replicated as one unit
ReplicaOne copy of a range, stored on one node
LeaderThe replica that takes writes for a range
ConsensusA method (Raft, Paxos) for copies to agree on the same order of writes
Majority (quorum)More than half of the copies. A write commits when a majority has it
Distributed transactionA transaction that changes data in more than one range or node
Two-phase commitA protocol where everyone prepares, then everyone commits or aborts together
Hot spotA range that gets far more traffic than the others
SerializableThe strongest isolation level: transactions behave as if they ran one after another
Geo-partitioningPlacing certain rows in chosen regions, for speed or for data-residency rules

09Pros, Cons and Trade-offs

✅ Pros
  • SQL and strong transactions at large scale
  • Automatic sharding and rebalancing
  • Survives node, rack and zone failures
  • Can span regions for resilience
  • Less custom sharding code in the app
⚠️ Cons
  • Higher write latency than a single node
  • More complex to run and to understand
  • Cost: several copies and more machines
  • Hot spots with badly chosen keys
  • Transactions may need retries
  • SQL compatibility is often partial, so check features you rely on

Trade-offs

ChoiceWe gainWe lose
More copies per rangeSurvives more failuresMore cost and a slower majority
Copies in many regionsSurvives a region outageSlow writes across regions
Copies in one regionFast commitsA whole-region failure is a big risk
Strong readsAlways the latest dataMust talk to the leader, so slower
Stale reads from nearbyFast readsMay show data a few seconds old
Transactions across rangesEasy app logicExtra rounds, so higher latency and more retries

10Common Problems and Mistakes

Common mistakes

  1. Choosing it too early. A small app on a distributed database pays the cost of complexity for no gain.
  2. Sequential keys. All new rows land in the last range, so one leader does all the work.
  3. Huge transactions. Touching many ranges makes commits slow and raises the chance of conflicts.
  4. Ignoring retries. The app must handle an aborted transaction and run it again safely.
  5. Spreading copies across the world without thinking. Every write now waits for a long round trip.
  6. Assuming full compatibility. Some SQL features, extensions or behaviours differ from PostgreSQL or MySQL.
  7. Treating it as free of CAP. During a partition, the minority side cannot write.

Things to watch

🔥Hot ranges
One range takes most of the traffic. Spread keys or split the range.
⏱️Clock uncertainty
Ordering across nodes relies on clocks. Keep clocks in sync and know your product's rules.
🔁Leader changes
A failure causes a short pause while a new leader is chosen. Add retries and timeouts.
💸Cost
Several copies of everything, and often more nodes, add up.

11Real-World Examples

🌐Google Spanner
Google's globally distributed SQL database. It uses a clock design with bounded uncertainty to order transactions.
🪳CockroachDB
A PostgreSQL-compatible distributed database that replicates ranges with Raft.
🧩TiDB
A MySQL-compatible distributed database that separates compute from storage.
🚀YugabyteDB
A distributed SQL database with a PostgreSQL-compatible layer.
🏦Finance and fintech
Ledgers and balances that need strong guarantees and growth.
☁️Cloud-managed offerings
Several providers offer managed distributed SQL so you do not run the cluster yourself.
📝Note
The details of each product change between versions. Treat the names above as examples, and read the current documentation before choosing.
Mini case: a payments service
📱App
→↓SQL
🧭Any noderoutes to the leader
→↓majority of 3
🇪🇺EU copy
🇺🇸US copy
🌏Asia copy
Data is placed near users, and a regional failure does not stop the service.

12Related Topics to Read Next

Relational Databases→

NewSQL keeps the relational model and SQL.

SQL vs NoSQL→

NewSQL tries to get the best of both sides.

ACID Transactions→

The guarantees NewSQL works hard to keep at scale.

Sharding→

NewSQL does the sharding for you, automatically.

Raft→

The consensus method many NewSQL systems use inside each range.

Two-Phase Commit (2PC)→

The idea behind transactions that span several ranges.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔What: SQL and ACID, with scale-out and failure survival built in.
  • ✔How: tables split into ranges, each replicated and agreed with Raft or Paxos.
  • ✔Commit: a write is safe once a majority of copies has it.
  • ✔Across shards: a two-phase-commit style protocol, with extra rounds.
  • ✔Failure: lose a minority, nothing breaks. Lose a majority, writes stop (consistency over availability).
  • ✔Cost: higher write latency, more nodes, more complexity.
  • ✔Tips: avoid sequential keys, keep transactions small, place copies near users, retry on abort.
  • ✔One line: “One SQL database on the outside, many agreeing copies on the inside.”
← Previous
Vector Databases
Next →
Columnar Databases