Cosmos DB Reference Data Sync from Dataverse
When reference data (catalogs, config, pricing) changes in Dataverse, the flow upserts the corresponding document into Cosmos DB so app reads stay fast and current, handling partition keys and soft-delete removals. Keeps Cosmos read-models in sync with the system of record.
Provided as-is, without warranty of any kind. Review and test each pattern in a non-production environment before deploying it to live automations. See our Terms.
Overview
This flow keeps an Azure Cosmos DB read model in sync with the system of record in Microsoft Dataverse. When a reference-data row (catalog, config, pricing, etc.) is added or modified, the flow projects the row into a Cosmos document and upserts it; when a row is deactivated (soft delete), the matching document is deleted from Cosmos. Every run is stamped with a correlation id and the outcome is posted to a Microsoft Teams channel.
Why it matters: apps read reference data from Cosmos for low-latency, globally-distributed reads, but the data is mastered in Dataverse. Propagating each change keeps the Cosmos read model accurate without app-side lookups or batch jobs.
Ships Off (demo). Connector-first throughout - no HTTP actions.
Use Case
A Cosmos-backed application needs Dataverse-mastered reference data available locally and current. Operations/dev teams maintain catalogs, configuration, and pricing in a Dataverse table; this flow mirrors each change into Cosmos so reads stay fast and consistent, and deactivating a row removes it from the read model.
Flow Architecture
When Reference Data Is Added or Modified
Dataverse - SubscribeWebhookTriggerFires on add/modify of a flowlibs_referencedata row (organization scope).
Initialize Trace & Config
Initialize variableMints a correlation id; binds the Cosmos account/database/container and Teams ids; sets the partition key from the row Category.
Compose Reference Document
ComposeProjects the Dataverse row into the Cosmos document shape (id = Reference Key, category = partition key, name, version, payload, isActive, sourceRowId, syncedUtc, correlationId).
Branch on Is Active
ConditionActive rows upsert the document into Cosmos (CreateDocument_V3, is-upsert); deactivated rows delete it (DeleteDocument_V2 with the partition-key header) - the soft-delete propagation.
Notify Sync Result
Teams - PostMessageToConversationPosts the outcome (upsert/delete, key, category, correlation id) to the Teams channel.
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_CosmosAccountName | String | flowlibs-cosmos | Azure Cosmos DB (SQL/Core API) account name. |
| flowlibs_CosmosDatabaseId | String | ReferenceDb | Cosmos database (DB) ID. |
| flowlibs_CosmosContainerId | String | ReferenceData | Cosmos container ID (partition key /category). |
| flowlibs_TeamsGroupId | String | <your-team-id> | Teams team/group id for notifications. |
| flowlibs_TeamsChannelId | String | <your-channel-id> | Teams channel id for notifications. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| Azure Cosmos DB | shared_documentdb | CreateDocument_V3 DeleteDocument_V2 |
| Microsoft Dataverse | shared_commondataserviceforapps | SubscribeWebhookTrigger |
| Microsoft Teams | shared_teams | PostMessageToConversation |
Note — All connections are referenced as solution connection references; the flow is portable between environments as long as a connection is mapped at import time.
Customization Guide
Almost every realistic variant of this flow can be implemented by changing environment variable values. A few cases require small edits inside the flow definition — those are called out explicitly below.
- Bulk seed
- Build a companion scheduled flow that lists all active rows and upserts each into Cosmos for an initial full load.
- Hard deletes
- To also catch hard deletes, change the trigger to Added/Modified/Deleted and add delete-detection; the soft-delete pattern is preferred for reliability.
- Partition strategy
- Change the partition key column by editing the partition-key init and the document category field; keep the container's partition key path in sync.
- Idempotency
- id = Reference Key makes upserts idempotent and safe to replay.
- Versioning / cache-bust
- version is carried into the document so downstream apps can invalidate caches.
Key Expressions
The flow is intentionally light on Power Fx / WDL gymnastics — the heaviest expressions are the branch-name concatenation and the approval outcome check. They are listed below in the order they appear in the flow.
EXPR.01Trigger row field
Business key used as the Cosmos document id.
EXPR.02Active check
Branches upsert vs delete.
EXPR.03Partition key (delete header)
JSON array passed via the raw-partitionkey header on delete.
EXPR.04Upsert body
The projected document upserted into Cosmos.
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.