Microservices Deployment Strategies
Releasing a new version of a service is a risky moment. A bug can reach every customer within seconds. Deployment strategies control how new code replaces old code, so teams limit the damage of a mistake and roll back quickly. The right strategy balances speed, cost, and safety.
Layman Explanation
A restaurant introduces a new recipe. The owner can swap the whole menu overnight, serve the dish to a few tables first, or run two kitchens side by side and switch when ready. Each approach carries a different cost and a different level of risk. Deployment strategies offer the same choices for software.
Recreate
Stop the old version completely and start the new one. Downtime occurs between the two steps. Suitable for internal tools and off-hours maintenance windows, and unsuitable for customer-facing services.
Rolling Update
Replace instances a few at a time. Kubernetes uses this method by default.
Start: [v1] [v1] [v1] [v1] Step 1: [v2] [v1] [v1] [v1] Step 2: [v2] [v2] [v1] [v1] Step 3: [v2] [v2] [v2] [v1] End: [v2] [v2] [v2] [v2]
No downtime and low extra cost. Old and new versions run together for a while, so both must work with the same database and API contracts.
Blue-Green Deployment
Run two identical environments. Blue serves customers while green holds the new version. After testing green, switch the router so traffic flows to green.
+--> BLUE (v1) live
Router -------+
+--> GREEN (v2) idle, tested
After switch:
+--> BLUE (v1) idle, kept for rollback
Router -------+
+--> GREEN (v2) live
Rollback means flipping the router back, which takes seconds. The price is double infrastructure during the release.
Canary Release
Send a small share of traffic to the new version and watch the numbers. Miners once carried canaries to detect gas; the canary group warns the team about problems before everyone feels them.
Traffic split over time: Step 1: v1 ################## 95% v2 # 5% Step 2: v1 ############## 75% v2 #### 25% Step 3: v1 ####### 50% v2 ####### 50% Step 4: v1 0% v2 ################## 100%
Automated checks compare error rate and latency at each step. A bad reading triggers an automatic rollback.
Feature Flags
Ship code with new behavior switched off. Turn it on for staff, then for one percent of users, then for everyone. Deployment and release become two separate decisions. A flag can disable a faulty feature in seconds without a new deployment.
A/B Testing
Two versions run at the same time for different user groups. The goal is learning which version performs better, such as higher sign-ups. Canary releases test safety, and A/B tests test business value.
Comparison
| Strategy | Downtime | Extra Cost | Rollback Speed |
|---|---|---|---|
| Recreate | Yes | None | Slow |
| Rolling | No | Low | Medium |
| Blue-green | No | High | Very fast |
| Canary | No | Low to medium | Fast |
Database Changes
Old and new versions often share one database during a release. Use the expand and contract approach:
- Expand: add the new column or table while keeping the old structure.
- Migrate: deploy code that writes both and reads the new one.
- Contract: remove the old structure after every instance runs the new code.
Never rename or delete a column in the same release that stops using it.
Good Practices
- Automate the whole release inside the CI/CD pipeline.
- Define health and metric checks that decide success.
- Practice rollbacks so they feel routine.
- Release small changes often.
Key Takeaways
Pick rolling updates for everyday releases, blue-green for fast rollback, and canary for careful risk control. Pair them with feature flags and compatible database changes.
