Microsoft Azure

Azure Cosmos DB Data Modeling

Documentation Back to Top

Introduction

Cosmos DB's data modeling capabilities allow you to design your data structures to align with your application's needs. Choosing the right data model is critical for performance, scalability, and ease of development. Cosmos DB offers multiple data models:

Document Database

The document database model is ideal for applications that require a flexible schema and need to store unstructured or semi-structured data. It's the recommended model for most use cases.

Each document is stored as a JSON object. You can include arrays and nested objects within your documents to represent complex data relationships.

                
                {
                    "firstName": "John",
                    "lastName": "Doe",
                    "age": 30,
                    "address": {
                        "street": "123 Main St",
                        "city": "Anytown",
                        "state": "CA"
                    },
                    "hobbies": ["reading", "hiking"]
                }
                
            

Graph Database

If your application relies heavily on relationships between data entities, the graph database model is a good choice. Cosmos DB's graph database allows you to represent data as nodes and edges, making it easy to query complex relationships efficiently.

This model is well-suited for use cases such as social networks, recommendation engines, and knowledge graphs.

Key-Value and JSON (SQL API)

The Key-Value and JSON (SQL API) model provides a more traditional database experience, with a SQL-like interface for querying data. It's a good choice when you need a structured data format and want to leverage SQL skills.