Redirect with Akamai - Best Practices

Overview

A redirect is a way to send users to a different URL from the one they originally requested.  This is often desirable, for example, when a brand has a primary homepage URL but wishes to send the user to a different site based on their geographic location, device type, or other factor.

 

One of the challenges with redirects is the price paid in performance.  Traditionally, a redirect request travels to your origin to retrieve the new URL, as shown below.

Additionally, the user may encounter more than one redirect, as is the case when the user is redirected from non-www to www, then from http to https, as shown below.  This further contributes to the performance issues associated with redirects.

Fortunately, Akamai has a more performant way to deal with redirects, where the redirect is handled in the Akamai edge network rather than going back to origin, as shown below:

Methods

Akamai provides 2 methods for setting up redirects at the edge.  The first method is using the Edge Redirect Cloudlet.  Cloudlets are tools that allow you to solve specific business or operational problems by placing functionality at the edge of the Akamai network, resulting in fewer requests to origin.  Cloudlets are self-serviceable and can be configured through the user interface or the Cloudlets API.  A cloudlet exists for managing redirects called the Edge Redirector Cloudlet.

Cloudlets are set up by 1) creating a policy for the cloudlet, 2) creating a rule that governs execution of the cloudlet, 3) adding the policy to the property that controls the domain, and 4) activating the property in staging and/or production.

The second method for applying redirects at the Akamai Edge is using a newer technology – EdgeWorkers.  EdgeWorkers is an edge compute technology that executes JavaScript on the thousands of edge servers around the world.  In this method, redirect logic is written in the JavaScript code that gets deployed to the Edge.

EdgeWorkers are set up by 1) creating an EdgeWorker code bundle that contains the redirect logic, 2) adding the EdgeWorker to the property that controls the domain, and 3) activiting the property in staging and/or production.  

But when would you use one method over the other?

Best Practices

We recommend using the Edge Redirector Cloudlet for most situations.  Its easy-to-use interface makes it suitable for both developers and operations teams alike, as well as non-technical users like marketing and business users.  There are, however, a few situations where it would make more sense to use EdgeWorkers for redirects.

  • Large number of 1 to 1 mappings, exceeding the cloudlet limits.

Take the example of migrating a blog post site from one platform to another.  I was involved in such a migration where 130,000+ blog posts were migrated to a new platform with a desire to keep the user experience untouched.  Since the Edge Redirector Cloudlet has a limit of 5,000 rules per policy, it was impossible to handle these redirects with the cloudlet.

  • Complex transformations

There can be complex redirect transformations that are difficult to express in the user interface of the cloudlet.  An example of this is a recent customer that required multiple transformations of the URL, like replacing “product” with “products”, “us” with “en-us” (plus variants for other locales), and adding a directory to the URL depending on the value of a query string parameter.  Transformations like these are usually better to express programmatically via JavaScript with EdgeWorkers.

  • Redirects based on outside data

Take for example the case where the original URL contains a product id and needs to be changed to a product name.  This would be better managed with EdgeWorkers as the data could be stored separately in the external key-value pair EdgeKV database, allowing data to be updated without changes to the EdgeWorkers code or the need to push a new version of the property.

Summary

Executing redirects at the Akamai Edge provides the benefits of better performance to the end user as well as reducing traffic to your origin.  We recommend using the Edge Redirector Cloudlet to define redirects.  However, there are a few use cases where the power of using JavaScript in EdgeWorkers is required.

 

Whatever the method used, managing redirects at the Akamai Edge is a win for applications owners and end users alike.