Azure Cosmos DB NoSQL data modeling
Gather application requirements, access patterns, volumetrics, concurrency, and relationship constraints; maintain cosmosdb_requirements.md during discovery; then create cosmosdb_data_model.md with a justified Azure Cosmos DB for NoSQL container, partition-key, indexing, and denormalization design.
When to invoke
- "Design a Cosmos DB NoSQL data model for this app."
- "Help choose containers and partition keys from our access patterns."
- "Create cosmosdb_requirements.md and cosmosdb_data_model.md."
- "Review whether these entities should be embedded or separated."
- "We have massive Cosmos DB write volume and need a data model."
Prerequisites and context
- Work from the user's domain, entities, relationships, access patterns, RPS, latency SLOs, consistency needs, document size, retention, and geographic distribution.
- Maintain two files in the working repository:
cosmosdb_requirements.md as the live scratchpad and cosmosdb_data_model.md as the final deliverable.
- Ask one question at a time when possible, and at most three related questions.
- Read
references/extended-guide.md when the main skill does not contain enough detail for advanced Cosmos DB modeling decisions.
Discovery rules
Update cosmosdb_requirements.md after every user message that adds information. Capture evolving thoughts, uncertain assumptions, and design considerations instead of waiting for a final answer.
For massive scale signals such as >10k writes/sec, several million records in a short period, or the phrase "massive scale", immediately ask about:
- Data binning or chunking strategies: can individual records be grouped into chunks?
- Write reduction: what is the minimum number of actual write operations, and can work be batched?
- Physical partition impact: how will total data size affect cross-partition query costs?
Every access pattern must have RPS. If the user does not know, estimate from business context and label the value as an assumption.
Requirements artifact
Create or update cosmosdb_requirements.md with this concrete structure:
# Azure Cosmos DB NoSQL Modeling Session
## Application Overview
- **Domain**: <domain>
- **Key Entities**: <entity list and relationships such as User (1:M) Orders>
- **Business Context**: <rules, constraints, compliance>
- **Scale**: <concurrent users, document sizes, retention, total requests/second>
- **Geographic Distribution**: <single region, multi-region reads, multi-region writes>
## Access Patterns Analysis
| Pattern # | Description | RPS (Peak and Average) | Type | Attributes Needed | Key Requirements | Design Considerations | Status |
| --- | --- | --- | --- | --- | --- | --- | --- |
| 1 | Get user profile by user ID when the user logs into the app | 500 RPS | Read | userId, name, email, createdAt | <50ms latency | Simple point read with id and partition key | Yes |
| 2 | Create new user account when the user is on the sign up page | 50 RPS | Write | userId, name, email, hashedPassword | Strong consistency | Consider unique key constraints for email | Pending |
## Entity Relationships Deep Dive
- **User → Orders**: 1:Many (avg 5 orders per user, max 1000)
- **Order → OrderItems**: 1:Many (avg 3 items per order, max 50)
- **Product → OrderItems**: 1:Many (popular products in many orders)
- **Products and Categories**: Many:Many
## Enhanced Aggregate Analysis
### <Entity1 + Entity2> Container Item Analysis
- **Access Correlation**: <% requiring both entities>
- **Query Patterns**: Entity1 only, Entity2 only, and both together percentages
- **Size Constraints**: Combined max size in MB and growth pattern
- **Update Patterns**: Independent or related update frequencies
- **Decision**: Single Document, Multi-Document Container, or Separate Containers
- **Justification**: <reasoning>
## Container Consolidation Analysis
| Parent | Child | Relationship | Access Overlap | Consolidation Decision | Justification |
| --- | --- | --- | --- | --- | --- |
| <Parent> | <Child> | 1:Many | <overlap> | Consolidate/Separate | <why> |
## Design Considerations (Subject to Change)
- **Hot Partition Concerns**: <analysis>
- **Large fan-out with Many Physucal partitions based on total Datasize Concerns**: <analysis>
- **Cross-Partition Query Costs**: <trade-offs>
- **Indexing Strategy**: <composite indexes, included paths, excluded paths>
- **Multi-Document Opportunities**: <30-70% correlation candidates>
- **Multi-Entity Query Patterns**: <related retrievals>
- **Denormalization Ideas**: <duplicated attributes>
- **Global Distribution**: <write regions and consistency levels>
## Validation Checklist
- [ ] Application domain and scale documented
- [ ] All entities and relationships mapped
- [ ] Aggregate boundaries identified based on access patterns
- [ ] Identifying relationships checked for consolidation opportunities
- [ ] Container consolidation analysis completed
- [ ] Every access pattern has: RPS (avg/peak), latency SLO, consistency level, expected result size, document size band
- [ ] Write pattern exists for every read pattern (and vice versa) unless USER explicitly declines
- [ ] Hot partition risks evaluated
- [ ] Consolidation framework applied; candidates reviewed
- [ ] Design considerations captured (subject to final validation)
Modeling decisions
| Situation |
Prefer |
Reason |
>70% access correlation, bounded size, related operations |
Multi-Document Container or embedded Single Document |
Joint reads dominate and transaction scope may matter. |
50-70% access correlation |
Analyze operational coupling |
Same backup/restore favors Multi-Document Container; different scaling or consistency favors Separate Containers. |
30-50% access correlation |
Compare cost and complexity carefully |
Either design can be valid; quantify cross-partition query cost. |
<30% access correlation |
Separate Containers |
Independent access dominates. |
Child cannot exist without parent and queries always know parent_id |
Identifying relationship with partition key parent_id |
Avoid parent-to-child cross-partition queries. |
| Unbounded child growth |
Separate documents or containers |
Avoid exceeding document size and write amplification. |
Consolidate when access overlap is >50%, the relationship is natural parent-child, size is bounded, and an identifying relationship exists. Keep separate when access overlap is <30%, growth is unbounded, or operations must scale independently.
Procedure
- Capture application overview, entities, business context, scale, geographic distribution, and compliance constraints in
cosmosdb_requirements.md.
- Stay in access-pattern discovery until the user confirms all reads and writes are captured. Ask, "Do you have any other access patterns to discuss? I see we have a user login access pattern but no pattern to create users. Should we add one?"
- For each access pattern, record average/peak RPS, read/write type, attributes, latency SLO, consistency level, result size, document size band, and status.
- Analyze aggregates, identifying relationships, access correlation, update coupling, size constraints, hot partitions, cross-partition query costs, indexing, and denormalization.
- Only after the user confirms access patterns are complete, create
cosmosdb_data_model.md with final container designs and justifications.
- Group indexes with the containers they belong to; do not create a detached indexing section that loses container context.
Final deliverable
Create cosmosdb_data_model.md only after confirmation:
# Azure Cosmos DB NoSQL Data Model
## Design Philosophy & Approach
<aggregate-oriented design principles and request-unit rationale>
## Aggregate Design Decisions
<why data was grouped together, split, or duplicated>
## Container Designs
### <Container name>
- **Purpose**: <what it stores>
- **Document Types**: <type discriminator values if Multi-Document Container>
- **Partition Key**: <path and why>
- **ID Strategy**: <id shape>
- **Items**: <example document summaries>
- **Indexes**: <included paths, excluded paths, composite indexes grouped here>
- **Served Access Patterns**: <pattern IDs>
- **Trade-offs**: <hot partition, cross-partition, transaction, consistency notes>
Progressive disclosure and bundled resources
references/extended-guide.md: deeper Cosmos DB modeling guidance for aggregate, partition-key, indexing, and scale decisions.
Compatibility vocabulary
Preserve these legacy terms, API names, command placeholders, and literal phrases when applying or migrating this skill:
AP31
CRITICAL
Container/Separate
Document/Multi-Document
EVERY
FILE
IMMEDIATELY
Independent/Related
MANAGEMENT
MASSIVE
MOST
MUST
No/Yes/Yes
SCALE
WARNING
artifacts_produced
binning/chunking
by-step
e-commerce
last_updated
progressive-disclosure
use-case
user_id
volume/size
UserOrders
Output template
## Cosmos DB data modeling result
**Status:** requirements-updated | model-created | blocked
**Files changed:** `cosmosdb_requirements.md`, `cosmosdb_data_model.md`
### Requirements captured
| Area | Status | Evidence |
| --- | --- | --- |
| Access patterns | <complete/incomplete> | <count and missing fields> |
| Scale and RPS | <complete/incomplete> | <avg/peak RPS notes> |
| Relationships | <complete/incomplete> | <entities and cardinality> |
### Design summary
| Container | Partition key | Document types | Main access patterns | Key trade-off |
| --- | --- | --- | --- | --- |
| <name> | <partition key> | <types> | <pattern IDs> | <trade-off> |
### Open questions
- <question or none>
Quality gate
1---2name: cosmosdb-datamodeling3description: Capture Azure Cosmos DB for NoSQL workload requirements and produce access-pattern-driven data model artifacts. Use when the user asks to design a Cosmos DB NoSQL model, choose containers and partition keys, document access patterns, analyze aggregates, or create cosmosdb_requirements.md and cosmosdb_data_model.md.4---56<!-- Generated from harness/github-copilot/skills/cosmosdb-datamodeling/SKILL.md by harness/claude-code/scripts/convert_from_copilot.py. Edit the source, not this file. -->78# Azure Cosmos DB NoSQL data modeling910Gather application requirements, access patterns, volumetrics, concurrency, and relationship constraints; maintain `cosmosdb_requirements.md` during discovery; then create `cosmosdb_data_model.md` with a justified Azure Cosmos DB for NoSQL container, partition-key, indexing, and denormalization design.1112## When to invoke1314- "Design a Cosmos DB NoSQL data model for this app."15- "Help choose containers and partition keys from our access patterns."16- "Create cosmosdb_requirements.md and cosmosdb_data_model.md."17- "Review whether these entities should be embedded or separated."18- "We have massive Cosmos DB write volume and need a data model."1920## Prerequisites and context2122- Work from the user's domain, entities, relationships, access patterns, RPS, latency SLOs, consistency needs, document size, retention, and geographic distribution.23- Maintain two files in the working repository: `cosmosdb_requirements.md` as the live scratchpad and `cosmosdb_data_model.md` as the final deliverable.24- Ask one question at a time when possible, and at most three related questions.25- Read `references/extended-guide.md` when the main skill does not contain enough detail for advanced Cosmos DB modeling decisions.2627## Discovery rules2829Update `cosmosdb_requirements.md` after every user message that adds information. Capture evolving thoughts, uncertain assumptions, and design considerations instead of waiting for a final answer.3031For massive scale signals such as `>10k writes/sec`, several million records in a short period, or the phrase "massive scale", immediately ask about:32331. Data binning or chunking strategies: can individual records be grouped into chunks?342. Write reduction: what is the minimum number of actual write operations, and can work be batched?353. Physical partition impact: how will total data size affect cross-partition query costs?3637Every access pattern must have RPS. If the user does not know, estimate from business context and label the value as an assumption.3839## Requirements artifact4041Create or update `cosmosdb_requirements.md` with this concrete structure:4243```markdown44# Azure Cosmos DB NoSQL Modeling Session4546## Application Overview47- **Domain**: <domain>48- **Key Entities**: <entity list and relationships such as User (1:M) Orders>49- **Business Context**: <rules, constraints, compliance>50- **Scale**: <concurrent users, document sizes, retention, total requests/second>51- **Geographic Distribution**: <single region, multi-region reads, multi-region writes>5253## Access Patterns Analysis54| Pattern # | Description | RPS (Peak and Average) | Type | Attributes Needed | Key Requirements | Design Considerations | Status |55| --- | --- | --- | --- | --- | --- | --- | --- |56| 1 | Get user profile by user ID when the user logs into the app | 500 RPS | Read | userId, name, email, createdAt | <50ms latency | Simple point read with id and partition key | Yes |57| 2 | Create new user account when the user is on the sign up page | 50 RPS | Write | userId, name, email, hashedPassword | Strong consistency | Consider unique key constraints for email | Pending |5859## Entity Relationships Deep Dive60- **User → Orders**: 1:Many (avg 5 orders per user, max 1000)61- **Order → OrderItems**: 1:Many (avg 3 items per order, max 50)62- **Product → OrderItems**: 1:Many (popular products in many orders)63- **Products and Categories**: Many:Many6465## Enhanced Aggregate Analysis66### <Entity1 + Entity2> Container Item Analysis67- **Access Correlation**: <% requiring both entities>68- **Query Patterns**: Entity1 only, Entity2 only, and both together percentages69- **Size Constraints**: Combined max size in MB and growth pattern70- **Update Patterns**: Independent or related update frequencies71- **Decision**: Single Document, Multi-Document Container, or Separate Containers72- **Justification**: <reasoning>7374## Container Consolidation Analysis75| Parent | Child | Relationship | Access Overlap | Consolidation Decision | Justification |76| --- | --- | --- | --- | --- | --- |77| <Parent> | <Child> | 1:Many | <overlap> | Consolidate/Separate | <why> |7879## Design Considerations (Subject to Change)80- **Hot Partition Concerns**: <analysis>81- **Large fan-out with Many Physucal partitions based on total Datasize Concerns**: <analysis>82- **Cross-Partition Query Costs**: <trade-offs>83- **Indexing Strategy**: <composite indexes, included paths, excluded paths>84- **Multi-Document Opportunities**: <30-70% correlation candidates>85- **Multi-Entity Query Patterns**: <related retrievals>86- **Denormalization Ideas**: <duplicated attributes>87- **Global Distribution**: <write regions and consistency levels>8889## Validation Checklist90- [ ] Application domain and scale documented91- [ ] All entities and relationships mapped92- [ ] Aggregate boundaries identified based on access patterns93- [ ] Identifying relationships checked for consolidation opportunities94- [ ] Container consolidation analysis completed95- [ ] Every access pattern has: RPS (avg/peak), latency SLO, consistency level, expected result size, document size band96- [ ] Write pattern exists for every read pattern (and vice versa) unless USER explicitly declines97- [ ] Hot partition risks evaluated98- [ ] Consolidation framework applied; candidates reviewed99- [ ] Design considerations captured (subject to final validation)100```101102## Modeling decisions103104| Situation | Prefer | Reason |105| --- | --- | --- |106| `>70%` access correlation, bounded size, related operations | Multi-Document Container or embedded Single Document | Joint reads dominate and transaction scope may matter. |107| `50-70%` access correlation | Analyze operational coupling | Same backup/restore favors Multi-Document Container; different scaling or consistency favors Separate Containers. |108| `30-50%` access correlation | Compare cost and complexity carefully | Either design can be valid; quantify cross-partition query cost. |109| `<30%` access correlation | Separate Containers | Independent access dominates. |110| Child cannot exist without parent and queries always know `parent_id` | Identifying relationship with partition key `parent_id` | Avoid parent-to-child cross-partition queries. |111| Unbounded child growth | Separate documents or containers | Avoid exceeding document size and write amplification. |112113Consolidate when access overlap is `>50%`, the relationship is natural parent-child, size is bounded, and an identifying relationship exists. Keep separate when access overlap is `<30%`, growth is unbounded, or operations must scale independently.114115## Procedure1161171. Capture application overview, entities, business context, scale, geographic distribution, and compliance constraints in `cosmosdb_requirements.md`.1182. Stay in access-pattern discovery until the user confirms all reads and writes are captured. Ask, "Do you have any other access patterns to discuss? I see we have a user login access pattern but no pattern to create users. Should we add one?"1193. For each access pattern, record average/peak RPS, read/write type, attributes, latency SLO, consistency level, result size, document size band, and status.1204. Analyze aggregates, identifying relationships, access correlation, update coupling, size constraints, hot partitions, cross-partition query costs, indexing, and denormalization.1215. Only after the user confirms access patterns are complete, create `cosmosdb_data_model.md` with final container designs and justifications.1226. Group indexes with the containers they belong to; do not create a detached indexing section that loses container context.123124## Final deliverable125126Create `cosmosdb_data_model.md` only after confirmation:127128```markdown129# Azure Cosmos DB NoSQL Data Model130131## Design Philosophy & Approach132<aggregate-oriented design principles and request-unit rationale>133134## Aggregate Design Decisions135<why data was grouped together, split, or duplicated>136137## Container Designs138### <Container name>139- **Purpose**: <what it stores>140- **Document Types**: <type discriminator values if Multi-Document Container>141- **Partition Key**: <path and why>142- **ID Strategy**: <id shape>143- **Items**: <example document summaries>144- **Indexes**: <included paths, excluded paths, composite indexes grouped here>145- **Served Access Patterns**: <pattern IDs>146- **Trade-offs**: <hot partition, cross-partition, transaction, consistency notes>147```148149## Progressive disclosure and bundled resources150151- `references/extended-guide.md`: deeper Cosmos DB modeling guidance for aggregate, partition-key, indexing, and scale decisions.152153## Compatibility vocabulary154155Preserve these legacy terms, API names, command placeholders, and literal phrases when applying or migrating this skill:156157- `AP31`158- `CRITICAL`159- `Container/Separate`160- `Document/Multi-Document`161- `EVERY`162- `FILE`163- `IMMEDIATELY`164- `Independent/Related`165- `MANAGEMENT`166- `MASSIVE`167- `MOST`168- `MUST`169- `No/Yes/Yes`170- `SCALE`171- `WARNING`172- `artifacts_produced`173- `binning/chunking`174- `by-step`175- `e-commerce`176- `last_updated`177- `progressive-disclosure`178- `use-case`179- `user_id`180- `volume/size`181- `UserOrders`182183## Output template184185```markdown186## Cosmos DB data modeling result187188**Status:** requirements-updated | model-created | blocked189**Files changed:** `cosmosdb_requirements.md`, `cosmosdb_data_model.md`190191### Requirements captured192| Area | Status | Evidence |193| --- | --- | --- |194| Access patterns | <complete/incomplete> | <count and missing fields> |195| Scale and RPS | <complete/incomplete> | <avg/peak RPS notes> |196| Relationships | <complete/incomplete> | <entities and cardinality> |197198### Design summary199| Container | Partition key | Document types | Main access patterns | Key trade-off |200| --- | --- | --- | --- | --- |201| <name> | <partition key> | <types> | <pattern IDs> | <trade-off> |202203### Open questions204- <question or none>205```206207## Quality gate208209- [ ] `cosmosdb_requirements.md` was updated after every new user-provided fact.210- [ ] Every access pattern includes RPS, latency SLO, consistency, result size, and document size band.211- [ ] Every read has a matching write or an explicit user-declined write pattern.212- [ ] Massive-scale workloads triggered binning, write-reduction, and physical-partition questions.213- [ ] Aggregates were judged by access correlation, size, update coupling, and identifying relationships.214- [ ] `cosmosdb_data_model.md` was created only after the user confirmed discovery was complete.215- [ ] Index definitions are grouped under their owning containers.