Background
Sections
IntroductionRequirements & Problem AnalysisConstraints & AssumptionsEstimation TechniquesFunctional vs Non-Functional RequirementsMoSCoW PrioritizationSystem Design FundamentalsArchitecture DiagramClass DiagramComponent DiagramData Flow Diagram (DFD)ER Diagram (Entity-Relationship Diagram)High Level Design (HLD)Low Level Design (LLD)Sequence DiagramState DiagramUse Case DiagramData StorageDocument StoresFile StorageGraph DatabasesIn-Memory DatabasesKey-Value StoresNewSQLNoSQL DatabasesObject StorageSQL Databases (RDBMS)Time-Series DatabasesWide-Column StoresDatabase ConceptsACID PropertiesCAP TheoremConsistency ModelsIndexingNormalization & DenormalizationReplicationSharding & PartitioningTransactions & Isolation LevelsScalabilityAuto-Scaling & ElasticityConsensus & Leader ElectionLoad BalancingReplication & Read ReplicasSharding & PartitioningVertical vs Horizontal ScalingAvailability & ReliabilityBackup & Data DurabilityCircuit BreakerData ConsistencyDisaster RecoveryFault Tolerance & FailoverGraceful DegradationHigh AvailabilityNetworkingCDNDNSFirewalls & VPNHTTP & HTTPSLoad Balancer & Reverse ProxyTCP/IP & UDPWebSocketsCachingCache InvalidationCache Read/Write PatternsCaching LayersEviction PoliciesRedis vs MemcachedMessaging & CommunicationDead-Letter QueueIdempotencyKafka vs RabbitMQ vs SQSMessage QueuesPub/SubCompute & ServicesAPI GatewayContainers & OrchestrationMonolith vs MicroservicesServerlessService DiscoveryService MeshWeb Server & App ServerAPI DesignAPI Versioning & IdempotencyAuthentication & AuthorizationGraphQLgRPCPaginationRate Limiting & ThrottlingRESTSecurityAuthentication & AuthorizationData PrivacyEncryptionInput Validation & InjectionOAuth2 & JWTSecrets ManagementXSS & CSRFStorage & File SystemsBackup & RetentionBlock vs File vs Object StorageData Lakes & WarehousesDistributed File SystemsEphemeral StorageObservability & MonitoringDistributed TracingHealth ChecksLoggingMetricsSLI, SLO, SLADesign PatternsBulkhead PatternCircuit Breaker PatternCreational PatternsRate Limiter PatternRetry PatternStructural & Behavioral Patterns

NewSQL

6 min read

In a Nutshell

NewSQL databases are the attempt to give you the best of both worlds: the SQL interface, joins, and ACID transactions of a relational database, combined with the horizontal scalability of NoSQL. Systems like Google Spanner, CockroachDB, and TiDB deliver on this promise — you get distributed transactions across multiple nodes and regions, with familiar SQL semantics. The trade-off is higher write latency (every write needs a consensus round across nodes) and greater operational complexity than a single-node SQL database.

2D minimalistic Venn diagram showing two overlapping circles: left circle labeled 'SQL' with features like ACID and joins, right circle labeled 'NoSQL' with features like horizontal scaling, and the overlap area labeled 'NewSQL' combining both

How It Actually Works

How NewSQL Achieves Both

Challenge How NewSQL Solves It
Horizontal scaling Data is automatically sharded (range or hash) across nodes
Distributed transactions Consensus protocols (Raft, Paxos) coordinate writes across shards
SQL interface Standard SQL — compatible with existing ORMs and tooling
Strong consistency Linearizable reads and serializable transactions by default
Fault tolerance Each shard is replicated (typically 3 replicas) with automatic failover

The Consensus Cost

The key trade-off of NewSQL is write latency. Every write must:

  1. Be proposed to the shard leader
  2. Replicated to a majority of shard replicas (consensus)
  3. Acknowledged only after the majority confirms

In a single-region deployment, this adds 2–5ms per write. In a multi-region deployment (Spanner), each write involves cross-region round trips (50–200ms). This is why NewSQL write latency is measurably higher than a single-node PostgreSQL.

The Major Players

Database Key Innovation Backed By Best For
Google Spanner TrueTime (GPS + atomic clocks for global consistency) Google Cloud Global-scale applications needing strong consistency
CockroachDB Spanner-inspired, no special hardware needed Cockroach Labs Multi-region SQL without Google's infrastructure
TiDB MySQL-compatible, separates compute and storage PingCAP Drop-in MySQL replacement with horizontal scaling
YugabyteDB PostgreSQL-compatible, Spanner-inspired Yugabyte PostgreSQL workloads needing distributed SQL

When to Choose NewSQL

Use NewSQL when:

  • You need SQL + horizontal scaling (can't shard manually)
  • Your application requires distributed ACID transactions
  • You need multi-region deployment with strong consistency
  • You've outgrown single-node PostgreSQL/MySQL but can't give up SQL

Don't use NewSQL when:

  • A single PostgreSQL instance handles your load (don't over-engineer)
  • You can tolerate eventual consistency (use a simpler distributed database)
  • Write latency is your primary concern (single-node SQL is faster for writes)
  • Your data doesn't need relationships (use a NoSQL family instead)

2D minimalistic diagram showing a decision tree: Start → 'Need SQL?' → Yes → 'Outgrown single node?' → Yes → 'Need strong consistency?' → Yes → 'NewSQL', with alternative branches leading to PostgreSQL, NoSQL, and Eventual Consistency options

Seeing It in Action

Scenario: CockroachDB for a global e-commerce platform

-- CockroachDB looks like PostgreSQL
CREATE TABLE orders (
    id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id     UUID NOT NULL,
    total       DECIMAL(12, 2) NOT NULL,
    status      STRING NOT NULL DEFAULT 'PENDING',
    region      STRING NOT NULL,
    created_at  TIMESTAMP DEFAULT now()
);

-- Geo-partition orders by region (data stays close to users)
ALTER TABLE orders PARTITION BY LIST (region) (
    PARTITION us_east VALUES IN ('us-east'),
    PARTITION eu_west VALUES IN ('eu-west'),
    PARTITION ap_south VALUES IN ('ap-south')
);

-- Pin partitions to specific regions (data residency + low latency)
ALTER PARTITION us_east OF TABLE orders
    CONFIGURE ZONE USING constraints = '[+region=us-east]';
ALTER PARTITION eu_west OF TABLE orders
    CONFIGURE ZONE USING constraints = '[+region=eu-west]';

Why NewSQL is right here:

  • SQL interface — Existing application code and ORMs work with minimal changes
  • Geo-partitioning — US orders stored in US region, EU orders in EU region (GDPR compliance + low latency)
  • Distributed transactions — An order that spans multiple tables is ACID-consistent globally
  • Automatic failover — If a region goes down, replicas in other regions serve reads (with stale reads or rerouted writes)

Interview Questions

  1. Q: What problem does NewSQL solve that traditional SQL and NoSQL don't? Hint: Traditional SQL: doesn't scale horizontally (single-node bottleneck). NoSQL: scales but gives up SQL, joins, and ACID transactions. NewSQL: scales horizontally while keeping SQL and ACID — at the cost of higher write latency due to distributed consensus.

  2. Q: Why are NewSQL writes slower than single-node PostgreSQL writes? Hint: Each write requires a consensus round (Raft/Paxos) — the leader must replicate to a majority before acknowledging. In-region, this adds 2–5ms. Cross-region (Spanner), 50–200ms. Single-node PostgreSQL only needs to write to local WAL and fsync — much faster.

  3. Q: How does Google Spanner achieve global strong consistency? Hint: TrueTime — GPS receivers and atomic clocks in every datacenter provide tightly bounded clock uncertainty (~7ms). Spanner uses this to assign globally ordered timestamps to transactions without cross-region coordination for reads. Other NewSQL databases (CockroachDB) achieve similar results with NTP and hybrid logical clocks, at slightly higher uncertainty.

  4. Q: When would you recommend sticking with single-node PostgreSQL instead of migrating to CockroachDB? Hint: If the current load fits a single node (most applications), PostgreSQL is simpler, faster for writes, has a richer extension ecosystem, and costs less to operate. Migrate to NewSQL only when you genuinely need horizontal scaling, multi-region consistency, or have hit the limits of read replicas and partitioning.

  5. Q: How does NewSQL handle data partitioning differently from manually sharding a SQL database? Hint: NewSQL does it automatically — data is range-partitioned across nodes, and the system handles rebalancing, splitting, and merging as data grows. Manual sharding requires application-managed routing, no cross-shard joins, and manual rebalancing — all of which NewSQL abstracts away. The trade-off: NewSQL is operationally simpler but less flexible.

References

Dive Deeper