Skip to content
AI Engineer Guide.

concept · basics · intermediate · concept 10 of 24

NoSQL

0 of 24 complete

Why it matters

A relational schema is normalised first and indexed for queries later; a NoSQL store usually inverts that, because the physical layout follows the access pattern and changing the pattern means rewriting the data. That is a good trade when the pattern is known and the volume is high, and a bad one when the product is still discovering what it needs to ask. The choice has to be made with the query set in view.

Mental model

It is a filing cabinet organised by the question you expect to ask: fast for that question, expensive for any other. The analogy breaks because a record can be duplicated into several cabinets, which keeps every question fast and makes every update a multi-place write.

How it works

Mechanism, step by stepInteractive
  1. 1Write the access patterns first: the exact queries, their frequency and their latency targets.
  2. 2Choose the model from those patterns, then decide the partition key so reads and writes spread evenly.
  3. 3Decide where duplication is acceptable, and list every place a single fact is stored.
  4. 4Set consistency per operation, and test the behaviour when a read follows a write immediately.
  5. 5Check index limits and whether secondary indexes are updated synchronously.
  6. 6Plan the migration path, because changing the partition key requires rewriting the data set.

Step 1 of 6

Write the access patterns first: the exact queries, their frequency and their latency targets.

Step 1/6 · step 1

Figure. The mechanism in this page's own steps. The figure adds sequence, not new claims.

What to notice. A step can be read alone, but the order is the mechanism. The control lets you stop on any one.

Text version

The page's steps: 1. Write the access patterns first: the exact queries, their frequency and their latency tar… 2. Choose the model from those patterns, then decide the partition key so reads and writes s… 3. Decide where duplication is acceptable, and list every place a single fact is stored. 4. Set consistency per operation, and test the behaviour when a read follows a write immedia… 5. Check index limits and whether secondary indexes are updated synchronously. 6. Plan the migration path, because changing the partition key requires rewriting the data s…

  1. Write the access patterns first: the exact queries, their frequency and their latency targets.
  2. Choose the model from those patterns, then decide the partition key so reads and writes spread evenly.
  3. Decide where duplication is acceptable, and list every place a single fact is stored.
  4. Set consistency per operation, and test the behaviour when a read follows a write immediately.
  5. Check index limits and whether secondary indexes are updated synchronously.
  6. Plan the migration path, because changing the partition key requires rewriting the data set.

Trade-offs

ChoiceGood forCostFails when
Document storeFlexible shape per recordCross-document joins are expensiveQueries span many entity types
Key-value storeVery low latency at scaleNo query language beyond the keyThe access pattern changes
Wide-column storeHigh write throughput on large dataRigid schema and query planningThe team needs ad-hoc queries
Graph databaseTraversal-heavy relationshipsSmaller ecosystem and operational familiarityThe workload is mostly key lookups
Trade-off mapInteractive

Good for

Flexible shape per record

Cost

Cross-document joins are expensive

Fails when

Queries span many entity types

  1. Queries span many entity types
  2. The access pattern changes
  3. The team needs ad-hoc queries
  4. The workload is mostly key lookups

Figure. Each choice with what it buys, what it costs, and the case where it loses.

What to notice. The fourth column is the decision: if the losing case describes your situation, the choice is wrong.

Text version

Four trade-offs: Document store is good for Flexible shape per record, costs Cross-document joins are expensive, and fails when Queries span many entity types. Key-value store is good for Very low latency at scale, costs No query language beyond the key, and fails when The access pattern changes. Wide-column store is good for High write throughput on large data, costs Rigid schema and query planning, and fails when The team needs ad-hoc queries. Graph database is good for Traversal-heavy relationships, costs Smaller ecosystem and operational familiarity, and fails when The workload is mostly key lookups

Failure modes

  • Hot partition. One key receives most traffic and latency spikes while the cluster looks underused. Debug: chart request rate per partition key and look for a single dominant value.
  • Read-after-write surprise. A user updates a record and sees the old value on the next request. Debug: reproduce with an immediate read against the same consistency setting and compare replicas.
  • Unbounded document growth. A record grows with every event and eventually exceeds the item size limit. Debug: track maximum document size per collection and alert before the limit.

In production

Monitor per-partition throughput, throttling events and replication lag, since these are signals a relational dashboard does not show. Cap document size and index count, and review access patterns before adding a new query path.

Common misconceptions

People think: NoSQL means no schema.

Actually: It means the schema is enforced by the application and by the access pattern, which is usually harder to change than a migration.

People think: Eventually consistent means it will be consistent soon.

Actually: It means there is no bound without a mechanism; the window depends on replication and on how you read.

Interview angle

Start from access patterns, then name the partition key and the duplication cost. Explain that consistency is per operation. Choosing a product by reputation and meeting the query shapes later is the usual mistake.

Sources