Blue-green deployments are a strategy that allows developers to transition users from one version of an application to another with minimal downtime and risk. It involves maintaining two identical environments: one that serves live traffic (Blue) and another staged version for testing (Green).
Rolling Releases are a built-in feature of Vercel that let you configure blue-green deployments with no code changes. You can create automated or manual, multi-stage rollout strategies that integrate with Observability.
If you'd like to implement blue-green deployments yourself with lower-level primitives, this guide will walk you through setting up blue-green deployments on Vercel, leveraging its features like Skew Protection, Edge Config, and Middleware in Next.js for a seamless transition.
Explore a live demo of blue-green deployments: https://blue-green.vercel.app
- Deploy Your Project: You can begin with deploying our template that is configured for blue-green deployments.
- Activate Skew Protection: Enable Skew Protection for your project in Vercel. This ensures that users stick to the assigned blue or green deployments throughout their session, providing a consistent user experience across Vercel’s global CDN and serverless function infrastructure.
- Activate Deployment Protection Bypass: This setting ensures that your deployments can bypass any protections, facilitating smooth transitions between blue and green environments.
- Disable Auto-assign Custom Production Domains: This prevents Vercel from automatically assigning your custom domains to new production deployments, giving you a production-like deployment to use as a staging environment instead.
- Create an Edge Config: Edge Config allows you to define how traffic is split between your blue and green deployments. Use the following settings to get started:
Next.js Middleware is utilized to direct traffic between your blue and green deployments based on predefined rules. This setup requires fetching the blue-green configuration from Edge Config and routing requests accordingly.
Below is an example of how to implement the middleware in your Next.js application:
The middleware ensures that only production GET requests for HTML documents are considered for blue-green deployment routing, excluding API routes, static files, image optimization files, and the favicon.
Using GitHub Actions as an example, we can create a workflow to automate the process of updating your Edge Config settings when a new staged deployment is successful. We initiate the traffic splitting based of the configuration you specify. In this case we are starting the traffic at 50%.
Set up another workflow to manage the promotion of the green deployment to production upon approval of the deployment. This specific workflow allows for manual triggers, providing flexibility in deployment management, but this can also be automated based on your organizational needs.
This setup involves fetching the current Edge Config, parsing the deployment to promote, and updating the Edge Config to reflect the new state.
Blue-green deployments on Vercel offer a robust strategy for managing application updates with minimal risk and downtime. By leveraging Vercel's features along with GitHub Actions, developers can automate and control the deployment process, ensuring smooth and reliable application updates. Follow the steps outlined in this guide to implement your blue-green deployments, and visit the provided demo for a practical example.