Database / Azure Cosmos DB interview questions
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 (it is not ephemeral like a message queue). Deletes are not captured by default, but you can enable a soft-delete pattern by marking items with a deleted flag and relying on TTL to purge them.
The Change Feed exposes two primary consumption models:
- Change Feed Processor (CFP) — A library (available in all Cosmos DB SDKs) that manages distributed consumption across multiple worker instances. It uses a separate lease container to track each worker's read position per logical partition. This is the recommended approach for most applications — it handles partition splits, lease management, and worker scaling automatically.
- Azure Functions Cosmos DB Trigger — A serverless binding that invokes a function for each batch of changes. Internally it uses the Change Feed Processor library. Zero infrastructure to manage.
Common use cases:
- Real-time event streaming — Forward Cosmos DB mutations to Azure Event Hubs or Kafka for downstream analytics pipelines.
- Materialized views — Maintain a denormalized view in another container that is optimized for a different query pattern (e.g., store orders by customerId in the source, maintain a separate container keyed by productId for product-based reporting).
- Cache invalidation — When an item in Cosmos DB changes, push the updated version to Redis or a CDN edge cache.
- Auditing — Write every change to an immutable audit log container or Azure Blob storage.
- Event-driven microservices — Use Cosmos DB as an event store and the Change Feed as the outbox, replacing traditional message broker coupling.
More Related questions...