Skip to main content

Database Types

SQL vs. NoSQL frames the decision as roughly one axis — relational structure vs. flexible scale — but "NoSQL" itself covers several genuinely different data models, each shaped around a different access pattern. Knowing which model fits which problem, and naming it specifically, is a stronger interview answer than "we'll use a NoSQL database."

The main types​

TypeData modelGood forExamples
RelationalTables, rows, foreign keysComplex relationships, strong consistencyPostgreSQL, MySQL
DocumentNested, semi-structured JSON-like documentsFlexible schemas, one-document-per-entity readsMongoDB, DynamoDB (partially)
Key-valueOpaque value looked up by a single keyExtremely fast simple lookups, caching, sessionsRedis, DynamoDB
Columnar (wide-column)Rows grouped by column families, sparseMassive write volume, analytical scans over columnsCassandra, HBase
GraphNodes and edges as first-class citizensDeep relationship traversal (friend-of-a-friend, fraud rings)Neo4j
Time-seriesData indexed and optimized by timestampMetrics, sensor data, high write rate, range queries by timeInfluxDB, TimescaleDB
SearchInverted index over text fieldsFull-text search, relevance rankingElasticsearch, OpenSearch

Why the model matters more than the brand name​

Each type exists because it optimizes its internal storage layout around one access pattern, at the cost of being awkward or slow for others:

System Design Lab

A key-value store is fast precisely because it gives up query flexibility — it can't filter or sort by anything other than the key, but a lookup by key is close to as fast as a lookup can be, which is why key-value stores double as the storage layer for most caches, a connection worth naming when it comes up in the Caching Fundamentals module. A graph database is fast at multi-hop traversal precisely because it stores relationships as direct pointers rather than requiring a relational join at every hop — the same query ("friends of friends of friends") that gets exponentially expensive as a chain of SQL joins is comparatively cheap when the storage engine is built around walking edges.

Picking a type: match the model to the query, not the trend​

The practical exercise in an interview is to look at the dominant read pattern the design actually needs and pick the model built for it:

  • Need consistent, relational, transactional data with complex queries you can't fully predict upfront? Relational.
  • Need to store and fetch a whole entity (a user profile, a product) as one flexible unit, with schema that varies or evolves? Document.
  • Need the fastest possible lookup by a single known key, and nothing more? Key-value.
  • Need to answer "who is connected to whom, how deeply"? Graph.
  • Need to ingest huge volumes of timestamped data and query by time range? Time-series.
  • Need to search free text with relevance ranking, not exact match? Search.

Real systems commonly use several of these side by side — a relational database for core transactional data, a key-value store for sessions and caching, and a search index for the site's search bar — rather than forcing one database type to serve every access pattern in the system.

Why this matters in an interview​

Naming the specific database type — "a graph database, since the core query is multi-hop relationship traversal" — rather than a generic "NoSQL database" demonstrates you're reasoning from the access pattern to the storage engine, not from a buzzword. It also opens the door to naming a specific product, which signals real familiarity rather than textbook recall.

Using multiple specialized databases vs. one general-purpose database: pros and cons​

Pros

  • Each data model is fast at exactly the access pattern it was built for
  • Avoids forcing an awkward workload (e.g. graph traversal) onto a mismatched engine
  • Lets each piece of the system scale and evolve independently

Cons

  • More operational surface area — multiple database systems to run and monitor
  • Data often needs to be synchronized or duplicated across systems
  • Team needs to understand the failure modes and tuning of more than one engine

Further Reading​

Saved locally in your browser — visible in the sidebar as you go.