Azure Cosmos DB SDK for Java
Build Cosmos DB Applications with Java
Integrating Azure Cosmos DB into Java applications requires understanding SDK patterns and best practices. This skill provides comprehensive guidance for database operations, reactive programming, and global distribution.
Download the skill ZIP
Upload in Claude
Go to Settings → Capabilities → Skills → Upload skill
Toggle on and start using
Test it
Using "Azure Cosmos DB SDK for Java". Create a CosmosClient with session consistency and preferred regions
Expected outcome:
CosmosClient configured with endpoint from environment variables, session consistency level, preferred regions (West US, East US), direct mode connection, and user agent suffix for application identification.
Using "Azure Cosmos DB SDK for Java". Query users where status equals active
Expected outcome:
Parameterized SQL query executed against Cosmos container, returning CosmosPagedIterable of User objects filtered by status parameter, with results iterated and printed to console.
Security Audit
SafeThis is a prompt-only skill containing documentation and code examples for Azure Cosmos DB Java SDK. Static analysis scanned 0 files with 0 findings and a risk score of 0/100. The skill provides instructional content for database operations without any executable code. The only risk factor is env_access for environment variable usage in authentication examples, which is standard practice for credential management.
Risk Factors
🔑 Env variables (1)
Quality Score
What You Can Build
Enterprise Application Developer
Build scalable backend services that store and retrieve data from globally distributed Cosmos DB containers with proper partitioning strategies.
Cloud Migration Specialist
Migrate existing database applications to Azure Cosmos DB with guidance on SDK integration and consistency model selection.
Full-Stack Developer
Implement reactive data access patterns using the async client for high-throughput scenarios in modern web applications.
Try These Prompts
Show me how to create a CosmosClient in Java using environment variables for the endpoint and key. Include proper error handling.
Generate Java code to create a database and container in Cosmos DB. The container should use /userId as the partition key. Use the async client pattern.
Write Java code that creates, reads, updates, and deletes a user document in Cosmos DB using reactive chains with the async client. Include proper error handling for each operation.
Create a parameterized SQL query in Java that retrieves users by status from Cosmos DB. Configure CosmosQueryRequestOptions for optimal performance and iterate through paged results.
Best Practices
- Reuse CosmosClient instance throughout your application - creating new clients is expensive
- Choose partition keys with high cardinality and even distribution for optimal scaling
- Use async client for high-throughput scenarios and reactive programming patterns
Avoid
- Creating new CosmosClient instances for each operation - causes connection pool exhaustion
- Using strong consistency level without understanding latency implications across regions
- Ignoring 429 rate limit responses - always implement retry logic or use built-in retry policy