The Azure Cosmos DB SDK for Rust is now generally available. It is a native client for Azure Cosmos DB for NoSQL, built for production workloads, and it builds on the public preview we shipped earlier this year.
The theme of this release is simple: the SDK comes with the right defaults for production, and they are on by default. Features that other SDKs make you opt into, the Rust SDK turns on for you with no extra configuration.
Production-ready by default
Three things make the Rust SDK a strong default for demanding workloads, and you get all of them without changing a setting:
- Low latency with Gateway v2. The SDK uses Gateway v2, a rewritten, performance-optimized gateway path, so you get low latency without the complexity and client overhead of direct-mode.
- Efficient network traffic and parsing. Support for the Cosmos Binary serialization format is enabled by default, reducing serialization costs, RU costs, and bytes on the wire.
- Reliability by default. Per-partition automatic failover (PPAF) and the per-partition circuit breaker (PPCB) keep failover contained to a single partition instead of failing the entire container to a different region, which matters most for accounts with very high partition counts.
The Rust SDK also retries read and write operations for you when a retry is safe. However, some operations (executing stored procedures and certain patch operations) cannot be safely retried by the SDK.
Hardened at hyperscale with OpenAI
Between preview and GA, we ran the SDK against one of the largest NoSQL workloads in the world. OpenAI moved real production traffic onto it and worked with us as they went. That scale surfaced issues no synthetic benchmark would reproduce: accounts with very high partition counts, highly contended documents, and imperfect network conditions. Each finding became a fix, and each fix shipped in a release. Read more about OpenAI’s journey to rapidly scaling online storage to serve over 1 billion ChatGPT users in part part 1 and part 2 of their blog series!
The hardening covered topology discovery at very high partition counts, retry behavior under network stress, and safe-by-default write retries.
Built on a new native driver core
The performance and reliability above come from a new native driver core: a single, shared implementation of the SDK’s most performance-sensitive logic, written for speed and correctness. It uses binary encoding on the hot path, is exercised by round-trip fuzzing, and runs under a soak harness that keeps it under sustained load.
Future SDKs will be built on top of this same core, using it directly to provide consistent features across all our language SDKs.
Already in production
Adoption is the clearest signal that this is ready. As OpenAI migrated production write traffic onto the Rust SDK, its share of their Cosmos DB traffic grew until it passed the other language SDKs.
Adoption momentum: the Rust SDK’s share of production traffic, rising over time (illustrative).
Running the Rust client alongside an existing one kept that migration safe: traffic could shift gradually, with an easy fallback if anything looked off.
What is new since preview
| Area | Preview | General Availability |
|---|---|---|
| Latency | Baseline | Gateway v2, on by default |
| Serialization | JSON | Native driver with binary encoding |
| Availability | Regional | Per-partition failover (PPAF) and circuit breaker (PPCB), on by default |
| Write retries | Basic | Safe by default, automatic wherever a retry is safe |
| Queries | Single-partition focus | Cross-partition query support |
| Tail latency | Baseline | Optional request hedging |
Getting started
Prerequisites:
- An Azure subscription, an Azure Cosmos DB for NoSQL free trial account, or the Azure Cosmos DB Emulator.
- A working Rust development environment.
Add the dependencies to your Cargo.toml (confirm the exact GA version before publishing):
[dependencies]
azure_data_cosmos = "1.0.0"
azure_identity = "1.0.0"
azure_core = "1.0.0"
tokio = { version = "1", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
futures = "0.3"
Create a client using DefaultAzureCredential (recommended, authenticates via Microsoft Entra ID):
use azure_data_cosmos::CosmosClient;
use azure_identity::DefaultAzureCredential;
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let credential = DefaultAzureCredential::new()?;
let client = CosmosClient::new("myCosmosAccount", credential, None)?;
println!("Cosmos client initialized successfully");
Ok(())
}
Create an item:
use azure_data_cosmos::PartitionKey;
use serde::Serialize;
#[derive(Serialize)]
struct Item {
id: String,
#[serde(rename = "myPartitionKey")]
my_partition_key: String,
name: String,
}
let item = Item {
id: "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb".to_string(),
my_partition_key: "myPartitionKeyValue".to_string(),
name: "Theo".to_string(),
};
let partition_key = PartitionKey::from(item.my_partition_key.clone());
container_client.create_item(partition_key, item, None).await?;
Query items with familiar SQL syntax:
use futures::StreamExt;
let query = "SELECT * FROM c";
let pk = PartitionKey::from("myPartitionKeyValue");
let mut items = container_client.query_items::<serde_json::Value>(query, pk, None)?;
while let Some(page) = items.next().await {
let page = page?.into_body().await?;
for item in page.items {
println!("{:#?}", item);
}
}
Next steps
The Azure Cosmos DB SDK for Rust is now ready for production. Explore our samples repository, follow the quickstart guide, and browse the source on GitHub.
We welcome your feedback. If you have questions or suggestions, please open an issue on our GitHub repository. We cannot wait to see what you build with Azure Cosmos DB and Rust.
About Azure Cosmos DB
Azure Cosmos DB is a fully managed and serverless NoSQL and vector database for modern app development, including AI applications. With its SLA-backed speed and availability as well as instant dynamic scalability, it is ideal for real-time NoSQL and MongoDB applications that require high performance and distributed computing over massive volumes of NoSQL and vector data.
Try Azure Cosmos DB for free here. To stay in the loop on Azure Cosmos DB updates, follow us on X, YouTube, and LinkedIn.
0 comments
Be the first to start the discussion.