Databases & StorageIntermediate15 min read2 questions

SQL vs NoSQL: Choosing the Right Database

Stop asking 'SQL or NoSQL'. Ask what your access patterns are, then let the answer pick the store - with a defensible reason you can say in one sentence.

Covers: Relational, document, key-value, wide-column, graph and time-series stores; access patterns; polyglot persistence

“SQL or NoSQL?” is the wrong question, and interviewers know it. NoSQL is not one thing - a key-value store and a graph database have nothing in common except not being relational. The useful question is: what are the access patterns, and which engine makes them cheap?

Filter
0/2 mastered
IntermediatedatabasesnosqlsqlAsked at Amazon, Uber

30-second answer

Relational for structured data with relationships, transactions and ad-hoc queries. Document for self-contained aggregates with a flexible schema and a natural read-whole-object pattern. Key-value for the fastest possible lookup by a single known key - sessions, caches, feature flags. Wide-column for enormous write volumes with predictable query patterns and no joins. Graph when the relationships themselves are the data and you traverse many hops. Time series for append-only measurements queried by time range with automatic downsampling. Most real systems use two or three of these deliberately.

IntermediateschemadenormalizationmodellingAsked at Amazon, Meta

30-second answer

Denormalise when a read path is hot enough that the join cost dominates and the duplicated data changes rarely relative to how often it is read. The cost is that every copy must be updated on write, so you trade cheap reads for expensive, error-prone writes and the permanent risk of copies drifting apart. Normalise by default, measure, then denormalise the specific hot path - and make the update path a single owned code path, ideally driven by an event rather than scattered across the codebase.

Showing 2 of 2 questions for sql-vs-nosql-choosing-a-database.

Check your understanding

4 questions · no sign-up, nothing stored

0/4 answered
Question 1

1.You need 200,000 writes/second of append-only sensor readings, always queried by device and time range, never updated. Best fit?

Question 2

2.What is the fundamental trade in choosing a relational database?

Question 3

3.You keep a search index alongside Postgres. What must be true of the index?

Question 4

4.Which value is safest to denormalise into another table?

Hands-on challenge

Build it - this is what you talk about in a deep-dive round.

Pick the stores for a marketplace

A marketplace has product listings, full-text search, user sessions, order history, real-time inventory and clickstream analytics. Choose the persistence layer.

Requirements

  • For each of the six workloads, name the store family and justify it with a specific constraint.
  • Identify the single source of truth and mark every other store as derived.
  • Describe how each derived store stays in sync, without dual writes from application code.
  • State what breaks, and how badly, if each derived store is lost entirely.
  • Argue the case for doing all six in Postgres, and say at what scale that stops working.

Stretch goals

  • Design the reconciliation job for one denormalised field.
  • Estimate the operational headcount cost of each additional store.