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.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
