20. Indexes, Writes, Storage, and Working Set

Every insert may require new entries in relevant indexes. Updates to indexed fields can require index maintenance, and deletes remove relevant index entries. More indexes therefore increase write work and consume additional disk and memory.

The working set is the data and index content frequently needed by active workloads. If frequently used index pages fit in memory, access can be more efficient. If the working set exceeds available memory, cache misses and storage reads may affect latency.

Index size is influenced by indexed values, key types, array expansion, compound keys, and the number of documents. Use database statistics and operational monitoring to understand index sizes and cache behavior.

The right index portfolio balances read latency, write throughput, storage, and operational complexity.

Code Example
db.orders.stats();

db.orders.totalIndexSize();
Key Takeaways
  • Indexes add write-maintenance work.
  • Indexes consume storage and memory.
  • Array fields can produce many multikey entries.
  • Balance read performance with write and operational costs.
Knowledge Check

Why can too many indexes harm a write-heavy application?