Azure Cosmos DB Cassandra API

Azure Cosmos DB is a globally distributed, multi-model database service. The Cassandra API in Azure Cosmos DB provides a managed Apache Cassandra service that allows you to use familiar Cassandra SDKs, drivers, and tools. This enables you to leverage the benefits of a cloud-native database solution while maintaining compatibility with your existing Cassandra applications.

Key Features

  • Global Distribution: Distribute your data across multiple Azure regions for high availability and low-latency access.
  • Scalability: Scale your throughput and storage independently to meet the demands of your application.
  • High Availability: Achieve 99.999% availability with built-in fault tolerance and automatic failover.
  • Schema Flexibility: Benefit from the flexible schema of Cassandra while enjoying the managed service features.
  • Compatibility: Use existing Apache Cassandra drivers and tools without code changes.
  • Cost-Effectiveness: Pay only for what you use with flexible pricing options.

Getting Started

To start using Azure Cosmos DB with the Cassandra API:

  1. Create an Azure Cosmos DB Account: Choose the Cassandra API during account creation.
  2. Create a Keyspace: A keyspace is a container for tables, similar to a database in other systems.
  3. Create Tables: Define your table schema using CQL (Cassandra Query Language).
  4. Connect Your Application: Use your preferred Cassandra driver to connect to your Azure Cosmos DB account.
Important: Ensure you use the correct connection string and port (default is 1035) when connecting from your application.

Connecting with Drivers

Here's a conceptual example of connecting using the Java driver:


import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;

public class CosmosDbCassandraConnection {
    public static void main(String[] args) {
        // Replace with your Cosmos DB account name and primary key
        String host = "your_cosmosdb_account_name.cassandra.cosmos.azure.com";
        String password = "your_primary_key";
        String port = "1035";
        String localDataCenter = "your_datacenter_name"; // e.g., "West US"

        Cluster cluster = Cluster.builder()
            .addContactPoint(host)
            .withPort(Integer.parseInt(port))
            .withCredentials(host, password)
            .build();

        // For TLS/SSL:
        // Cluster cluster = Cluster.builder()
        //     .addContactPoint(host)
        //     .withPort(Integer.parseInt(port))
        //     .withSSL()
        //     .withCredentials(host, password)
        //     .build();

        Session session = cluster.connect();

        System.out.println("Successfully connected to Azure Cosmos DB Cassandra API!");

        // Example: Create a keyspace
        // session.execute("CREATE KEYSPACE IF NOT EXISTS mykeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }");
        // System.out.println("Keyspace 'mykeyspace' created or already exists.");

        // Example: Use a keyspace
        // session.execute("USE mykeyspace");

        session.close();
        cluster.close();
    }
}
                    

Learn More