Microsoft Azure Documentation

Your comprehensive guide to Azure services and solutions.

Introduction to Azure Cosmos DB

Azure Cosmos DB is Microsoft's globally distributed, multi-model database service. It allows you to elastically and independently scale throughput and storage across any number of geographic regions. You can turn on multi-region writes with global distribution and low-latency access to your data anywhere in the world.

What is Azure Cosmos DB?

Azure Cosmos DB is a NoSQL database service that supports multiple data models, including document, key-value, graph, and column-family. It's designed for:

Key Features

Use Cases

Azure Cosmos DB is ideal for a wide range of applications, including:

Getting Started

To get started with Azure Cosmos DB, you'll typically perform these steps:

  1. Create an Azure Cosmos DB Account: Choose an API and a region.
  2. Create a Database and Container: Define your data storage structure.
  3. Ingest Data: Add your application data to the container.
  4. Query Data: Retrieve and manipulate data using the chosen API's query language.

Example: Creating a container using SQL API

Here's a conceptual example of how you might interact with Cosmos DB using its SQL API. For a real-world scenario, you would use an SDK.

// Conceptual representation using a hypothetical SDK
import com.azure.cosmos.CosmosClient;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.CosmosDatabase;
import com.azure.cosmos.models.CosmosContainerProperties;
import com.azure.cosmos.models.CosmosContainerResponse;

public class CreateContainerExample {

    // Replace with your actual endpoint and key
    private static final String ENDPOINT = "https://YOUR_COSMOS_DB_ACCOUNT.documents.azure.com:443/";
    private static final String KEY = "YOUR_PRIMARY_KEY";
    private static String DATABASE_ID = "MyDatabase";
    private static String CONTAINER_ID = "MyContainer";

    public static void main(String[] args) {
        CosmosClient client = new CosmosClientBuilder()
                .endpoint(ENDPOINT)
                .key(KEY)
                .buildClient();

        CosmosDatabase database = client.getDatabase(DATABASE_ID);

        try {
            // Define container properties
            CosmosContainerProperties containerProperties = new CosmosContainerProperties(CONTAINER_ID, "/partitionKey");

            // Create the container
            CosmosContainerResponse containerResponse = database.createContainer(containerProperties);

            System.out.println("Container created with id: " + containerResponse.getProperties().getId());

        } catch (Exception e) {
            System.err.println("Error creating container: " + e.getMessage());
        } finally {
            client.close();
        }
    }
}

This introduction provides a high-level overview of Azure Cosmos DB. Dive deeper into the subsequent tutorials to learn about specific aspects like account creation, data modeling, and performance optimization.