
Countermeasures against rate limiting and response acceleration with Contentful's Advanced Caching
This page has been translated by machine translation. View original
This blog, Developers IO, uses the headless CMS Contentful. While Contentful can deliver content globally through APIs, optimizing API performance becomes a crucial challenge for large-scale websites and applications due to its nature.
In this article, I will explain Contentful's Advanced Caching feature. By utilizing this feature, you can configure sophisticated caching behavior at the CDN level, improving user experience and optimizing API requests.
What is Advanced Caching?
Advanced Caching is a feature that allows you to configure advanced caching behavior at the CDN level for Contentful's Content Delivery API (CDA) and GraphQL Content API.
Compared to standard caching features, it enables more flexible caching strategies, making it particularly effective for high-traffic sites or projects handling frequently updated content.
While Contentful APIs have request rate limits, enabling this feature allows you to continue providing content to users even when API rate limits are reached, and reduce response times immediately after entry publication.
Key Features of Advanced Caching
Advanced Caching offers two options that can be enabled. Each option can be configured individually or both simultaneously.
Stale-when-rate-limited
This feature sends stale data instead of 429 error responses when high traffic causes some requests to hit rate limits (HTTP status 429 situations).
This feature is particularly effective in cases such as:
- Scenarios where service availability is prioritized over data freshness
- Websites with generally high traffic
For services prone to temporary traffic spikes, such as news sites or blogs, providing users with slightly outdated content might offer a better user experience than displaying an error screen.
Stale-while-revalidate
During the first minute after a 'Publish' event occurs in Contentful, the cache returns old data (if available) and updates the data in the background. The additional time required to update content does not affect response time.
This feature is especially useful for:
- Sites handling frequently updated content
- Cases where low latency is more important than data freshness
- Sites that need to process many identical requests
For example, large media sites or social platforms with high content update frequency and simultaneous user access can update content to the latest state in the background without compromising user experience.
How to Enable Advanced Caching
Advanced Caching is a feature available only to Premium plan customers (and previous Enterprise plan).
If you are using Contentful through Classmethod, please contact us. We can enable it individually based on your API usage and use cases. Classmethod engineers will support you if details are unclear.
Advanced Caching Usage Scenarios
Advanced Caching improves Contentful project performance in various scenarios.
- Ensuring stability in high-traffic environments: The "Stale-when-rate-limited" option is effective for large media sites, maintaining user experience by providing older content when rate limits are reached during traffic surges, preventing business opportunity losses.
- Response optimization for frequently updated sites: For frequently updated sites, API response performance may decrease immediately after updates. Using the "Stale-while-revalidate" option allows immediate response to users while CDN cache updates in the background.
Considerations
Balance with Data Freshness
Advanced Caching involves a trade-off between performance and data freshness. Especially when using the "Stale-when-rate-limited" option, you need to understand that users may receive older data and make decisions based on business requirements.
Implementation of Monitoring
After enabling Advanced Caching, we recommend regularly monitoring performance to verify the effect of settings. Tracking metrics such as response time, cache hit rate, and number of API requests can help optimize your configuration.
Summary
Contentful's Advanced Caching is a powerful feature that optimizes caching behavior at the CDN level and improves the performance of large-scale sites. By utilizing the two options "Stale-when-rate-limited" and "Stale-while-revalidate," you can achieve stability during high traffic and reduce response times.
However, it's important to select settings that match your project requirements, considering the balance between data freshness and performance. If you have issues with site display speed, stability, or high traffic handling, please contact Classmethod.