Contributed by Densify
Written by Frank Wang, Product Marketing Manager, Densify

Leverage “Optimization as Code” to achieve Continuous Optimization that fits into your DevOps CI/CD Framework

Speed, agility, and efficiency — that’s what every organization wants from the cloud. It’s all about going faster, changing direction faster, and doing it with less risk and cost. For CIOs and IT leaders in financial institutions and fintech companies, this is especially important as they are very driven to innovate and come up with more tailored services, as well as unique and better customer experiences for their end users driven by new applications. Increasingly, the IT organizations in the financial services industry are leveraging the public cloud for scalability, elasticity and agility.  As they deploy more apps into the public cloud, organizations are embracing the DevOps culture to move faster, and at the same time they are leveraging Infrastructure as Code (e.g., Terraform) tools to automate cloud resource selections to achieve operational efficiency during the process. However, this level of granular automation in cloud provisioning poses challenges for cloud operation teams to manage and optimize the infrastructure on which those key applications are running.

The Challenge – Hard-Coded Infrastructure as Code
Cloud micro-purchasing and manual specifications drive potential risks and unnecessary spend

As DevOps teams move faster and deploy more apps into the cloud using processes such as Continuous Integration and Continuous Delivery (CI/CD), it usually drives a lot of cloud micro-purchasing and creates cloud sprawl. In fact, one organization can have thousands of cloud micro-purchasing transactions happening in any given month, and it’s very challenging for the team to systematically manage and optimize theses countless, granular cloud resource provisioning processes.

Coupled with this challenge is the manual specifications in Infrastructure as Code templates. Infrastructure as Code (IaC) tools like HashiCorp Terraform and AWS CloudFormation simplify and automate the process of managing and provisioning infrastructure, but two challenges are often inadvertently encountered. First, developers often leverage tribal knowledge to manually size cloud instances, provisioning them larger (increasing costs) or smaller (introducing business outage risk) than required, or even selecting totally wrong instance types. Second, these incorrect requirements become hardcoded through declarative IaC. Even if you change the instance type and size on the fly, the instance will be kicked back to the original misconfiguration after every restart. The hard-coded Infrastructure as Code not only limits the power of automation, but more importantly it creates operational risks and unnecessary cloud spend.

Below is an example of a Terraform template that automates the provision of an Amazon EC2 “m4.large” instance. It is hard-coded but that instance type and size may not be optimal for that given workload.

Densify Code Example

The Solution – “Optimization as Code”
The next frontier of Infrastructure as Code that enables Continuous Optimization, seamlessly fitting into the DevOps CI/CD pipeline

Now that we understand that hard-coding the cloud resource specification is not the best way to go, we need to automate and parameterize that line of code to get the accurate cloud resource specifications to make sure it’s perfectly aligned with what your applications really need. – This is “Optimization as Code”, and here’s how to achieve it to enable Continuous Optimization for your cloud infrastructure.

Step One: Self-Aware Infrastructure – Imagine If Your Cloud Apps Just Knew
It would be so great if your cloud apps became self-aware of their exact resource requirements. To make that happen, you will need some proper analytics to continuously model your apps’ utilization patterns and compare these models against complete knowledge of offerings from cloud providers. Each workload has CPU, memory and I/O parameters fluctuating all day, and these utilization patterns can change over time.  As such, you will need a powerful multi-dimensional permutation analytics engine to model these workload patterns and generate the accurate recommendations for optimal instance types and sizes for each app and workload. This engine will then:

  • Inject these findings into your cloud instances as tags to make the apps “self-aware”
  • Build an Impact Analysis Report for providing transparency, evidence and benefits to app owners and attaching it directly to change tickets for approval
  • Document recommendations in machine-readable map files that can be automatically synced to repos like GitHub for optimization automation (for step two)

With self-aware cloud apps, developers no longer need to rely on tribal knowledge when selecting and sizing cloud instances. This analytics engine automatically provides a perfect, data-validated recommendation—every time.

Step Two: Continuous Optimization – The Next Frontier of Infrastructure as Code
The next step for organizations that are successfully leveraging self-aware infrastructure is to evaluate Continuous Optimization (CO) as an addition to their CI/CD framework—an approach that makes infrastructure automatically self-optimizing.

By replacing fixed resource assignments in your infrastructure as code templates with calls to reference the analytics engine’s recommendations (as shown below), your cloud apps and workloads can be automatically re-provisioned to the best-fit instances. And, as app resource demands change over time or newer instance types are introduced by cloud providers, your infrastructure remains optimized.Densify Code Example

When your organization embraces Continuous Optimization, hardcoded instance selections in your IaC templates are replaced by calls to the analytics engine to leverage recommendations based on your apps’ exact needs. Your cloud infrastructure becomes self-optimizing, 24/7.

Benefits of “Optimization as Code”

  • Improves your environment’s stability and application performance
  • Significantly increases your cloud cost efficiency
  • Automated, Continuous Optimization as your applications’ demands evolve and change
  • Operational excellence in the way your organization leverages and selects instances and deploys applications in the cloud
  • Tightly fits into your CI/CD pipeline, facilitating a new DevOps paradigm of CI/CD/CO (Continuous Optimization)

Everybody Wins – Bridge the Gap Between App Developers, CloudOps, and Finance
With “Optimization as Code”, every key cloud management stakeholder in your organization wins

Developers can embed code snippets into their Infrastructure as Code templates to make them self-aware and self-optimizing, freeing them from the burden of determining granular resource requirements. Cloud operations teams can provide API-based optimization services to app teams, enabling them to run a safe and efficient environment. Finance benefits from the dramatically-improved cloud cost efficiency.


Interested to see “Optimization as Code” in action? Visit

Frank Wang
Product Marketing Manager at Densify

About Densify
Densify provides next-generation cloud optimization technology that makes cloud instances and containers self-optimizing by continuously and precisely matching app demands to the right cloud resources. Delivered as code, Densify integrates with popular Infrastructure as Code (e.g. Terraform) to deliver continuous optimization that fits into the DevOps CI/CD framework. With Densify, you’ll achieve operational excellence with better app performance and lower cloud spend, in an automated fashion.