Choosing a Database: SQL, NoSQL, Indexes and Storage Types

A decision guide for data stores: relational versus the NoSQL families (key-value, document, wide-column, graph), time-series, search and in-memory stores, reasons to choose SQL or NoSQL, polyglot persistence, the role of indexes, and block versus file versus object storage.

On this page

Simple definition#

There is no best database, only the best fit for a workload: the shape of the data, how it is queried, how much there is, how fast it changes, and which guarantees it needs. Choosing well means asking those questions first and naming the technology last.

SQL versus NoSQL#

SQL (relational)NoSQL (non-relational)
DataStructured rows and columns; one row is one entity, one column one attributeUnstructured or semi-structured; documents, key-values, wide rows, graphs
SchemaPredefined (schema-on-write)Dynamic (schema-on-read)
QueriesSQL, joins, ad-hoc queriesMostly by key or a predefined access pattern; limited joins
TransactionsACID, multi-rowOften single-item atomicity; some offer transactions
ScalingPrimarily vertical, plus read replicas; sharding is manual or via distributed SQLDesigned for horizontal scaling across commodity servers
ExamplesPostgreSQL, MySQL, MariaDB, Oracle, SQL ServerMongoDB, Cassandra, DynamoDB, Redis, Neo4j, HBase

Reasons to choose SQL#

  • You need ACID guarantees and integrity constraints — e-commerce orders, financial records — to reduce anomalies and protect data.
  • Your data is structured and stable, and the business is not facing sudden, massive growth in volume or variety.
  • You need flexible, ad-hoc queries and joins across entities.

Reasons to choose NoSQL#

  • You must store large volumes of data with little or no structure, or with varying attributes.
  • You want to make full use of cloud and commodity hardware, spreading data across many servers cheaply.
  • You need rapid development with evolving data shapes, or very high write throughput with predictable key-based access.

The NoSQL families and other specialised stores#

FamilyModelStrengthsExamplesTypical uses
Key-valueOpaque value by keyExtreme speed and scale, simple APIRedis, DynamoDB, Riak, etcdCaches, sessions, shopping carts, feature flags, rate-limit counters
DocumentJSON-like documents, indexed fieldsFlexible schema, locality for treesMongoDB, Couchbase, FirestoreCatalogues, user profiles, content
Wide-columnRows with dynamic columns grouped in families, partitioned and sortedMassive write throughput, time-ordered data per keyCassandra, ScyllaDB, HBase, BigtableMessaging, IoT, activity logs, time-series at scale
GraphVertices and edgesRelationship traversalsNeo4j, NeptuneSocial networks, fraud detection, recommendations
Time-seriesTimestamped measurementsCompression, downsampling, retentionInfluxDB, TimescaleDB, PrometheusMetrics, monitoring, sensors
SearchInverted indexFull-text relevance, facetingElasticsearch, OpenSearch, SolrProduct search, log search
Columnar (OLAP)Column-oriented storageAggregations over billions of rowsClickHouse, BigQuery, Redshift, SnowflakeAnalytics, reporting
NewSQL / distributed SQLRelational + horizontal scaling + consensusSQL and transactions at scaleCockroachDB, Spanner, YugabyteDB, TiDBGlobal transactional systems

See Data Models and Storage Engines for how these work internally.

A decision process#

A simplified database decision flow
flowchart TD
    A[New data store needed] --> B{Need multi-entity<br/>transactions and joins?}
    B -- yes --> C{Fits one primary<br/>with replicas?}
    C -- yes --> PG[Relational: PostgreSQL / MySQL]
    C -- no --> NS[Distributed SQL: CockroachDB / Spanner]
    B -- no --> D{Main access pattern?}
    D -- "by key, very fast" --> KV[Key-value: Redis / DynamoDB]
    D -- "documents, flexible fields" --> DOC[Document: MongoDB]
    D -- "huge write volume by partition key" --> WC[Wide-column: Cassandra]
    D -- "relationship traversal" --> G[Graph: Neo4j]
    D -- "full-text search" --> ES[Search: Elasticsearch]
    D -- "aggregations over history" --> OLAP[Columnar: ClickHouse / BigQuery]
    D -- "metrics over time" --> TS[Time-series: Prometheus / InfluxDB]

Questions to ask in an interview:

  1. What are the entities and relationships? (one-to-many trees vs many-to-many)
  2. What are the top queries, and their read/write ratio?
  3. What volume and growth? (estimate it)
  4. Which consistency is required for each operation? (see CAP and PACELC)
  5. What latency, availability and geographic distribution are required?
  6. What does the team already know how to operate?

Polyglot persistence#

Large systems use several stores, each for what it does best: PostgreSQL as the system of record, Redis for caching and rate limiting, Elasticsearch for search, a warehouse for analytics, object storage for files. Keep one system of record per piece of data and derive the others from it, ideally with change data capture, to avoid inconsistent dual writes. Each additional technology adds operational cost.

Indexes#

An index is a data structure that makes retrieval faster at the cost of extra storage and slower writes (every insert, update and delete must update every index). Indexes are well known from relational databases, but the same idea applies to any data set: a table of contents for large data spread across machines.

  • Index the columns used in WHERE, JOIN and ORDER BY of frequent queries; verify with EXPLAIN.
  • For write-heavy tables, keep indexes to a minimum.
  • Composite indexes follow the leftmost-prefix rule.

See Storage Engines: other indexing structures.

Block, file and object storage#

Not all data belongs in a database. Large binary content (images, videos, backups, logs) belongs in storage designed for it.

Block storageFile storageObject storage
UnitFixed-size blocks, raw volumeFiles in a hierarchical directory treeObjects (data + metadata) in a flat namespace with keys
AccessAttached to one server, formatted with a filesystem or used by a databaseNetwork protocols (NFS, SMB), shared by many clientsHTTP API (PUT/GET by key)
PerformanceHighest, lowest latencyMediumHigher latency, very high throughput
ScalabilityLimited per volumeMediumVirtually unlimited, cheapest per GB
MutabilityIn-place updatesIn-place updatesObjects are typically immutable (replace whole object)
ExamplesAWS EBS, SAN, local SSDAWS EFS, NFS sharesAmazon S3, Google Cloud Storage, Azure Blob, MinIO
Use forDatabases, VM disksShared home directories, legacy appsMedia, backups, data lakes, static assets

Object stores achieve durability with replication or erasure coding (splitting data into fragments plus parity, so it can be rebuilt from a subset at lower storage overhead than full copies). Large uploads use multipart upload: split the file into parts, upload them in parallel and independently (retrying only failed parts), then ask the store to assemble them.

Common mistakes#

  • Storing large files as database BLOBs instead of object storage plus a metadata row.
  • Modelling NoSQL tables like relational ones; wide-column and key-value stores are designed around the queries, one table per access pattern.
  • Adding a technology per feature, multiplying operational burden.

Quick check#

Give two reasons to choose a relational database. ACID transactions and integrity for critical data, and structured, stable data with ad-hoc queries and joins.

Give two reasons to choose NoSQL. Large volumes of unstructured or varied data, and cheap horizontal scaling across commodity or cloud servers.

What is polyglot persistence and its main risk? Using several specialised data stores in one system; the risk is inconsistency and operational cost, mitigated by one system of record and change data capture.

What do indexes cost? Storage space and write performance, because every write must update each index.

When would you use object storage instead of block storage? For large, immutable binary objects accessed over HTTP at scale (media, backups, data lakes); block storage is for databases and VM disks needing low-latency in-place updates.

References#

  • Alex Xu. ByteByteGo System Design Handbook: a visual guide on how to choose the right database; block storage, file storage and object storage; erasure coding; upload large files.
  • System Design Notes (handwritten, LinkedIn): SQL vs NoSQL, reasons to use SQL and NoSQL databases, indexes.
  • Martin Kleppmann. Designing Data-Intensive Applications. O’Reilly, 2017. Chapters 2 and 3.