Azure Cosmos DB
Azure Cosmos DB offers five consistency levels: Strong : Guarantees linearizability; use for financial transactions requiring absolute consistency Bound...
Can you explain the different consistency levels provided by Azure Cosmos DB and when you might use each?
Azure Cosmos DB offers five consistency levels: Strong : Guarantees linearizability; use for financial transactions requiring absolute consistency Bounded Staleness : Reads lag behind writes by a configured time/version window; good when predictable staleness is acceptable Session : Monotonic reads/writes within a single session; ideal for user centric applications Consistent Prefix : Reads never see out of order writes; useful when operation ordering matters Eventual : No ordering guarantee wit
How would you design a partitioning strategy for a large-scale application using Azure Cosmos DB?
An effective partitioning strategy in Azure Cosmos DB requires three key considerations: Choose a high cardinality partition key that distributes data evenly and avoids hotspots (e.g., userId in a multi tenant app) Align with access patterns so most queries target a single partition, minimizing expensive cross partition queries Monitor partition metrics regularly via Azure Monitor and adjust the strategy as data volume and access patterns evolve
Describe a scenario where you would use the Change Feed feature in Azure Cosmos DB.
The Change Feed in Azure Cosmos DB captures a sorted log of insert and update operations within a container. Key use cases include: Real time event processing : Triggering Azure Functions to update materialized views or send notifications on data changes Data synchronization : Keeping downstream systems (caches, search indexes) in sync with the latest data Auditing and logging : Maintaining a chronological record of all document changes for compliance purposes
How can you implement multi-region writes in Azure Cosmos DB, and what are the benefits?
To enable multi region writes , add additional regions in the Azure portal and toggle the multi region writes setting on your Azure Cosmos DB account. Benefits include: Lower write latency : Writes are directed to the nearest region, eliminating cross region round trips Higher availability : If one region fails, other regions continue accepting writes with automatic failover Conflict resolution : Configure automatic conflict resolution policies (last writer wins or custom stored procedures) to h
Can you explain how Request Units (RUs) work in Azure Cosmos DB and how to estimate the RUs needed for a workload?
Request Units (RUs) are the currency of throughput in Azure Cosmos DB , abstracting CPU, memory, and IOPS into a single metric. A point read of a 1 KB item costs 1 RU Writing a 1 KB item costs approximately 5 RUs Query cost depends on item count scanned, filters, and complexity Use the Azure Cosmos DB Capacity Calculator to estimate RUs based on document size, read/write ratios, and query patterns.
How would you handle a scenario where a query is consuming a high number of RUs in Azure Cosmos DB?
To reduce RU consumption on a high cost query in Azure Cosmos DB : Review indexing policies : Ensure the query leverages composite or range indexes on filtered fields Use projections : Retrieve only the fields you need via SELECT c.field1, c.field2 instead of SELECT Refactor the query : Simplify predicates and reduce the number of items scanned Implement pagination : Use continuation tokens to break large result sets into smaller pages
Describe how you would implement a schema versioning strategy in Azure Cosmos DB.
Since Azure Cosmos DB is schema agnostic, you manage schema evolution at the application level: Include a schemaVersion field in every document to track which version of the schema it conforms to Handle multiple versions in application code, reading and transforming documents based on their schemaVersion Migrate incrementally using the Change Feed to detect older documents and update them to the latest schema version over time
How can you secure data in Azure Cosmos DB both at rest and in transit?
Azure Cosmos DB provides multiple layers of data protection: Encryption at rest : All data is automatically encrypted using Microsoft managed keys (or customer managed keys via Azure Key Vault ) Encryption in transit : All communication is secured via TLS 1.2+ Network security : Configure IP firewall rules , VNet service endpoints , or Private Link to restrict access Access control : Use Role Based Access Control (RBAC) and resource tokens for fine grained authorization