NoSQL data models
Start with the questions your app asks
NoSQL is a broad family of databases that use data models other than the traditional relational table model as their main interface. It does not mean “no schema,” “no transactions,” or “automatically faster.” A distributed database stores or processes data across multiple machines; it may be relational or nonrelational. Choose the model that supports your actual access patterns (the reads and writes the application must perform), correctness requirements, and expected load.
Imagine a bookstore. The catalog displays a book by ISBN, customers browse books by category, and checkout must prevent selling the last copy twice. These are three different access patterns. You can keep checkout in a relational database while using a document catalog or a cache for public product descriptions. You do not need a different database for every feature.
Four data models and distributed SQL
| Model | Natural access pattern | Bookstore example |
|---|---|---|
| Key-value | Get or replace a value by a known key | Cart by cart ID |
| Document | Retrieve structured records with fields and nested values | Product with title, author and categories |
| Wide-column | Retrieve rows or ranges by designed keys, with flexible column families | Device events by device and time |
| Graph | Traverse relationships between nodes | Authors connected to books and publishers |
| Distributed SQL | Relational queries and transactions across a distributed engine | Orders and inventory with relational constraints |
A key-value store may also offer richer operations; a document database may support indexes and transactions. Wide-column storage is not the same as a columnar analytics warehouse. A graph store is useful when multi-hop relationships dominate the workload. Distributed SQL is not a synonym for NoSQL.
Example: a JSON-like catalog document (illustrative data, not a provider API request):
{ "id": "book-17", "title": "Cloud Basics", "category": "technology", "priceCents": 1800, "tags": [ "cloud", "beginner" ], "schemaVersion": 1}A lookup by ID should return this record. A query by category may need an index, a separate lookup structure or a different key layout. Price in integer cents avoids a floating-point representation for this fixture. A flexible document schema still requires validation, migration rules and consistent field meanings.
Design for access patterns and indexes
Suppose the catalog reads one book 900 times per minute and lists books by category 100 times per minute. A document model with an ID lookup and category index is a reasonable candidate. An index is an additional structure that helps locate records; it consumes storage and can add write work. An index on the wrong field may not help the intended query.
For time-ordered events, a key such as (deviceId, eventTime) supports reading one device's events in time order when the engine supports that key structure. It does not automatically support “all devices in the last hour.” That query needs another access path. A wide-column design may use a composite row key, but key encoding and sorting are engine-specific. Duplicating data to support another query (denormalization) requires a policy for keeping copies synchronized.
Avoid picking a data model just because a record fits inside JSON. If the important operation is a transaction across many related records, start by checking the exact transactional guarantees.
Compare provider service families
| Service | Starting model and question to verify |
|---|---|
| Amazon DynamoDB | Key-value and document items; check partition/sort keys, index and consistency restrictions |
| Azure Cosmos DB | Multiple APIs and models; for NoSQL API check item ID, partition key, consistency and transaction scope |
| Cloud Firestore | Documents in collections; check query indexes and transaction restrictions |
| Google Cloud Bigtable | Wide-column rows; design row keys for expected ranges |
| Amazon Neptune | Graph data and relationship queries; check supported graph query language |
| Google Cloud Spanner | Distributed relational transactions; check dialect, isolation, instance configuration and cost |
These are candidates, not equivalent products. For example, Firestore uses collections/documents and supports transactions, while Bigtable emphasizes row-key design. Spanner is relational and supports ACID read-write transactions; serializable isolation provides external consistency. Cosmos DB offers consistency settings; do not assume every API supports identical settings or transactions. Ordinary transactional batches for Cosmos DB for NoSQL are scoped to a logical partition; distributed transaction capabilities have separate requirements that must be checked for the chosen account/API. Do not copy one service's partition, index or capacity settings into another.
Consistency, transactions and failure
A strongly consistent read (in the linearizable single-object sense) sees the effects of completed writes in real-time order, subject to the selected API guarantee. Eventual consistency allows a stale result before replicas converge if updates stop and replication succeeds. Session consistency can give a client read-your-writes behavior within its defined session scope. These terms have precise service-specific boundaries; a strong read of one object does not itself make a multi-object transaction atomic.
A transaction groups operations according to its engine's atomicity and isolation guarantees. For checkout, use an atomic conditional stock update or a transaction that preserves the stock invariant. A naive read-then-write can allow two requests to both see stock 1. A conditional update checks the current stock at write time: only one purchase should succeed. Retried requests need an idempotency strategy (such as a unique order ID) to avoid double application. A transaction callback may execute more than once, so do not send irreversible external notifications inside a retryable callback.
During a network partition, a distributed system cannot guarantee both linearizable consistency and availability in the formal sense for all requests (CAP). That does not mean choosing any two of three features at all times. Some requests may wait or fail to preserve guarantees; weaker reads may remain available. Record what a user sees during a failure and how the application recovers.
TTL, security and portability
Time to live (TTL) is an expiration policy. A database may delete expired records asynchronously: DynamoDB, for example, can still return expired items until background deletion occurs. Apply an explicit expiration check where the business rule requires it. TTL is not an exact legal deletion deadline or an authorization mechanism. A cache entry's TTL is a different mechanism from database record retention.
Use private access where supported, workload identity, least privilege and encrypted transport. A tenant ID in a partition key helps locate data but is not proof that the caller owns the tenant. Enforce authorization before returning records. Design backups and restores independently of replicas.
For portability, write down your access patterns, version document schemas, export synthetic data in a neutral format, validate record counts and important invariants, and rebuild indexes on the target engine. A JSON export does not carry transaction semantics, query behavior, or access policy. Evaluate migration and ongoing cost before selecting a service.
Practice: choose a model, not a brand
For a bookstore, assign each access pattern a candidate model: read a cart by ID; browse products by category; read device events for one device in a time range; find authors two relationships away from a publisher; atomically update inventory and orders. Explain one index or key for each nonrelational candidate and a correctness requirement for checkout. It is valid to keep multiple patterns in one relational database if measurements and operational simplicity support that decision.
Next: partition keys, hot partitions, capacity units, and caching.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
NoSQL data models — knowledge check
Choose the best answer for each offline scenario.
A service must repeatedly traverse author–book–publisher relationships. Which model is a natural candidate?
A product is read by ID and frequently queried by category. What should the design include?
Two customers see stock 1 at the same time. What preserves the inventory invariant?
A DynamoDB item passes its TTL timestamp but has not been deleted. What should the application do if expired items must not be used?
Which description of Spanner is most appropriate here?