Skip to content

Azure Cosmos DB ​

Parity grade: A · SDK azure-sdk-for-go/sdk/data/azcosmos@v1.5.0 · last audited 2026-10-20 (658ecc434)

Category: Azure · View PARITY.md on GitHub · All Services

In-memory Cosmos DB Core (SQL) API with a SQL query engine, plus the Table API on the same port.

Quick start ​

bash
curl "http://localhost:8081/"

curl -X POST "http://localhost:8081/dbs" \
    -H "Content-Type: application/json" --data '{"id":"my-db"}'

curl -X POST "http://localhost:8081/dbs/my-db/colls" \
    -H "Content-Type: application/json" \
    --data '{"id":"my-container","partitionKey":{"paths":["/pk"],"kind":"Hash"}}'

curl -X POST "http://localhost:8081/dbs/my-db/colls/my-container/docs" \
    -H "Content-Type: application/json" \
    --data '{"id":"doc1","pk":"partition1","name":"example"}'

Go SDK:

go
cred, _ := azcosmos.NewKeyCredential(
    "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==")
client, _ := azcosmos.NewClientWithKey("http://localhost:8081", cred, nil)
_, _ = client.CreateDatabase(ctx, azcosmos.DatabaseProperties{ID: "my-db"}, nil)
db, _ := client.NewDatabase("my-db")
_, _ = db.CreateContainer(ctx, azcosmos.ContainerProperties{
    ID: "my-container",
    PartitionKeyDefinition: azcosmos.PartitionKeyDefinition{Paths: []string{"/pk"}},
}, nil)

The default master key is the real Cosmos DB Local Emulator's published key, shown above.

Supported operations ​

AreaOperations
AccountGetDatabaseAccount
DatabasesCreateDatabase, GetDatabase, ListDatabases, QueryDatabases, DeleteDatabase
ContainersCreateContainer, GetContainer, ListContainers, QueryContainers, ReplaceContainer, DeleteContainer
DocumentsCreateDocument (upsert with x-ms-documentdb-is-upsert: true), GetDocument, ListDocuments, QueryDocuments, ReplaceDocument, DeleteDocument, PatchDocument, ExecuteBatch
Change feed, partitionsReadChangeFeed, ReadPKRanges
OffersListOffers, QueryOffers, GetOffer, ReplaceOffer
ConflictsListConflicts, GetConflict, DeleteConflict, QueryConflicts
Users and permissionsusers and permissions CRUD, resource tokens
Stored procedures, triggers, UDFsCreate, Get, Replace, Delete, List and Query for each, plus ExecuteSproc (JavaScript)
Table APICreateTable, DeleteTable, ListTables, InsertEntity, GetEntity, QueryEntities, ReplaceEntity, MergeEntity, DeleteEntity, and POST /$batch (one multipart/mixed changeset on one partition, atomic)
  • GetDocument and DeleteDocument need x-ms-documentdb-partitionkey. ReplaceDocument is an upsert without If-Match and returns 412 on a mismatch.
  • Containers take up to three partition-key paths (kind: MultiHash). Point operations need every key component. A query's partition key may be a leading prefix.
  • A container defaultTtl (-1 means on, no default expiry) and per-item ttl expire documents. Expired documents are invisible at once and removed by a background sweeper.
  • Lists and queries page with x-ms-max-item-count and x-ms-continuation.

SQL support ​

SELECT [DISTINCT] [TOP n] (* | VALUE expr | expr [AS name], ...), FROM c [JOIN x IN c.arr]..., WHERE, GROUP BY, multi-key ORDER BY, OFFSET n LIMIT n, @parameters, COUNT/SUM/AVG/MIN/MAX, EXISTS, ARRAY and scalar subqueries, IN, BETWEEN, LIKE, ?:, ??, and string, math, type-check, array, date and spatial functions. Full list: parity audit.

Configuration ​

Cosmos DB runs on its own TCP port, as the real emulator does. Startup fails if the port is taken.

FlagEnvDefaultPurpose
--cosmosdb-portCOSMOSDB_PORT8081Listener port
--cosmosdb-master-keyCOSMOSDB_MASTER_KEYemulator keyKey checked when auth validation is on
--cosmosdb-validate-authCOSMOSDB_VALIDATE_AUTHfalseVerify master-key signatures on every request
--cosmosdb-enforce-throughputCOSMOSDB_ENFORCE_THROUGHPUTfalseThrottle with 429 once a container's provisioned RU/s is spent
--cosmosdb-burst-capacityCOSMOSDB_BURST_CAPACITYfalseLet a partition spend up to 300 s of idle RU/s at up to 3000 RU/s. Needs enforce-throughput
--cosmosdb-serverlessCOSMOSDB_SERVERLESSfalseReject throughput provisioning and cap containers at 5000 RU/s. Needs enforce-throughput to throttle
--cosmosdb-resource-token-max-secondsCOSMOSDB_RESOURCE_TOKEN_MAX_SECONDS86400Resource-token lifetime, 600 to 86400
noneCOSMOSDB_TLS=trueoffServe HTTPS with an in-memory self-signed certificate
noneCOSMOSDB_TLS_HOSTSnoneExtra certificate hosts (the certificate already covers localhost, 127.0.0.1, ::1)

With COSMOSDB_TLS=true, point the SDK at https://localhost:8081 and skip certificate verification.

With validation on, every request must carry a correctly signed Authorization: type=master&ver=1.0&sig=... header and an x-ms-date (or Date) within 15 minutes of server time, or it gets 401. Table API requests may use SharedKey or SharedKeyLite with the same key.

Throughput offers (/offers, the x-ms-offer-throughput and x-ms-cosmos-offer-autopilot-settings headers) are always served. An overdrawn budget returns 429 with x-ms-retry-after-ms and x-ms-substatus: 3200.

Differences from Azure ​

WARNING

Authentication is off by default: any Authorization header, or none, is accepted. Use --cosmosdb-validate-auth to check signatures.

  • Queries the indexing policy cannot serve are rejected unless the request sends x-ms-documentdb-query-enable-scan.
  • x-ms-request-charge is an approximation from payload size and operation. Nothing is throttled unless --cosmosdb-enforce-throughput is set.

Parity & Coverage ​

MetricValue
PARITY entries audited35 (35 ok)
Feature families24 (24 ok)
Known gapsnone
Deferred items0
Resource leaksclean

Audited Operations ​

35 audited operations
OperationWireErrorsStatePersist
GetDatabaseAccountokokn/an/a
CreateDatabaseokokokok
GetDatabaseokokokn/a
ListDatabasesokokokn/a
DeleteDatabaseokokokok
CreateContainerokokokok
GetContainerokokokn/a
ListContainersokokokn/a
DeleteContainerokokokok
QueryDatabasesokokokn/a
QueryContainersokokokn/a
ReplaceContainerokokokok
CreateDocumentokokokok
QueryDocumentsokokokn/a
ListDocumentsokokokn/a
GetDocumentokokokn/a
ReplaceDocumentokokokok
DeleteDocumentokokokok
PatchDocumentokokokok
ExecuteTransactionalBatchokokokok
ReadChangeFeedokokokok
ListOffersokokokok
QueryOffersokokokn/a
GetOfferokokokn/a
ReplaceOfferokokokok
ReadPartitionKeyRangesokokokok
StoredProceduresokokokok
Triggersokokokok
UserDefinedFunctionsokokokok
Usersokokokok
Permissionsokokokok
ExecuteStoredProcedureokokokok
ListConflictsokokokok
GetConflictokokokn/a
DeleteConflictokokokok

Audited Feature Families ​

Feature FamilyStatus
server_side_scriptsok
change_feedok
conflict_resolutionok
multi_regionok
authok
resource_tokensok
wire_protocolok
sql_queryok
indexingok
searchok
continuationok
ttlok
throughputok
request_chargeok
partition_keysok
tlsok
edm_fidelityok
etag_and_timestampok
aliasingok
composite_keysok
persistenceok
routing_isolationok
observabilityok
table_apiok

Released under the MIT License.