Best practices for MongoDB data retention and archiving.

Instruction: Outline best practices for managing data retention and archiving in MongoDB, considering factors like compliance, storage efficiency, and data accessibility.

Context: This question explores the candidate's knowledge of data lifecycle management in MongoDB, including strategies for data retention, archiving, and deletion in compliance with business and regulatory requirements.

Updated

Official answer

Obtain an approved retention policy by data class, purpose and jurisdiction from the responsible legal/privacy and business owners. Define retention start, legal holds, archive access and deletion requirements; do not infer a universal period from a regulation's name.

TTL indexes can delete eligible documents in the background, but expiration is not an exact deletion deadline and TTL is not an archive mechanism. If access must stop immediately at expiry, enforce that rule in the application too. Exclude held data through an appropriate supported design and verify behavior before enabling deletion.

For archiving, copy a bounded eligible set to the intended storage, verify completeness and retrieval, then delete from the source only under the approved workflow. Make retries idempotent and reconcile partial failures. A separate database on the same cluster may still share resource and failure risks.

Include replicas, search indexes, exports, caches and backups in the lifecycle. Define how a restore avoids silently reintroducing data that should remain deleted. Protect archive keys and access and test retrieval/recovery.

Measure retained/expired counts, overdue deletions, hold exceptions, archive reconciliation and retrieval time. Stable DAU does not establish successful retention enforcement, and sharding does not inherently reduce total storage cost.

MongoDB TTL behavior, backup methods

Related Questions