Deployment approaches
A best practice for deployments in a microservice architecture is to ensure that a change does not break the service contract of the consumer. If the API owner makes a change that breaks the service contract and the consumer is not prepared for it, failures can occur.
Being aware of which consumers are using your APIs is the first step to ensure that deployments are safe. Collecting metadata on consumers and their usage allows you to make data driven decisions about the impact of changes. API Keys are an effective way to capture metadata about the API consumer/clients and often used as a form of contact if a breaking change is made to an API.
Some customers who want to take a risk-averse approach to breaking changes may choose to clone the API and route customers to a different subdomain (for example, v2.my-service.com) to ensure that existing consumers aren’t impacted. While this approach enables new deployments with a new service contract, the tradeoff is that the overhead of maintaining dual APIs (and subsequent backend infrastructure) requires additional overhead.
The table shows the different approaches to deployment:
Deployment | Consumer Impact |
Rollback |
Event Model Factors |
Deployment Speed |
---|---|---|---|---|
All-at-once | All at once |
Redeploy older version |
Any event model at low concurrency rate |
Immediate |
Blue/Green | All at once with some level of production environment testing beforehand |
Revert traffic to previous environment |
Better for async and sync event models at medium concurrency workloads |
Minutes to hours of validation, and then immediate to customers |
Canary(or Linear) | 1–10% typical initial traffic shift, then phased increases, or all at once |
Revert 100% of traffic to previous deployment |
Better for high concurrency workloads |
Minutes to hours |
All-at-once deployments
All-at-once deployments involve making changes on top of the existing configuration. An advantage to this style of deployment is that backend changes to data stores, such as a relational database, require a much smaller level of effort to reconcile transactions during the change cycle. While this type of deployment style is low-effort and can be made with little impact in low-concurrency models, it adds risk when it comes to rollback and usually causes downtime. Use this deployment model for non-critical environments, such as development, where impact to customers is not a risk.
Blue/green deployments
Another traffic shifting pattern is enabling blue/green
deployments. This near zero-downtime release enables traffic to
shift to the new live environment (green) while still keeping
the old production environment (blue) warm in case a rollback is
necessary. Since API Gateway
Serverless architectures that follow the best practice of statelessness and idempotency are amenable to this deployment style because there is no affinity to the underlying infrastructure. You should bias these deployments toward smaller incremental changes so that you can easily roll back to a working environment if necessary.
You need the right indicators in place to know if a rollback is
required. As a best practice, we recommend customers using
CloudWatch
Canary deployments
Canary deployments are a way for you to gradually release new software in a coordinated and safe way that enable rapid deployment cycles. Canary deployments involve deploying a percentage of requests to new code, and monitoring for errors, degradations, or regressions.
You can use Lambda