Database / Azure Cosmos DB interview questions
1. What is Azure Cosmos DB and what problems does it solve?
Azure Cosmos DB is Microsoft's globally distributed, multi-model NoSQL database service built for modern cloud-native applications. It is designed to solve two of the hardest problems in distributed systems: global low-latency reads and writes and horizontal scalability without any schema...
2. What are the different APIs available in Azure Cosmos DB?
Azure Cosmos DB is a multi-model database, meaning a single back-end engine exposes different wire-protocol-compatible APIs so you can interact with data using the client libraries and query syntax you already know. As of 2024, six APIs are available: Azure...
3. What is a partition key in Azure Cosmos DB and why is choosing it correctly so important?
A partition key is a property you designate on every item in a Cosmos DB container. Its value is hashed to determine which logical partition the item belongs to....
4. What are Request Units (RU/s) in Azure Cosmos DB?
Request Units (RU/s) are the currency of throughput in Azure Cosmos DB. Rather than expressing capacity in CPU cores, memory, or IOPS — which are hard to reason about at the application level — Cosmos DB normalizes all database operations...
5. What are the five consistency levels in Azure Cosmos DB?
Consistency levels in Cosmos DB define the tradeoff between data freshness and system availability/latency when data is replicated across multiple regions or replicas. Azure Cosmos DB offers five levels, from strongest to weakest: Cosmos DB Consistency Levels Level Guarantee Latency...
6. How does global distribution work in Azure Cosmos DB?
Cosmos DB is built from the ground up for global distribution. Every account has a single write region by default (or multiple write regions with multi-master enabled), and you can add any number of read regions at any time....
7. What is the Cosmos DB Change Feed and what are its main use cases?
The Change Feed is a persistent, ordered log of every insert and update that occurs in a Cosmos DB container. It records changes in the order they occur within each logical partition, and this log is available for consumption indefinitely...
8. What is provisioned throughput vs autoscale vs serverless in Cosmos DB?
Cosmos DB offers three throughput provisioning models, and choosing the right one significantly affects cost and performance: Provisioned Throughput (Manual) — You pre-set a fixed RU/s number (minimum 400) that is guaranteed and always available. The cost is flat per...
9. How does indexing work in Azure Cosmos DB?
By default, Cosmos DB automatically indexes every property in every JSON item you insert — no schema definition, no CREATE INDEX statement required. This is called the automatic indexing policy ....
10. What is Time to Live (TTL) in Cosmos DB and how do you configure it?
Time to Live (TTL) is a built-in expiry mechanism that automatically deletes items after a specified number of seconds from their last modification timestamp. This is useful for session data, temporary tokens, audit logs with retention windows, or any data...
11. What is a stored procedure in Cosmos DB and what are its limitations?
Stored procedures in Cosmos DB are JavaScript functions registered on a container and executed server-side on the Cosmos DB engine itself. They run atomically within a single partition — meaning all operations inside the stored procedure either all commit or...
12. What is the difference between a point read and a query in Cosmos DB?
A point read is the most efficient read operation in Cosmos DB. It fetches a single item by specifying both the item's id and its partition key value exactly....
13. What is the Cosmos DB NoSQL query language and how does it differ from standard SQL?
The Cosmos DB NoSQL API supports a SQL-like query language (sometimes called Cosmos DB SQL or the NoSQL query language) that is syntactically close to ANSI SQL but adapted for JSON documents. You use familiar keywords — SELECT, FROM, WHERE,...
14. What is the Cosmos DB transactional batch API?
The transactional batch API is the way to execute multiple operations (up to 100) atomically on items that share the same partition key. Unlike stored procedures (which also provide ACID atomicity but require JavaScript and have size limits), the transactional...
15. What is Cosmos DB Integrated Cache and how does it reduce RU consumption?
The Cosmos DB Integrated Cache is a server-side in-memory cache built into the dedicated gateway tier. When enabled, it caches the results of point reads and queries at the gateway layer so that repeated identical requests can be served from...
16. How does optimistic concurrency work in Azure Cosmos DB?
Cosmos DB uses ETags for optimistic concurrency control. Every item in Cosmos DB has a system-generated _etag property that changes on every write....
17. What is hierarchical partition keys in Cosmos DB and when do you use it?
Hierarchical partition keys (also called sub-partitioning) allow you to define up to three levels of partition key paths on a container, forming a composite key like /tenantId/userId/sessionId . This feature, introduced in GA in 2023, solves the hot partition problem...
18. What is the Cosmos DB Bulk Executor and how do you use bulk operations in the SDK?
Bulk operations in Azure Cosmos DB allow you to send multiple create, upsert, replace, delete, or read operations in a single SDK call that the library optimizes internally — batching by partition, retrying 429 throttles automatically, and maximizing throughput by...
19. What are Cosmos DB triggers and user-defined functions (UDFs)?
Cosmos DB supports two additional server-side JavaScript constructs beyond stored procedures: triggers and user-defined functions (UDFs) . Both run on the Cosmos DB compute engine but serve different purposes....
20. How does Cosmos DB handle conflicts in multi-region write (multi-master) setups?
When multi-region writes are enabled in Cosmos DB, any region can accept writes simultaneously. If two clients in different regions write to the same item at the same time, a write conflict occurs....
21. What is the Cosmos DB Emulator and how is it used in development?
The Azure Cosmos DB Emulator is a locally running software that faithfully emulates the Cosmos DB NoSQL API on your development machine. It lets you develop and test Cosmos DB applications without an Azure subscription, without incurring costs, and with...
22. What is Cosmos DB for MongoDB API and what version compatibility does it provide?
The Cosmos DB for MongoDB API is a compatibility layer that implements the MongoDB wire protocol, allowing applications written for MongoDB to connect to Cosmos DB by changing only the connection string. The application code — queries, aggregation pipelines, driver...
23. What is the Cosmos DB analytical store and Azure Synapse Link?
The Cosmos DB analytical store is a fully isolated, column-oriented copy of your operational data maintained automatically by Cosmos DB, designed for analytical queries. When you enable it on a container, Cosmos DB automatically synchronizes every insert, update, and delete...
24. What are Cosmos DB materialized views and how do they differ from containers?
Cosmos DB materialized views (in preview as of 2024) are automatically maintained read-only containers that are derived from a source container via a defined query or projection. When data changes in the source container, Cosmos DB updates the materialized view...
25. How does Cosmos DB pricing work and what are the key cost drivers?
Cosmos DB billing has three main components: provisioned throughput , storage , and additional features . Understanding each is essential for cost-effective application design....
26. What is the Cosmos DB Gremlin API and what is it optimized for?
The Cosmos DB Gremlin API implements Apache TinkerPop's Gremlin graph traversal language, enabling you to model and query data as a property graph — a network of vertices (nodes) and edges (relationships), each of which can carry arbitrary key-value properties....
27. How does Cosmos DB backup and restore work?
Cosmos DB offers two backup modes, selected at account creation and switchable in some scenarios: Periodic backup (the legacy default) and Continuous backup (the recommended modern option). Periodic Backup — Takes full snapshots at a configured interval (default every 4...
28. What is the Cosmos DB Patch API and how does it differ from Replace?
The Patch API (partial document update) was introduced in Cosmos DB in 2022 to address a common inefficiency in document updates. Before Patch, the only way to modify a field in a Cosmos DB item was to read the full...
29. What is the Cosmos DB Cassandra API and how does CQL map to Cosmos DB concepts?
The Cosmos DB Cassandra API exposes Cosmos DB as a Cassandra-compatible data store using the Cassandra Query Language (CQL) wire protocol. Applications built on Apache Cassandra — using drivers like DataStax Java Driver, Python driver, or the gocql Go driver...
30. How do you model one-to-many relationships in Cosmos DB?
Cosmos DB is a document database with no foreign key enforcement and no JOIN between containers, so one-to-many relationship modeling requires deliberate design decisions based on your access patterns. There are three main strategies, each with different tradeoffs: 1....
31. What is the Cosmos DB free tier and what does it include?
The Cosmos DB free tier is a permanent (not time-limited) offering where every Azure account can have one Cosmos DB account with a perpetual free allocation, making it suitable for prototyping, side projects, and learning without ongoing costs. The free...
32. What is the Cosmos DB SDK and what are the key client configuration options?
The Azure Cosmos DB SDK is the official client library for interacting with Cosmos DB programmatically. Microsoft provides first-party SDKs for .NET, Java, Python, JavaScript/Node.js, and Go....
33. What is the Cosmos DB Table API and when would you migrate from Azure Table Storage to it?
The Cosmos DB Table API is a compatibility layer that exposes Cosmos DB as an Azure Table Storage-compatible endpoint. Applications using the Azure Table Storage SDK can point their connection string at a Cosmos DB Table API account and gain...
34. How does Cosmos DB handle security and access control?
Cosmos DB provides multiple layers of security: network isolation, authentication, and fine-grained authorization. Network-level security : By default, Cosmos DB accounts accept connections from all networks....