DEV Community

Mustafa ERBAY
Mustafa ERBAY

Posted on • Originally published at mustafaerbay.com.tr

CI/CD Deployment Strategies: Speed or Security?

Introduction: The Fine Line Between Speed and Security

CI/CD pipelines have become the backbone of our software development processes. On one hand, we want to deliver products to market quickly, while on the other, we must maintain the highest level of security for our systems. These two goals, while often seeming contradictory, can actually be harmonized. However, achieving this harmony requires strategic decisions and the selection of the right deployment methods.

In this post, I will discuss this delicate balance between speed and security in the CI/CD world, drawing from my own experiences. I will explain the trade-offs brought by different deployment strategies with concrete examples and numbers, offering a perspective on what might be more logical in which situation. This is not just a technology post, but also a career commentary blended with a lifestyle, a "it is what it is" philosophy.

Blue-Green Deployment: The Key to Fast Rollbacks

Blue-Green deployment is based on the principle of maintaining two identical environments (Green and Blue) in the production environment. While one environment is active and handling user traffic, the new version is deployed to the other. After successful testing, traffic is instantly switched to the new version. The biggest advantage of this strategy is its ability to roll back to the old version in seconds if any issues arise.

In a production ERP, especially when financial modules are involved, the cost of any downtime is very high. On one occasion, we used the Blue-Green strategy to deploy a new feature. We moved the new version to the "Blue" environment and conducted extensive tests. Everything seemed fine. It took us exactly 15 seconds to switch traffic from "Green" to "Blue." However, an instantaneous data inconsistency was detected. The issue stemmed from the new version conflicting with a specific background task. By switching traffic back to the old "Green" environment within 15 seconds, the total downtime remained at 20 seconds. This prevented a rollback and debugging process that could have normally taken hours. Strategies like these demonstrate how important the "it is what it is" approach is, especially in critical systems.

ℹ️ Trade-off: Cost and Complexity

The most apparent disadvantage of Blue-Green deployment is that it requires two production environments. This increases infrastructure costs and makes deployment processes more complex. However, the ability to minimize downtime and perform quick rollbacks often justifies these costs. This strategy can be a lifesaver, especially for systems with high transaction volumes and zero tolerance for downtime.

Canary Deployment: The Security of Gradual Rollout

Canary deployment is based on the principle of releasing the new version to a small group of users first. If this small group provides positive feedback and no errors are observed in the system, the version is gradually rolled out to a wider audience. This allows potential issues to be detected before they affect the entire user base.

In a personal project, an anonymous data platform for Turkey, our user base was initially small. However, as the system grew and we started processing more data, I wanted to minimize the risk of every deployment. On one occasion, I needed to make a significant update to the data processing engine. Using Canary deployment, I released the new version to only 5% of users. For the first 24 hours, I closely monitored system metrics and error logs. I detected a subtle anomaly indicating that the Redis OOM (Out Of Memory) eviction policy was behaving unexpectedly. I was able to identify and fix this issue before it spread to 95% of the user base. This early detection prevented potential data loss or system crashes.

💡 Real-time Monitoring

The success of Canary deployment relies heavily on real-time monitoring and the ability to intervene quickly. Tools like Prometheus and Grafana for system metrics, the ELK stack for logs, and Jaeger for traces help us detect anomalies early. This is the operational aspect of the "it is what it is" philosophy: being constantly vigilant and sensing potential problems early.

Canary deployment is an excellent method for safely testing new features in a production environment, especially in large and complex systems. This strategy instills more confidence in development and operations teams by distributing potential risks.

Rolling Deployment: A Method Ensuring Continuity

Rolling deployment is based on the principle of updating servers in batches. While one batch of servers is being updated, others continue to handle traffic. This prevents the system from going completely offline during deployment. After each batch is updated, the process moves to the next batch. This method has a relatively simple structure and usually does not require additional infrastructure costs.

On my VPS hosting my financial calculators, I used rolling deployment when I needed to update the Nginx reverse proxy. I had multiple Nginx instances running on my VPS. First, I updated an instance that was directing 10% of the traffic. After the update, I checked Nginx's logs and CPU usage. Everything was normal. Then, I updated the next instance directing 20% of the traffic. I continued this process until all instances were updated. This process took about 45 minutes, and during this time, the system's overall availability remained above 99.9%. This is a practical way for individual developers or small teams to provide uninterrupted service while acting with an "it is what it is" mentality.

⚠️ Risk: Potential for Inconsistency

The most significant risk of rolling deployment is that different versions of the system are running simultaneously during deployment. This can lead to problems, especially in applications that require session management or data consistency. For example, a user might be directed to the old version on their first request and the new version on their next. In such scenarios, solutions like application-level session affinity or sticky sessions might be necessary.

This method can be preferred in many scenarios due to its simplicity and cost-effectiveness. However, for high-traffic situations where instant consistency is critical, other strategies might be more suitable.

Feature Flags: The Power of Controlled Rollout

Feature flags (or feature toggles) are a technique that allows us to enable or disable a specific piece of code at runtime. This way, we can deploy features that are not yet complete or seem risky to production but keep them hidden from users. When the feature is ready or the risks are understood, the feature is activated by flipping the flag.

In an ERP system for a manufacturing firm, we were developing a new supply chain integration module. This module interacted with multiple external systems and had a high probability of errors. Instead of deploying the module completely, we hid it behind a feature flag. Thus, the code was deployed to production but could only be activated by specific test users or internal teams. For a week, we monitored the system's performance and its interactions with external systems in this controlled environment. We detected an unexpected API rate limiting issue. We were able to resolve this issue with only the limited group of users who had the feature flag active, without affecting the entire production system. This is a great example of how the "it is what it is" approach can be integrated into the software development process.

🔥 Technical Debt Risk

Overuse of feature flags can lead to a difficult-to-manage pile of technical debt over time. Cleaning up unused or obsolete feature flags makes the code harder to read and maintain. Therefore, every feature flag should have a lifecycle and be regularly reviewed and cleaned up. This is like a precaution against the question, "We're doing it, but what about tomorrow?"

Feature flags are a powerful tool that enhances deployment speed while ensuring security. They allow development teams to experiment more freely and manage risks in a controlled manner.

Speed or Security? A Pragmatic Approach

In conclusion, making a choice among CI/CD deployment strategies does not mean giving a clear answer to the question "speed or security?". It is a complex balancing act that varies depending on the situation, the risks involved, and the business objectives. Blue-Green is ideal for critical systems requiring fast rollbacks. Canary allows for gradual rollout by distributing risks. Rolling deployment offers simplicity and continuity. Feature flags allow us to control the code itself.

For me, the "it is what it is" philosophy comes into play precisely at this point. Instead of always jumping to the most complex or expensive solution, it is important to choose the most pragmatic path by considering the current situation, risk appetite, and the desired outcome. On one occasion, the deployment process for an update to the Android version of my mobile app took two weeks due to metadata rejection. This taught me that the concept of "speed" is not solely within our control and that we must also be prepared for external factors.

The best strategy often involves using a combination of these methods. For example, you might deploy a feature behind a feature flag, then gradually roll it out with Canary, and finally perform a full switch with Blue-Green. The important thing is to know what you are doing at each step, understand the potential trade-offs, and learn by continuously monitoring metrics.

Top comments (0)