Skip to main content

 Subscribe

Azure DocumentDB is making it easy to prune old data with the support for Time To Live (TTL). 

Previously, if you wanted to delete documents in DocumentDB older than a particular point in time, you would have to write your own logic to first retrieve the records, and then execute a delete statement per document in the result set. You would have to schedule and run this logic in some custom process like an Azure worker role, or use a custom built activity within Azure Data Factory. This custom logic would consume Request Units for fetching the documents and again for each delete operation, making this a potentially very costly exercise. 

With the addition of “time to live” or TTL, Azure DocumentDB provides the ability to store data and with the ability to have that data automatically purged from the system. By setting the “ttl”  property of a document, customers can control exactly when documents will be automatically purged by the service. This expiry time interval can be set at a collection level or at an individual document level. Once this TTL value is set, either at the collection or document level, DocumentDB will automatically remove documents that were modified at a time older than the TTL value. For example, a TTL value of 1000 would automatically delete a document modified more than 1000 seconds ago.

In addition to simplifying the process of purging old data, TTL also makes capacity planning easy. Purges caused by TTL expiration are not charged RUs out of the user’s provisioned budget. This means that you don’t need to plan your provisioned throughput around nightly delete jobs or the like.

TTL values can be set at the collection and the document levels. The collection level TTL controls whether TTL enforcement is enabled for the data in that collection and if so, what the default TTL is. The document level TTL enables you to either selectively enable TTL on a per-document basis or override the collection level default. Disabling enforcement at the collection level prevents any documents from being purged due to TTL expiration. This is to ensure that in case documents need to be retained (Eg: incorrect TTLs are accidentally written to documents), this can be achieved in a single operation instead of having to update every document in the collection.

DocumentDB TTL documentation describes this feature in detail – you can start using this on your existing and new DocumentDB accounts today.

To learn more about DocumentDB, visit the DocumentDB product page. If you need any help or have questions or feedback, please reach out to us on the developer forums on Stack Overflow or schedule a 1:1 chat with the DocumentDB engineering team.

Stay up-to-date on the latest DocumentDB news and features by following us on Twitter @DocumentDB.

  • Explore

     

    Let us know what you think of Azure and what you would like to see in the future.

     

    Provide feedback

  • Build your cloud computing and Azure skills with free courses by Microsoft Learn.

     

    Explore Azure learning