nosql-data-modeling
Skill1 starsChanged 2 months agoMITView on GitHub
Model data for document, key-value and wide-column stores - embed versus reference, document size limits and the fan-out trap, partition key selection, hot partitions, single-table DynamoDB layouts, and the real anti-patterns. Use when someone is choosing MongoDB, DynamoDB, Cassandra or Redis for a relational problem, when a document grew too big, when one shard is hot, when reads became N+1 against MongoDB, or when designing an access-pattern-first schema. Triggers on "NoSQL", "document model", "embed vs reference", "partition key", "hot partition", "16MB", "MongoDB", "DynamoDB", "Cassandra", "Cassandra modeling".
2 other projects use a version of this.
Adopted by
Most recently taken up by
- novatic-cu/nova-skills-coretheir own version, first seen Nov 22, 2026
- novatic-cu/nova-skillstheir own version, first seen Sep 20, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- novatic-cu/nova-skills★ 1same name
- novatic-cu/nova-skills-core★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository126 other files it gives its agents.
- eu-data-backend-job-hunterSkill
- job-application-matcherSkill
- llm-agents-and-tool-useSkill
- llm-application-architectureSkill
- llm-cost-and-latency-optimizationSkill
- llm-evaluationSkill
- llm-fine-tuning-and-adaptersSkill
- llm-privacy-and-safetySkill
- llm-prompt-engineeringSkill
- llm-rag-systemsSkill
- structured-output-and-jsonSkill
- graphql-api-designSkill
- pagination-and-filteringSkill
- rest-api-designSkill
- webhooks-and-integrationsSkill
- caching-architecture-multi-layerSkill
- resilience-patternsSkill
- service-boundaries-and-monolithsSkill
- system-design-interviewSkill
- go-concurrencySkill
- go-error-handlingSkill
- java-spring-patternsSkill
- nodejs-server-performanceSkill
- python-async-patternsSkill
- python-data-modelingSkill
- python-packaging-and-toolingSkill
- python-performanceSkill
- rest-api-implementationSkill
- rust-error-handlingSkill
- rust-ownership-patternsSkill
- typescript-type-safetySkill
- ci-caching-and-speedupSkill
- ci-pipeline-designSkill
- deployment-strategiesSkill
- github-actions-hardeningSkill
- release-versioning-and-changelogsSkill
- reproducible-buildsSkill
- aws-iam-and-securitySkill
- aws-serverless-architectureSkill
- azure-fundamentalsSkill
- cloud-cost-optimizationSkill
- cloud-networking-and-vpcSkill
- gcp-cloud-architectureSkill
- code-review-skillsSkill
- design-review-and-refactoring-architectureSkill
- refactoring-techniqueSkill
- understanding-unknown-codebaseSkill
- buildkit-and-cacheSkill
- container-image-debuggingSkill
- container-runtime-securitySkill
- docker-compose-workflowsSkill
- dockerfile-authoringSkill
- docker-image-optimizationSkill
- database-connection-managementSkill
- database-transactionsSkill
- distributed-databasesSkill
- postgres-query-tuningSkill
- redis-and-cachingSkill
- schema-migrationsSkill
- data-modeling-for-analyticsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 6 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 15
Read references/fan-out.md when an unbounded child collection is involved — it has the arithmetic worked through for orders → line items.
- Distinctive: line 24
Write volume is high and grows faster than read complexity.
- Distinctive: line 43
Embed: when the child is:
- Distinctive: line 47
Read together with the parent, always.
- Distinctive: line 48
Not queried independently or not shared.
- Distinctive: line 51
Reference: when the child is:
- Very specific: line 72
When an embedded array approaches 1000 elements, the BSON traversal cost, the page fragmentation, and the write amplification (a single …
- Very specific: line 77
Read references/fan-out.md for the worked example of moving 200k line items out of an order document without a big-bang migration.
- Distinctive: line 94
Write the queries down first, as a table.
- Very specific: line 126
Read with Query on a partition, never Scan.
- Very specific: line 165
Use explain("executionStats") to check whether a query used IXSCAN or COLLSCAN.
- Very specific: line 186
Use MongoDB's JSON-schema validator on collection creation, and add it before you have ten writers with different ideas of the shape.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
NoSQL Data Modelling
Access patterns decide the schema, not the entities. The output is a set of tables/collections and the queries each one serves, written down before any schema is created.
Read references/fan-out.md when an unbounded child collection is involved —
it has the arithmetic worked through for orders → line items.
First: should this be NoSQL at all?
Pick a document store when at least two are true:
- Reads are key-by-id or by a single high-cardinality attribute.
- A document is written and read as a unit — you always want all of it.
- Write volume is high and grows faster than read complexity.
- You need horizontal write scaling more than multi-table joins and secondary indexes.
- The working set can be denormalised, or the extra I/O of denormalising is cheaper than the join.
Stay relational when you need arbitrary ad-hoc filters across many columns, strong multi-row constraints, or the data is inherently relational and small. MongoDB is not a faster Postgres; it is a different set of trade-offs, and moving a normalized relational schema into documents without changing the access patterns buys nothing.
MongoDB's aggregation pipeline and joins ($lookup) are real, but a query that
leans on them is a relational query wearing a disguise. Redis is a cache and a
data structure server; it is not a system of record for anything you cannot
rebuild.
Embed or reference
Embed when the child is:
- Bounded (a hard upper limit you can enforce: at most 20 tags, at most 5 addresses).
- Read together with the parent, always.
- Not queried independently or not shared.
- Small relative to the parent.
Reference when the child is:
- Unbounded, or grows without limit.
- Queried independently, sorted, filtered, or joined.
- Shared by many parents.
- Large relative to the parent (images, files, messages, events).
A one-to-many that is genuinely unbounded — a user with 200k orders, a post with 50k comments — cannot be embedded. This is the most common modelling mistake in MongoDB, and it fails slowly, at 14MB, in production.
The size limits you must design around
| Store | Limit | What it means |
| MongoDB | 16 MB per document (BSONObjectTooLarge) | Hard cap, no partial updates possible |
| DynamoDB | 400 KB per item | Hard cap; partition total is 10 MB enforced for transactional writes |
| Cassandra | ~2 MB per partition value (InvalidRequest: Partition too big) | Per-partition value, not per row |
| Redis | 512 MB per string (older) | A big blob blocks the event loop |
| SQLite | ~1 GB default, 1e9 rows | Not a document store, but the "one big table" trap is the same |
When an embedded array approaches 1000 elements, the BSON traversal cost,
the page fragmentation, and the write amplification (a single $push rewrites
the whole document and the index entries) all get worse together. The number
1000 is a smell, not a limit.
Read references/fan-out.md for the worked example of moving 200k line items
out of an order document without a big-bang migration.
The fan-out problem, stated precisely
Anything stored inside a document cannot be indexed, filtered, or joined
independently. Asking for "all orders containing product X" over an embedded
items[] array means a full collection scan, no index, no selectivity. The
moment an embedded field needs a query, that field is a reference.
Bucket the collection that is the problem. Unbounded child data is stored in its own collection, keyed by parent, with a hard window per document (time ranged or count-capped), so each document stays small and each write touches one small document instead of rewriting a 15MB blob.
Access patterns first
Write the queries down first, as a table. Every access pattern that has no key is a schema you have to add later, and adding it to a document store means changing the primary key structure.
| # | Query | Frequency | Key it needs | Table/collection |
| 1 | Get order by id | high | PK = ORDER#<id> | orders |
| 2 | List a user's last 50 orders | high | PK = USER#<id>, SK = ORDER#<ts>#<id> | user_orders |
| 3 | Find orders containing SKU 42 | low | GSI1PK = SKU#42 | orders (GSI) |
| 4 | Aggregate revenue by month | batch | none — warehouse | separate |
Then design keys so those four lookups are all GetItem/find on a known
key. If a pattern needs a scan, either add an index (DynamoDB GSI, Cassandra
secondary index, Mongo index on the referenced field) or admit the scan is
acceptable at that frequency.
DynamoDB single-table layout
One table, composite string keys, access patterns expressed in the key names.
PK SK Entity
ORDER#o-123 ORDER#o-123 order header
ORDER#o-123 ITEM#i-1#sku-99 order line
USER#u-42 ORDER#2024-03-01#o-123 user's order index
SKU#sku-99 ORDER#o-123 reverse lookup- Keys are strings only, max 2048 bytes; the
#separator is a convention, not syntax.GSI1PK/GSI1SKare the names of the single secondary index DynamoDB gives you free-ish; every one of them is eventually consistent by default unless you request a strongly consistentQueryon it. - Read with
Queryon a partition, neverScan. AScanof a 100M-item table reads 100MB per page and will throttle. ProjectionExpressionto avoid fetching item bodies you don't need; fetch large item attributes selectively.- An item may be up to 400 KB, and the whole partition for a transactional write is limited to 10 MB.
Partition keys and hot partitions
The single most consequential decision. A hot partition is one key absorbing
far more than its share of traffic: a single hottest tenant, a customer_id
where one customer is 10% of writes, a monotonically increasing key where all
new writes land on one partition.
Symptoms and fixes:
| Symptom | Cause | Fix |
| Throughput plateaus while the table is empty | One key, one partition, one hot key | Add a hash-sharded sub-key: CUSTOMER#<id>#<shard 0-9> and query all 10 in parallel |
ProvisionedThroughputExceededException on a table far under its capacity | Hot partition + a burst | Spread across partitions; the fix is layout, not capacity |
| One shard is 10x the CPU of the others | Same as above, visible in Cassandra nodetool status | Compound partition key: PRIMARY KEY ((tenant, bucket), ts) |
| Sequential IDs | Time-based partitioning concentrates writes | Random/hash key, or a bucket prefix |
A hot partition can never be fixed by raising provisioned throughput, because the limit is per partition, not per table. Key design is the fix.
MongoDB specifics
- Embed a bounded array; a large array of sub-documents is fine up to a few
thousand elements, but index the fields you query inside the array if you
ever need to, because an index on the parent is useless for
items.sku. $pushand$seton a large embedded array rewrite the document; this is the classic write-amplification problem. Prefer a separate collection for anything that grows.useUnifiedTopologyis the default and only option in modern drivers; connection pooling is via themaxPoolSizeURI option, default 100.- A document whose largest field is a growing array is a
bucketpattern candidate: group children by a fixed size or time window and store the bucket id, so writes append to small documents. - Use
explain("executionStats")to check whether a query usedIXSCANorCOLLSCAN. ACOLLSCANon a large collection is the signal to add an index or restructure. - Aggregation
$lookupin a loop from the application is the relational join you were trying to avoid; do it once in the pipeline, or restructure the data.
Schema flexibility is an illusion
"Schemaless" does not mean "no schema"; it means the schema lives only in your application, so nothing validates it. Document stores trade a declared schema for per-document heterogeneity, which means:
- A
pricefield that is a number in one document and a string in another will break comparisons, indexes, and aggregations in ways nothing catches. - Index a field and you have declared a schema for that field. An index on
emailnow requires every document to have a compatibleemail. - Enforce what you can at the engine (a validator in MongoDB, a
CHECK-like conditional expression, a schema registry in Kafka) because application-only validation has holes wherever a second writer exists.
Use MongoDB's JSON-schema validator on collection creation, and add it
before you have ten writers with different ideas of the shape.
Anti-patterns
- The relational dump. A collection per table with
_idforeign keys and a$lookupfor every join. It is slower than a relational database and has none of the constraints. - Unbounded embedded arrays. See the fan-out reference.
$whereand non-indexedsorton large collections.- Counting on a document store.
count/db.order.count()over millions of documents is a full pass; maintain a counter, or query a warehouse. - Writing a full document to change one field (read-modify-write of a
document with no atomic operator). Use
$set/$incso concurrent writers do not lose each other. - Multi-document transactions as the default in Cassandra or DynamoDB. They exist, they are expensive, and they were the last thing designed. Design so they are not needed.
- Relying on a MongoDB transaction for a cross-collection invariant. One replica set, one primary, a latency spike on every write. Use a single document or an application-level invariant.
- Keying by a mutable attribute (a
statusin the primary key) — every status change is a delete plus an insert, and concurrent writers will silently fork.
Files
references/fan-out.md— worked example: unbucketing an order document as theitemsarray grows, with the migration path and the DynamoDB/Cassandra key layout for the same data.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

