Implement a Tiered Cache and Reduce Costs for Your E-commerce

Improve your e-commerce performance and reduce costs by implementing a tiered caching strategy.

Mariana Bellorín Aguilera - Technical Writer
Implement a Tiered Cache and Reduce Costs for Your E-commerce

E-commerce has been one of the fastest-growing sectors in recent years, but with great presence and demand come significant challenges. Managing vast product catalogs and serving thousands of users daily requires a smooth, highly available service that delivers the best possible user experience. Delays, downtime during peak times, and the inability to analyze data in real time can cause major headaches and often seem to require expensive infrastructure improvements.

However, you can improve your e-commerce performance and reduce costs without breaking the bank by implementing a tiered caching strategy. This approach enhances availability, user experience, and operational efficiency.

How Tiered Caching Works

Caching temporarily stores frequently accessed or recently requested data for faster retrieval. When a user requests data, the application first checks the cache. If the data is found (a cache hit), the response is sent directly to the user. If not (a cache miss), the application fetches the data from the origin, stores it in the cache for future requests, and sends it to the user.

Tiered caching takes this a step further by using multiple cache layers between the edge and the origin servers. If data isn’t found in a lower cache tier, the application checks the higher tiers before going to the origin. This reduces latency and infrastructure costs by minimizing origin trips.

Edge computing maximizes caching benefits by distributing cache nodes closer to users for even faster responses and more efficient resource usage. Here’s how a two-layer edge caching solution works:

Tiered Cache flow
  1. The user sends a request to Azion Edge Platform.
  2. The edge application receives the request and applies rules/policies.
  3. The first cache layer is checked locally.
  4. If the data isn’t found, the regional Tiered Cache is checked as a secondary layer.
  5. If the data isn’t found in any cache, the request is sent to the origin.
  6. The origin responds to Tiered Cache.
  7. Tiered Cache caches content and sends the response to the edge node.
  8. The edge node caches content and sends the response to the user.

Implementing Tiered Caching with Azion

Implementing tiered caching is straightforward using Azion Edge Cache and Tiered Cache. Here’s an example configuration via Azion CLI:

# Create new edge application
$ azion create edge-application --name "ecommerce-caching"
# Add custom domain
$ azion create domain --application-id 1234 --name "domainName"
// For more details on configuring a domain and optional flags, check this documentation: https://www.azion.com/en/documentation/devtools/cli/create/#domains
# Enable Tiered Cache add-on
$ azion update edge-application --application-id 1234 --l2-caching true
## You can also enable Large File Optimization for Tiered Cache using the --slice-l2-caching-enabled flag.
# Create an origin
$ azion create origin --application-id 1234 --name "origin-edge" --origin-type single_origin --addresses "azion.com.br" --host-header "azion.com.br"
# Configure edge cache settings
$ azion create cache-setting --application-id 1234 --name "edge-cache" --browser-cache-settings "override" --browser-cache-settings-maximum-ttl 604800 --cdn-cache-settings "override" --cnd-cache-settings-maximum-ttl 604800
# Configure tiered cache settings
$ azion create cache-setting --application-id 1234 --name "tiered-cache" --browser-cache-settings "override" --browser-cache-settings-maximum-ttl 15778800 --cdn-cache-settings "override" --cnd-cache-settings-maximum-ttl 15778800 --l2-caching-enabled true
// For more details on configuring cache settings and optional flags, check this documentation: https://www.azion.com/en/documentation/devtools/cli/update/#cache-settings
# Create Rules Engine rule for Edge Cache
$ azion create rules-engine --application-id 1234 --phase "request" --file `./edge-cache-rule.json`
In the edge-cache-rule.json file, include:
{
"name": "edge-cache-rule",
"description": "This is a description for your edge cache rule",
"criteria": [
[
{
"conditional": "if",
"variable": "${uri}",
"operator": "matches",
"input_value": "/black-friday/"
}
]
],
"behaviors": [
{
"name": "set_cache_policy",
"target": "edge-cache"
}
]
}
# Create Rules Engine rule for Tiered Cache
$ azion create rules-engine --application-id 1234 --phase "request" --file `./tiered-cache-rule.json`
In the tiered-cache-rule.json file, include:
{
"name": "tiered-cache-rule",
"description": "This is a description for your tiered cache rule",
"criteria": [
[
{
"conditional": "if",
"variable": "${uri}",
"operator": "matches",
"input_value": ".(webp|avi|video_formats)."
}
]
],
"behaviors": [
{
"name": "set_cache_policy",
"target": "tiered-cache"
}
]
}
// For more details on configuring rules and optional flags, check this documentation: https://www.azion.com/en/documentation/devtools/cli/update/#rules-engine

This configuration caches /black-friday content like product catalogs in the Edge Cache layer with a 7-day TTL, and more static /videos content in the Tiered Cache layer with a 6-month TTL. When the Edge Cache expires, the content remains in the Tiered Cache to minimize origin requests.

> Tiered Cache can be regionalized. You can define policies for a layer hosted in the US or Brazil, and attend better to your users. To know more on this topic, go to the documentation or contact the Sales Team.

Benefits for E-commerce

Tiered caching provides several key benefits for e-commerce platforms:

  • Reduced costs: minimizes origin server load and resource needs, saving on infrastructure, bandwidth, and hosting.
  • Improved performance: delivers content faster by caching at different layers, enhancing website speed and user experience.
  • Scalability: handles traffic spikes and increased loads more efficiently without sacrificing performance.
  • Reliability: reduces downtime and performance issues caused by origin server overload.

In real-world results, e-commerce platforms using edge computing and tiered caching have achieved:

Conclusion

Tiered caching is a powerful optimization tactic for e-commerce platforms looking to streamline operations, enhance efficiency, and deliver frictionless user experiences while saving on infrastructure costs. By caching and distributing content at the edge across multiple layers, applications can accelerate content delivery and minimize origin load.

Those milliseconds saved can make all the difference between a great user experience and an underwhelming one in today’s demanding digital landscape. Implementing a robust tiered caching strategy is a smart investment in your e-commerce platform’s performance, scalability, and bottom line.

 

Subscribe to our Newsletter