Enabling Analytical Store
Complete the full lesson to earn 25 points — 50 with Pro
Work through each section, then tap “Mark as Complete” on the last one.
✦ Skip the page breaks, the wait, and see fewer ads — read each lesson on a single page with Pro
Enabling and Managing the Azure Cosmos DB Analytical Store
Introduction to Analytical Workloads in Cosmos DB
In the world of modern data engineering, we often find ourselves caught between two competing needs: the requirement for fast, transactional updates to our data and the necessity to perform deep, complex analytics on that same data. Traditionally, this meant building complex extract-transform-load (ETL) pipelines to move data from a transactional database into a separate data warehouse. This process is not only time-consuming but also creates data latency, where your analytics are always reflecting the state of the world from several hours or even days ago.
Azure Cosmos DB addresses this fundamental challenge through the Analytical Store. The Analytical Store is a fully isolated, column-oriented storage layer that allows you to perform large-scale analytics on your operational data without impacting the performance of your transactional workloads. By enabling this feature, you essentially bridge the gap between operational databases and analytical engines like Azure Synapse Analytics or Azure Databricks. Understanding how to enable and manage this store is critical for any engineer looking to build real-time reporting or machine learning pipelines directly on top of their operational data.
This lesson explores the mechanics of the Analytical Store, how to enable it, how it interacts with the transactional store, and the best practices for ensuring your analytical queries remain performant and cost-effective.
Understanding the Architecture: Transactional vs. Analytical
To understand the Analytical Store, we must first look at the Transactional Store. The Transactional Store is row-oriented and optimized for low-latency CRUD operations—creating, reading, updating, and deleting records. It is designed to handle high concurrency and provide predictable performance for individual record lookups or small batch updates.
The Analytical Store, by contrast, is column-oriented. Columnar storage is highly efficient for analytical queries that process large volumes of data, such as calculating averages, sums, or performing complex joins across thousands or millions of records. Because the data is stored by column rather than by row, the engine only needs to read the specific columns requested in a query, which significantly reduces the amount of I/O required.
Callout: Row-Oriented vs. Column-Oriented Storage The Transactional Store (Row-Oriented) is designed for writing and reading complete records. If you need to update a user's address or fetch a specific order by ID, the row-oriented structure ensures the operation is completed in milliseconds. The Analytical Store (Column-Oriented) is designed for aggregation. If you need to calculate the average sales price across a million transactions, the columnar store allows the system to scan only the 'Price' column, ignoring the user names, addresses, and other metadata, leading to massive performance gains for large-scale analytical tasks.
The Automatic Sync Process
One of the most powerful aspects of the Analytical Store is the automatic synchronization process. When you enable the Analytical Store for a container, Azure Cosmos DB automatically moves data from the transactional store to the analytical store. This happens in near real-time, typically within a minute of the transaction being committed. You do not need to write code to manage this movement; it is a managed service background process that is entirely transparent to your application.
Enabling the Analytical Store
Enabling the Analytical Store is a configuration task performed at the container level. It is important to note that this is a "set it and forget it" configuration; once enabled, all data inserted into that container is automatically replicated to the analytical layer.
Step-by-Step: Enabling via Azure Portal
- Navigate to your Azure Cosmos DB account in the Azure portal.
- Select Data Explorer from the left-hand menu.
- Select your database and the specific container you wish to configure.
- Click on Settings in the top menu of the container view.
- Look for the Analytical Store section.
- Toggle the switch to On.
- If you have not yet enabled the Synapse Link for your account, you will be prompted to do so. Synapse Link is the underlying integration that connects Cosmos DB to the analytical engines.
- Click Save to apply the changes.
Enabling via Azure CLI
If you prefer infrastructure-as-code or command-line tools, you can enable the Analytical Store during container creation or update an existing container.
# Update an existing container to enable Analytical Store
az cosmosdb sql container update \
--resource-group MyResourceGroup \
--account-name MyCosmosAccount \
--database-name MyDatabase \
--name MyContainer \
--analytical-storage-ttl -1
Note: Setting the
--analytical-storage-ttlto-1means the data will be kept in the Analytical Store indefinitely. You can set this to a positive integer to define a time-to-live in seconds, after which the data will be purged from the Analytical Store automatically.
Working with Analytical Data: Synapse Link
Once the Analytical Store is enabled, you need a way to query it. This is where Azure Synapse Link comes into play. Synapse Link allows you to create a "Linked Service" in Azure Synapse Analytics that points to your Cosmos DB container.
Creating a Linked Service
Within your Synapse workspace, you navigate to the Manage tab, select Linked Services, and then click New. Choose Azure Cosmos DB (SQL API) as the source. You will provide your connection string and select the appropriate database. Once the link is established, you can query your data using T-SQL or Spark notebooks.
Querying with T-SQL (Serverless SQL Pool)
Once the link is created, you can write standard SQL queries against your Cosmos DB data. This is incredibly powerful because it allows data analysts who are comfortable with SQL to interact with NoSQL data without needing to learn the Cosmos DB SDK or partition key structures.
SELECT
category,
SUM(price) as TotalSales
FROM OPENROWSET(
'CosmosDB',
'account=my-cosmos-account;database=my-db;container=my-container',
'SELECT * FROM c'
) AS [data]
GROUP BY category
In this example, the OPENROWSET function acts as the interface to the analytical store. The query engine automatically translates this SQL into an efficient scan of the columnar data, providing results in a fraction of the time it would take to iterate through the transactional store.
Best Practices for Analytical Workloads
While the Analytical Store is easy to enable, getting the most out of it requires understanding how to structure your data and how to manage your storage costs.
1. Data Modeling for Analytics
In the transactional store, we often use denormalization to optimize for read performance. For the analytical store, this remains a good strategy. Because the analytical store is columnar, having wide tables (many columns) is perfectly fine. You should aim to structure your documents so that fields frequently used for filtering or grouping are at the top level of your JSON documents.
2. Monitoring Analytical Storage Costs
The Analytical Store is billed separately from the Transactional Store. You are charged for the storage space used and for the read/write operations performed by the analytical engine. To keep costs down, use the Time-to-Live (TTL) feature to automatically expire data that is no longer needed for analytics. If you only need to run reports on the last 90 days of data, set your analytical TTL to 7,776,000 seconds.
3. Avoiding Common Pitfalls
One of the most common mistakes is attempting to run heavy analytical queries against the Transactional Store using the Cosmos DB SDK. This consumes Request Units (RUs) that are needed for your application's operational traffic. If your application starts experiencing latency or 429 (Too Many Requests) errors, it is a clear sign that you should be offloading those queries to the Analytical Store.
Warning: Never attempt to perform large-scale aggregations on the Transactional Store. Even if you have provisioned high RUs, the row-oriented nature of the store makes it inefficient for scanning millions of rows. Always use the Analytical Store for these types of operations to protect your operational application's performance.
4. Schema Evolution
Cosmos DB is schema-agnostic, which is great for flexibility. However, the Analytical Store needs to infer a schema from your JSON documents. If your documents have inconsistent structures—for example, one document has an integer price and another has a string price—the schema inference process might fail or create data type mismatches in the analytical layer. Ensure your application logic enforces a consistent schema for fields that you intend to analyze.
Comparison: Transactional vs. Analytical Store
The following table summarizes the key differences between the two storage layers to help you decide when to use which.
| Feature | Transactional Store | Analytical Store |
|---|---|---|
| Data Format | Row-oriented | Column-oriented |
| Primary Use Case | Real-time CRUD operations | Large-scale aggregations, BI, ML |
| Performance | Low-latency (ms) | High-throughput (for scans) |
| Billing | Provisioned RUs | Storage + Analytical Read/Write units |
| Sync Mechanism | Immediate | Near real-time (background) |
| Schema | Flexible | Schema-on-read (inferred) |
Implementing Advanced Analytical Patterns
Beyond simple aggregations, the Analytical Store is the backbone for sophisticated data pipelines. Let’s consider a scenario where you are running a retail platform and want to build a real-time dashboard that shows the most popular products in the last hour.
Pattern: The Lambda Architecture Evolution
In the past, you might have used a Kappa or Lambda architecture, involving complex stream processing like Apache Kafka or Azure Stream Analytics. With Cosmos DB Analytical Store, you can simplify this significantly. Your application writes orders to the transactional store. The analytical store automatically picks up these writes. Your Power BI dashboard or Synapse notebook queries the analytical store directly.
Spark Integration
For more advanced data science tasks, you can connect Azure Databricks or Synapse Spark pools to the Analytical Store. Using the Cosmos DB Spark connector, you can load your data into a DataFrame and apply machine learning models.
# Example of reading analytical store into a Spark DataFrame
df = spark.read \
.format("cosmos.olap") \
.option("spark.synapse.linkedService", "MyCosmosLink") \
.option("spark.cosmos.container", "Orders") \
.load()
# Perform a quick ML aggregation
from pyspark.sql.functions import avg
result = df.groupBy("product_id").agg(avg("price"))
result.show()
This code snippet demonstrates the simplicity of moving from raw operational data to a Spark-based analysis environment. The cosmos.olap format tells the Spark engine to specifically target the columnar analytical store, ensuring that the operation is performant and does not compete with your operational transactions.
Troubleshooting Analytical Sync Issues
Sometimes, you might notice that your analytical queries are not returning the most recent data. While the synchronization is "near real-time," there are factors that can influence this latency.
- System Load: During periods of extremely high volume, the background sync process may experience a slight delay.
- Container Configuration: Ensure that the Analytical Store is actually enabled on the container. You can verify this by checking the container settings in the portal.
- Data Types: As mentioned earlier, inconsistent data types can sometimes cause issues with the analytical schema inference. Check your application logs to ensure that your data is being written in the expected format.
- Synapse Link Status: Verify that your Synapse Link is healthy and that the credentials used for the Linked Service have not expired or been revoked.
Best Practices for Cost Management
Since Analytical Store billing is based on both storage volume and analytical read/write operations, you should be intentional about how you manage your data.
- Use Analytical TTL: As mentioned, this is the single most important setting for cost control. If you have years of historical data but only need to report on the last year, set a TTL of 31,536,000 seconds.
- Filter Aggressively: In your analytical queries, always include filters that restrict the scope of the data. For instance, if you are calculating monthly sales, filter by the month column in your SQL query. This reduces the number of Analytical Read units consumed.
- Project Only Necessary Columns: When using
SELECT *, you may be pulling more data than you need. Explicitly naming the columns in yourSELECTstatement helps the analytical engine optimize its I/O. - Partitioning Strategy: While the analytical store handles its own partitioning, your choice of partition key in the transactional store still influences how data is distributed. A good partition key that spreads data evenly will also help the analytical store perform more efficiently.
Practical Example: Building an Inventory Alert System
Let's imagine you are building an inventory management system. Your goal is to trigger an alert if the stock level of any product falls below a certain threshold.
- Transactional Layer: Your warehouse application updates the
stock_levelfield in theInventorycontainer whenever an item is sold. This is an O(1) operation that is very fast. - Analytical Layer: You have an analytical query that runs every 5 minutes to check for low stock.
- The Query:
SELECT product_id, stock_level FROM OPENROWSET(...) WHERE stock_level < 10 - The Outcome: Because this query runs against the Analytical Store, it has zero impact on the warehouse application's ability to process sales. Even if the warehouse is under heavy load, the alert system continues to function smoothly.
This pattern demonstrates the decoupling of operational and analytical concerns, which is the primary benefit of the Analytical Store.
Common Questions and FAQ
Can I enable the Analytical Store on an existing container?
Yes, you can enable the Analytical Store on an existing container at any time. Once enabled, the system will begin the synchronization process for all new data and, depending on the configuration, may backfill existing data.
Does the Analytical Store consume my Provisioned RUs?
No. The Analytical Store is billed separately. Operations performed against the Analytical Store do not consume the Request Units (RUs) provisioned for your transactional container. This is why it is the preferred method for analytical workloads.
Is the Analytical Store available for all Cosmos DB APIs?
Currently, the Analytical Store is primarily supported for the SQL (Core) API and the MongoDB API. Always check the official Azure documentation for the most current list of supported APIs and feature availability.
How does the Analytical Store handle updates to documents?
When a document is updated in the Transactional Store, the change is reflected in the Analytical Store. The system maintains the latest version of the document in the columnar format. If you need to track the history of changes (e.g., for an audit log), you should implement a versioning strategy in your application, such as adding a timestamp and version field to your documents.
Key Takeaways
To conclude this lesson, here are the most important points to remember when working with the Azure Cosmos DB Analytical Store:
- Isolation is Key: The Analytical Store provides a dedicated columnar storage layer that separates your analytical workloads from your transactional workloads, preventing performance degradation for your operational applications.
- Columnar Efficiency: By storing data in a column-oriented format, the Analytical Store is significantly more efficient for large-scale aggregations and analytical queries compared to the row-oriented transactional store.
- Managed Synchronization: The sync process from the Transactional to the Analytical store is fully managed and occurs in near real-time, removing the need for manual ETL processes.
- Synapse Link Integration: Leverage Azure Synapse Link to connect your Cosmos DB data to powerful analytical engines like Synapse SQL and Spark without moving your data.
- Cost Management: Always utilize the Analytical TTL feature to manage storage costs, and optimize your queries by filtering and selecting only the necessary columns to reduce Analytical Read unit consumption.
- Schema Consistency: Ensure that your application writes data with a consistent schema to prevent issues with the automated schema inference process in the Analytical Store.
- Protect Your RUs: Make it a hard rule that any query involving large-scale data aggregation or scanning must be routed through the Analytical Store rather than the Transactional Store to preserve your Request Unit budget.
By mastering these concepts, you can build sophisticated, data-driven applications that provide real-time insights without compromising the performance or reliability of your transactional systems. The Analytical Store is a powerful tool in the modern data architect's kit, and applying these practices will ensure your implementations are efficient, scalable, and cost-effective.
Reach the last section to complete this lesson and earn points — you're on section 1 of 10.
- Introduction to Cosmos DB Data Modeling
- Introduction to Cosmos DB Data Modeling Quiz5q
- Multiple Entity Types in Same Container
- Multiple Entity Types in Same Container Quiz5q
- Storing Related Entities in Same Document
- Storing Related Entities in Same Document Quiz5q
- Denormalizing Data Across Documents
- Denormalizing Data Across Documents Quiz5q
- Referencing Between Documents
- Referencing Between Documents Quiz5q
- Partition Keys and Document IDs
- Partition Keys and Document IDs Quiz5q
- Time to Live (TTL) Configuration
- Time to Live (TTL) Configuration Quiz5q
- Document Versioning Strategies
- Document Versioning Strategies Quiz5q
- Schema Versioning Patterns
- Schema Versioning Patterns Quiz5q
- Choosing Partition Strategies
- Choosing Partition Strategies Quiz5q
- Partition Key Selection Best Practices
- Partition Key Selection Best Practices Quiz5q
- Transactions and Partition Keys
- Transactions and Partition Keys Quiz5q
- Cross-Partition Query Costs
- Cross-Partition Query Costs Quiz5q
- Data Distribution Analysis
- Data Distribution Analysis Quiz5q
- Throughput Distribution Planning
- Throughput Distribution Planning Quiz5q
- Synthetic Partition Keys
- Synthetic Partition Keys Quiz5q
- Hierarchical Partition Keys
- Hierarchical Partition Keys Quiz5q
- Throughput and Storage Requirements
- Throughput and Storage Requirements Quiz5q
- Serverless vs Provisioned Throughput
- Serverless vs Provisioned Throughput Quiz5q
- Database-Level Provisioned Throughput
- Database-Level Provisioned Throughput Quiz5q
- Granular Scale Units
- Granular Scale Units Quiz5q
- Global Distribution Costs
- Global Distribution Costs Quiz5q
- Configuring Throughput in Portal
- Configuring Throughput in Portal Quiz5q
- Gateway vs Direct Connectivity Mode
- Gateway vs Direct Connectivity Mode Quiz5q
- Creating Database Connections
- Creating Database Connections Quiz5q
- Azure Cosmos DB Emulator
- Azure Cosmos DB Emulator Quiz5q
- Connection Error Handling
- Connection Error Handling Quiz5q
- Singleton Pattern for Clients
- Singleton Pattern for Clients Quiz5q
- Global Distribution Regions
- Global Distribution Regions Quiz5q
- Threading and Parallelism
- Threading and Parallelism Quiz5q
- Arrays and Nested Objects Queries
- Arrays and Nested Objects Queries Quiz5q
- Correlated Subqueries
- Correlated Subqueries Quiz5q
- Array and Type-Checking Functions
- Array and Type-Checking Functions Quiz5q
- Mathematical and String Functions
- Mathematical and String Functions Quiz5q
- Date Functions in Queries
- Date Functions in Queries Quiz5q
- Point Operations vs Query Operations
- Point Operations vs Query Operations Quiz5q
- CRUD Point Operations
- CRUD Point Operations Quiz5q
- Patch Operations for Updates
- Patch Operations for Updates Quiz5q
- Transactional Batch Operations
- Transactional Batch Operations Quiz5q
- Bulk Operations with SDK
- Bulk Operations with SDK Quiz5q
- Optimistic Concurrency with ETags
- Optimistic Concurrency with ETags Quiz5q
- Query Pagination and Continuation
- Query Pagination and Continuation Quiz5q
- Cosmos DB Mirroring for Fabric
- Cosmos DB Mirroring for Fabric Quiz5q
- Mirroring vs Spark Connector
- Mirroring vs Spark Connector Quiz5q
- Enabling Analytical Store
- Enabling Analytical Store Quiz5q
- Synapse Spark and SQL Queries
- Synapse Spark and SQL Queries Quiz5q
- Change Data Capture in Analytical Store
- Change Data Capture in Analytical Store Quiz5q
- Azure Functions and Event Hubs Integration
- Azure Functions and Event Hubs Integration Quiz5q
- Denormalization with Change Feed
- Denormalization with Change Feed Quiz5q
- Referential Integrity with Change Feed
- Referential Integrity with Change Feed Quiz5q
- Azure AI Search Integration
- Azure AI Search Integration Quiz5q
- Azure Functions Change Feed Trigger
- Azure Functions Change Feed Trigger Quiz5q
- Consuming Change Feed with SDK
- Consuming Change Feed with SDK Quiz5q
- Change Feed Estimator
- Change Feed Estimator Quiz5q
- Denormalization via Change Feed
- Denormalization via Change Feed Quiz5q
- Aggregation Persistence with Change Feed
- Aggregation Persistence with Change Feed Quiz5q
- Read-Heavy vs Write-Heavy Indexing
- Read-Heavy vs Write-Heavy Indexing Quiz5q
- Index Type Selection
- Index Type Selection Quiz5q
- Custom Indexing Policies
- Custom Indexing Policies Quiz5q
- Composite Index Implementation
- Composite Index Implementation Quiz5q
- Index Performance Optimization
- Index Performance Optimization Quiz5q
- Response Status Codes and Metrics
- Response Status Codes and Metrics Quiz5q
- Normalized RU Consumption Monitoring
- Normalized RU Consumption Monitoring Quiz5q
- Server-Side Latency Metrics
- Server-Side Latency Metrics Quiz5q
- Data Replication Monitoring
- Data Replication Monitoring Quiz5q
- Azure Monitor Alerts Configuration
- Azure Monitor Alerts Configuration Quiz5q
- Resource Logs Implementation
- Resource Logs Implementation Quiz5q
- Partition Throughput Monitoring
- Partition Throughput Monitoring Quiz5q
- Encryption Key Management
- Encryption Key Management Quiz5q
- Network-Level Access Control
- Network-Level Access Control Quiz5q
- Data Encryption Configuration
- Data Encryption Configuration Quiz5q
- Azure RBAC for Control Plane
- Azure RBAC for Control Plane Quiz5q
- Microsoft Entra ID for Data Plane
- Microsoft Entra ID for Data Plane Quiz5q
- CORS Settings Configuration
- CORS Settings Configuration Quiz5q
- Customer-Managed Keys
- Customer-Managed Keys Quiz5q
- Always Encrypted Implementation
- Always Encrypted Implementation Quiz5q
- Data Movement Strategy Selection
- Data Movement Strategy Selection Quiz5q
- SDK Bulk Operations for Data Movement
- SDK Bulk Operations for Data Movement Quiz5q
- Azure Data Factory Pipelines
- Azure Data Factory Pipelines Quiz5q
- Kafka Connector Integration
- Kafka Connector Integration Quiz5q
- Azure Stream Analytics Integration
- Azure Stream Analytics Integration Quiz5q
- Cosmos DB Spark Connector
- Cosmos DB Spark Connector Quiz5q
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles the points you earn on every lesson and quiz so you progress twice as fast, unlocks half of every practice exam — plus full case studies — with the Learn & Exam study modes, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× points per lesson & quiz
- ✓ 50% of every exam unlocked
- ✓ Learn & Exam modes
- ✓ Distraction-free lessons