Skip to main content
Version: 1.5.0

Azure Cosmos DB

Cloud Databasebackend/azurecosmos

Azure Cosmos DB is Microsoft's globally distributed, multi-model database service. It provides low-latency, elastic scale, and comprehensive SLAs for throughput, latency, availability, and consistency.

📦 Installation

go get github.com/azrod/kivigo/backend/azurecosmos

Requires an active Azure Cosmos DB account. You can create a free tier account on Azure Portal.

Dependencies

  • Azure Cosmos DB account
  • Valid connection string or account key
  • Network connectivity to Azure

✨ Features

Basic Operations
Batch Operations
Health Checks
Global Distribution
Multiple Consistency Levels
Automatic Scaling
SLA Guarantees
Multi-Model Support

🚀 Usage

package main

import (
"github.com/azrod/kivigo"
"github.com/azrod/kivigo/backend/azurecosmos"
)

func main() {
// Configuration with connection string
opt := azurecosmos.NewOptions()
opt.ConnectionString = "AccountEndpoint=<https://your-account.documents.azure.com:443/;AccountKey=your-key>;"
opt.DatabaseName = "kivigo"
opt.ContainerName = "keyvalue"

// Optional: Configure consistency level
opt.ConsistencyLevel = azurecosmos.SessionConsistency

// Optional: Configure request options
opt.RequestOptions = azurecosmos.RequestOptions{
RequestUnitsPerSecond: 400,
PartitionKey: "/id",
}

// Create backend
kvStore, err := azurecosmos.New(opt)
if err != nil {
panic(err)
}
defer kvStore.Close()

// Create client
client, err := kivigo.New(kvStore)
if err != nil {
panic(err)
}
}

📝 Notes

  • Azure Cosmos DB charges based on Request Units (RUs) consumed
  • Consider using session consistency for most applications to balance performance and consistency
  • Partition key design is crucial for performance - choose a key with good distribution
  • Use batch operations to reduce RU consumption for multiple operations
  • Monitor your RU consumption in Azure Portal to optimize costs
  • Consider using autoscale throughput for unpredictable workloads
  • The free tier provides 1000 RU/s and 25GB storage at no cost

🔗 Additional Resources