CDN TTL and Update

We recently encountered a scenario which involves deleting a field value, and the entry containing this field is published. When retrieving the modified entry using the CDN link, we are seeing at times the previous field value is returned, and at times the entry with the field removed (since there is no field value) is returned.

Questions:

  1. What is the TTL on CDN entries?
  2. Can requests for https://cdn.contentful.com hit different servers which contain different cached state?
  3. What is the expected sync time after a publish is made can we expect the CDN to be updated?

Any insight is much appreciated.

1 Like

Hey Willie,

Contentful is operating multiple layers of caching and hence there is multiple perspectives to this. I try to shed some light on your questions:

  1. the CDN layer is purged when you publish an entry in a space. Purging is instant and so fresh content is propagating usually within a few seconds. There is throttling logic which slows down cache purging if you programatically publish a space.

  2. Each CDN node operates its own cache. E.g. server A is hot and serves a cached version while server B is not and needs to hit our origin to retrieve data. This should not cause different data to return, but I assume possible in race conditions.

  3. instant for initial publish actions, throttled if a space is published frequently (e.g. every 2 seconds)

If you depend on fresh data in a webhook target which triggers for publish, its usually best to implement a small polling script to ensure the data you get from the CDN is fresh. From my own experience this rarely needs to poll as usually data is fresh instantly.

Here is a snippet which shows how this could be done: https://gist.github.com/floelhoeffel/2566d1c476e5cb96d62a8c3863851a99

Cheers,
Frederik

1 Like

Thank you, Frederik, appreciate the insight, this helps greatly.