Front-End Web & Mobile
Amplify Hosting Announces Skew Protection Support
A common challenge in web application development and deployment is version skew between client and server resources. Today, we’re excited to announce deployment skew protection for applications deployed to AWS Amplify Hosting. This feature helps verifies end users have a seamless experience during application deployments.
The Challenge
Modern web applications are complex systems comprising numerous static assets and server-side components that must all work together. In a world where its common to have multiple deployments occur hourly, version compatibility becomes a critical concern. When new deployments occur, users with cached versions of your application may attempt to fetch resources from the updated deployment, potentially resulting in 404 errors and broken functionality.
This challenge is compounded by client-server version skew, which manifests in two common scenarios. First, users often keep browser tabs open for extended periods, continuing to run older versions of your application while attempting to interact with updated backend services. Second, in mobile applications, users with disabled auto-updates may continue using outdated versions indefinitely, requiring backend services to maintain compatibility with multiple client versions simultaneously.
These version management challenges can significantly impact user experience and application reliability if not properly addressed. Consider the scenario:
- A user loads your application (version A)
- You deploy a new version (version B)
- The user’s cached JavaScript tries to load assets that only existed in version A
- Result: broken functionality and poor user experience
How skew protection works
Amplify Hosting now intelligently coordinates request resolution across multiple client sessions, ensuring precise routing to intended deployment versions.
1. Smart asset routing
When a request comes in, Amplify Hosting now:
- Identifies the deployment version that originated the request
- Routes and resolves the request to the identified version of the asset
- A hard refresh will always serve the latest deployment assets in a user session
2. Consistent version serving
The system confirms that:
- All assets from a single user session come from the same deployment
- New user sessions always get the latest version
- Existing sessions continue working with their original version until refresh
Advantages to skew protection
Here are some of the advantages of having skew protection:
- Zero Configuration: Works out of the box with popular frameworks
- Reliable Deployments: Eliminate 404 errors due to deployment skew
- Performance Optimized: Minimal impact on response times
Best practices
While skew protection handles most scenarios automatically, we recommend:
- Using atomic deployments
- Testing your deployment process in a staging environment
Enabling Skew Protection
Skew protection must be enabled for each Amplify app. This is done at the branch level for every Amplify Hosting app. You can read the full Amplify Hosting documentation here.
1. To enable a branch, click on App Settings, then click Branch Settings. Next, select the branch you want to enable followed by the Actions tab.
FIGURE 1 – Amplify Hosting Branch Settings
2. For skew protection to take effect, you must deploy the application once.
Note: Skew protection will not be available to customers using our legacy SSRv1/WEB_DYNAMIC applications.
Pricing: There is no additional cost for this feature and it is available to all Amplify Hosting regions.
Tutorial
To get started, follow these steps to create a Next.js application and enable skew protection on it.
Prerequisites
Before you begin, make sure you have the following installed:
- Node.js (v18.x or later)
- npm or npx (v10.x or later)
- Git (v2.39.5 or later)
Create a Next.js app
Let’s create a Next.js app to see skew protection in action.
- Create a new Next.js 15 app with Typescript and Tailwind CSS
2. Create a SkewProtectionDemo component that lists fingerprinted assets with deployment IDs. Use the following code to create the component.
Note: Amplify will automatically tag the fingerprinted assets of a NextJS app with a dpl
query parameter set to a UUID. This UUID is also available during the build via the AWS_AMPLIFY_DEPLOYMENT_ID
environment variable for other frameworks.
3. Next, create a DeploymentTester component that demonstrates how API requests maintain deployment consistency by sending the X-Amplify-Dpl
header with each request, allowing Amplify to route to the correct API version. Use the following code to create the component.
4. Now create an API route that uses the X-Amplify-Dpl
header to identify which deployment the request is coming from, simulating how Amplify routes API requests to maintain version consistency during deployments. Use the following code to create the API route:
5. Add the Amplify deployment ID environment variable to make it accessible to client code
6. Push the changes to a GitHub repository
- Create a new GitHub repository
- Add and commit the changes to the Git branch
- Add remote origin and push the changes upstream
Deploy the application to Amplify Hosting
Use the following steps to deploy your newly constructed application to AWS Amplify Hosting:
- Sign in to the AWS Amplify console.
- Choose Create new app and select GitHub as the repository source
- Authorize Amplify to access your GitHub account
- Choose the repository and branch you created
- Review the App settings and then choose Next
- Review the overall settings and choose Save and deploy
Enable skew protection
In the Amplify console, navigate to App settings and then Branch settings. Select the Branch, and from the Actions dropdown menu choose Enable skew protection.
FIGURE 2 – Amplify Hosting Branch Settings
Next, navigate to the deployments page and redeploy your application. When skew protection is enabled for an application, AWS Amplify must update its CDN cache configuration. Therefore, you should expect your first deployment after enabling skew protection to take up to ten minutes.
FIGURE 3 – Amplify Hosting App Deployments
Access the deployed Next.js app
Navigate to the Overview tab in the Amplify console and open the default Amplify generated URL in the browser. You should now observe a list of fingerprinted assets for your app along with the deployment ID.
FIGURE 4 – Amplify Hosting App Settings – Branch level
FIGURE 5 – Demo App Homepage
Testing skew protection
When you deploy your Next.js application to Amplify, each deployment gets assigned a unique deployment ID. This ID is automatically injected into your static assets (JS, CSS) and API routes to ensure version consistency. Let’s see it in action:
- Asset Fingerprinting: Notice how each static asset URL includes a ?dpl= parameter with your current deployment ID. This ensures browsers always fetch the correct version of your assets.
- API Routing: The
Test Route
button demonstrates how Amplify routes API requests. When clicked, it makes a request to the/api/skew-protection
endpoint. Since the request utilizes theX-Amplify-Dpl
header to match your current deployment ID, it ensures routing to the correct API version.
This means that even during deployments, your users won’t experience version mismatches and each user’s session stays consistent with the version they initially loaded, preventing bugs that could occur when client and server versions don’t match.
Try it yourself
- Keep your current browser tab open and click Test Route to see the API version and deployment ID match.
- Deploy a new version with a different CURRENT_API_VERSION in
api/skew-protection/route.ts
- Open your application in a new incognito window
- Compare the behavior:
-
- Your original tab will maintain the old version
- The new incognito window will show the new version
- Each tab’s assets and API calls will consistently match their respective versions
- Try clicking
Test Route
repeatedly in both windows – each will consistently route to its respective version, demonstrating how Amplify maintains session consistency even when multiple versions are live
-
- Compare the behavior:
FIGURE 6 -Side by Side Comparison of Skew Protection Behavior
This demonstrates how Amplify maintains version consistency for each user session, even when multiple versions of your application are running during deployments.
Congratulations, you’ve successfully created and verified skew protection on your Next.js application deployments on Amplify Hosting.
Cleanup
Delete the AWS Amplify app by navigating to App settings, next go to General settings, then choose Delete app.
Next Steps
- Enable Skew Protection for your application.
- Read our documentation to learn more about this feature!
About the Authors
Matt Auerbach, Senior Product Manager, Amplify Hosting
Matt Auerbach is a NYC-based Product Manager on the AWS Amplify Team. He educates developers regarding products and offerings, and acts as the primary point of contact for assistance and feedback. Matt is a mild-mannered programmer who enjoys using technology to solve problems and making people’s lives easier. B night, however…well he does pretty much the same thing. You can find Matt on X @mauerbac. He previously worked at Twitch, Optimizely and Twilio.
Jay Raval, Solutions Architect, Amplify Hosting
Jay Raval is a Solutions Architect on the AWS Amplify team. He’s passionate about solving complex customer problems in the front-end, web and mobile domain and addresses real-world architecture problems for development using front-end technologies and AWS. In his free time, he enjoys traveling and sports. You can find Jay on X @_Jay_Raval_