Database / CouchDB Interview Questions
How does CouchDB handle large document sets — what are the performance trade-offs of large vs many small documents?
CouchDB does not have a hard document size limit (the default max_document_size is 4GB), but the performance trade-offs between storing data as a small number of large documents versus many small documents are significant.
Large documents (e.g., one document per entity with thousands of nested items):
- Every update requires a full rewrite of the document, even if only one nested field changed. This amplifies write I/O and revision chain growth.
- Replication transfers the entire document body on every change. For a 5MB document that changes frequently, this saturates replication bandwidth quickly.
- MVCC conflicts are more likely and more costly to merge because the entire body must be transferred and compared.
- Reading the document always loads the full JSON, even if only one field is needed (CouchDB has no projection at the storage layer — Mango
fieldsprojection happens after the document is loaded).
Many small documents (one document per event/record):
- Updates are small and cheap; conflicts affect only the specific document touched.
- Replication is incremental — only changed documents are transferred.
- Mango and view queries can filter and paginate efficiently.
- The trade-off: each document has overhead (~200 bytes for metadata). A database with 100 million tiny 50-byte documents will have metadata overhead larger than the data itself.
The recommended pattern: keep documents to a natural entity size (an order with its line items, not an order with the entire customer history). Avoid designs that require updating a single document at a rate faster than ~100 writes/second — high-frequency counters belong in Redis, not in a CouchDB document.
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...
