Skip to content
Tech Interview Prep
Technical interview guide

NoSQL, Graph & Key-Value Data Stores

When a relational database isn't the right fit: document, key-value, graph, and vector stores, and how to choose between them.

Minutes to read
3
Practice MCQs
25
Interview Q&A
25
Edition
v4
Editorial status
Reviewed

Scope: SQL principles with PostgreSQL 18 examples; vendor-specific behavior must be verified.

Overview

Curated: · Written: · Reviewed:

NoSQL, Graph & Key-Value Data Stores

In one line

Reach for a NoSQL store when a known access pattern, a genuinely variable data shape, or a write volume one node cannot take is the hard constraint that relational defaults cannot meet. Relational stays the default, so a NoSQL choice needs a stated reason.

Key definitions

  • Access pattern: the queries the store must serve. The design starts here, not with the data.
  • Partition key: decides which node holds an item. Queries without it are rejected or scan the cluster.
  • Embed vs reference: embedding nests child data inside the parent document; referencing stores children separately and links them by ID.
  • Index-free adjacency: each graph node holds pointers to its neighbours, so a hop follows stored links instead of a global join lookup.
  • Read-your-writes: a user always sees their own last write. The minimum guarantee for user-facing state.
  • Hot partition: one key takes a disproportionate share of reads or writes and saturates the node that owns it.

Formulas and complexity

W+R>NW + R > N

A read quorum overlaps the write quorum when W + R > N, so a read sees the latest acknowledged write. W = 1 gives fast acks and possibly stale reads.

Graph traversal cost grows with the nodes and edges the query visits, not with total graph size. Quote it that way.

How it works

A write carries its partition key. The store hashes that key to a token range, and the owning node and its replicas take the write. Reads that include the key go to the same place. A read without the key has to ask every partition, which is why such queries are rejected or become full scans.

no key Request with partition key Hash partition key Owning node Replica 1 Replica 2 Scan every partition

When to use and when not to

SituationReach forAvoid when
Lookup by known key, latency dominatesKey-value (Redis)You need queries by content or multi-key atomicity
Self-contained aggregate, variable shape, known read pathsDocument (MongoDB)Ad-hoc cross-document queries or frequent multi-document transactions dominate
Write-heavy events with fixed partition accessWide-column (Cassandra)Query patterns change often or you need ad-hoc analytics
Variable-depth traversal is the core queryGraphOne or two joins would answer it
Multi-entity transactions, constraints, ad-hoc SQLRelational (PostgreSQL)Rarely a reason to leave, only a reason to check first

Traps interviewers probe

  1. Choosing for scale you do not have. Fix: measure a well-indexed relational baseline first, then name the pain it cannot meet.
  2. Treating Redis as a durable system of record. Fix: state the persistence mode and replication. With asynchronous replication, confirmed writes can be lost on failover.
  3. Calling a store schemaless. Fix: there is always a schema. Enforce it with $jsonSchema validation so readers do not handle every historical shape.
  4. Embedding an unbounded array. Fix: bound the child count, or reference the children and keep only a summary in the parent.
  5. Hash partitioning by a key one tenant dominates. Fix: add a time bucket or random suffix to the key, or cache the hot key in front of the store.

Interview tips

Open with the access pattern, the consistency requirement, and why Postgres is not enough. Expect these follow-ups: "Why not just Postgres?", "What consistency does this feature need?", "A key goes viral, what happens?", and "The read paths changed, now what?" The last one is the re-shaping cost: a new table or embedding change, a dual-write backfill, then cutover.

30-second outline: "Access is lookup by session ID at 50k/s with a sub-millisecond p99. Consistency is eventual, with read-your-writes on the same session. A relational table with a secondary index adds a second structure to maintain on every write. I would use a key-value store and accept that queries by user_id now need a separate index I build and keep in sync. If one key goes hot, I salt it or cache it in front."

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.