Software development teams have traditionally used persistent staging environments for testing and safe experimentation. However, the downside of shared persistent environments has become clearer in recent years, including configuration inconsistencies and delays when used across multiple teams.
In contrast, ephemeral environments allow development teams to deploy numerous isolated, short-lived preview environments quickly. They replicate the entire production stack—from the front-end and back-end to the database, integrate with continuous delivery pipelines—and are automatically removed once they are no longer needed.
In this article, we explore the challenges and benefits of ephemeral environments, provide instructions for creating an ephemeral environment of your own, and present an environment-as-a-service solution that can save time and effort.
Ideally, any code changes made to a codebase should be tested before they go live in a user-facing production environment. Traditionally, this has been achieved by creating multiple environments before production—such as a testing or staging environment—with the expectation that the staging environment is identical to production and well-tested before going live. However, in practice, this can take a lot of work to achieve and often be impractical for various reasons.
Since the staging environment should resemble the production environment as closely as possible, all infrastructure components need to be replicated for both environments as well. This translates into extra maintenance and overhead associated with frontends, backends, databases, and functioning interfaces among the components. Any infrastructure or architecture changes made to production must also be made here and can easily be forgotten or not perfectly replicated one-to-one.
With only one staging environment, every time changes are merged into a main branch; developers must wait for their “turn” before their changes are deployed to the staging environment. This can hinder the productivity and velocity of releases and sometimes even result in developers attempting to find ways around the workflow to release a new change more quickly, for example, in the case of a bug fix. These delays and possible workarounds can cause unwanted problems and result in untested changes in the long run.
In traditional workflows with staging environments, deploying changes from staging to production usually requires a separate manual step. If this step is not performed consistently after merging each branch, the staging environment can end up several commits ahead of the production environment. As a result, deploying from staging to production becomes a more extensive, riskier change because it includes multiple commits at once, increasing the chances of something breaking in production.
Traditional staging environments live just as long as a production environment lives, i.e., indefinitely, until a new set of changes is deployed. Longer periods without any changes mean the staging environment is still incurring costs while potentially providing no benefit to the company.
{{banner-large-dark="/banners"}}
Ephemeral environments can provide multiple advantages to organizations compared to traditional persistent environments.
Ephemeral environments and the infrastructure that they are built upon are designed to be created and destroyed quickly. Required infrastructural elements are created on demand for each pull request and spun up based on the current production infrastructure as defined in the code without any intervention required from any DevOps or infrastructure engineers. This ensures that the environment resembles the production environment as closely as possible. Any ephemeral environment that might become corrupt, broken, or otherwise unreachable can quickly be replaced with a new one.
Since every pull request will be allocated its own freshly created environment, multiple environments can be running in parallel, completely independently. This means no queue and less time that developers need to wait for their turn to deploy to a preview or test environment. Furthermore, each environment will only have changes from the single pull request running in it, meaning that manual testing can be done without any potential side effects from other new changes, and no big bang changes will be deployed to production.
Ephemeral environments are meant to be short-lived by design, and they can be configured to exist only as long as they are needed. For example, one can be created alongside the opening of a new pull request and destroyed once the pull request has been approved and merged. This means there’s no more paying for environments that are not explicitly in use, which results in lots of cost savings in the long term.
{{banner-small-4="/banners"}}
While setting up ephemeral environments can involve an initial learning curve, their advantages typically make the time and effort invested worthwhile. In general, ephemeral environments can be implemented using the following steps:
These steps are generally required to set up ephemeral environments, although they may not fully represent the effort required since the workflow is simplified.
{{banner-small-1="/banners"}}
Those who may be inexperienced or would prefer not to put in the effort to set up the infrastructure required for ephemeral environments but are still interested in the benefits can take advantage of an environment-as-a-service solution.
Some vendors provide solutions that can save a large amount of time and effort for a small fee. Some of the most complex aspects of setting up ephemeral environments are handled by these vendors, allowing development teams to focus on business-related tasks rather than dealing with infrastructure or configuration concerns.
Some of the key features that can be expected from an EaaS solution are the following:
Coherence offers a platform-as-a-service solution that greatly simplifies the steps required to create ephemeral or preview environments by using preset integrations and automation.
{{banner-small-2="/banners"}}
Coherence not only offers all of the features mentioned above, it also integrates with both AWS and GCP, so you can create ephemeral environments in your existing cloud accounts. The architecture is set up slightly differently depending on the cloud provider. In general, a VPC, load balancer, and caching service can be shared across applications, while components such as storage buckets or databases can be defined and deployed on a per-environment basis.
While previews can be created and destroyed automatically based on configurations, Coherence also provides users with an overview of all existing preview environments and the functionality to manage these previews in an easy-to-use UI. Environments are also defined in lifecycles, moving from “active” to “paused” and finally to “archived” based on the configuration and current usage of the environments. Those interested in adapting Coherence for their systems can find more information at Coherence and can even ask for support with migration.
{{banner-small-1="/banners"}}
As companies continue to look for ways to stand out from the crowd and development teams look for opportunities to ensure that new code changes do not create any downtime, ephemeral environments represent a significant improvement in development processes and a massive opportunity for teams to take advantage of its many benefits. They enable a transition from the pain of waiting in line in the staging environment and managing discrepancies with the production environment to having a fresh preview environment whenever one is needed and never needing to spend any effort managing the lifecycle. Teams can look forward to these benefits when adapting ephemeral environments into their processes.