All posts
cloud-costcontractsenvironment-management

Cloud Cost Optimization by Design: Put the Cost Rules in the Contract

Audits cut cloud cost for a quarter, then the bill grows back. Cost optimization by design keeps it down: cost rules inside versioned modules, non-production environments that scale down on their own, and spend you can see per environment.

Rohit Raveendran
Rohit Raveendran
Mar 27, 2024 · 8 min read

Cloud costs that keep rising are a problem most growing companies know. Audits and cost tools bring short relief. A few months later, the bill is back where it was, because the next service, the next environment and the next bucket were built the same way as the last ones.

As a business grows, cloud spend can reach, in extreme cases, up to 50% of the cost of revenue, according to a16z. In our experience, a SaaS company starts to question its cloud bill once it passes 7 to 10% of revenue, and that question leads to optimization projects, migrations and sometimes repatriation.

Cost optimization by design is the alternative. You decide the cost rules once, inside the building blocks that every team uses, so each new resource is cost-aware from the day it is created and nobody has to review cost change by change.

Why cost audits do not hold

When cloud costs climb, most organizations reach for the same tools:

ApproachWhat it does
Audit cyclesRegular audits find areas of excess spend and cut them.
War roomA central team reviews cost dashboards and tells teams where they overspend.
Project trackerA tracker follows each cost-reduction task and reports progress to stakeholders.
Anomaly toolsCost tools flag unusual spend, and some can act on it.
Ops owns costThe operations team manages cost on top of its existing work.

Each of these works on spend that already exists. None of them changes how the next resource gets built, so the savings fade and the cycle repeats.

Diagram that compares audit cycles with cost by design. On the left, with audit cycles, spend rises, an audit cuts it, and it rises again, so the line is a saw-tooth. On the right, with cost by design, the cost rules sit in every module and every environment inherits them, so spend grows only with the business and the line stays level.

AI raises the volume, and the bill follows

Coding assistants changed the math. Each engineer now sends more changes every week, and many of them need infrastructure: a new service, an environment for a branch, a cache, a bucket for exports.

A cost review per change cannot keep up with that volume. A monthly audit finds the waste only after it has billed for a month. AI accelerated the problem for delivery as a whole, and the cloud bill is one of its symptoms.

The answer is to make each new resource right by default, so the volume does not matter.

Decide once, inside the module

Leakage is the smallest kind of waste, and the hardest to spot. A bucket that costs $10 a day and stays unnoticed for a year costs $3,650. Multiply that by every team and every environment.

The fix is a rule: every bucket gets a lifecycle rule. A rule in a wiki depends on every engineer reading it. A rule in the module applies to every bucket the module creates. The same goes for the other cost rules a platform team cares about:

  • A lifecycle rule on every bucket, so old objects expire or move to cheaper storage.
  • Required tags for team, product and environment, so every line on the bill has an owner.
  • The sizes a developer may choose, so "just in case" does not mean the largest instance.
  • Retention defaults for logs, snapshots and backups.

This is the idea behind standards in contracts that a machine can check: a developer picks a few settings, and the platform team decides the rest once.

Diagram of a cost rule inside a contract, with an S3 module as the example. The developer chooses only the bucket name and the retention period. The platform team decides the rest inside the module: the lifecycle rule, the cost tags, the allowed storage classes and encryption. Every bucket the module creates gets the lifecycle rule, every resource carries the cost tags, and the result is the same in every environment.

How Facets does it

In Facets, a module is Terraform with a contract: what a developer can set, what it needs from other modules and what it gives back. The platform team writes the cost rules into the module once, and every project that uses it inherits them. The catalog's S3 module already includes encryption, versioning and lifecycle management. Facets also passes each environment's cloud tags to every module, so a module can tag everything it creates. Modules are versioned, so a stricter rule ships as a new version that each project takes when it is ready. Modules and the catalog describes the contract, and design by contract explains the idea.

Tags help in shared clusters too. In a shared Kubernetes cluster, the node tags show only the cluster's total cost. To split that cost per service, carry each service's tags into your metrics as labels, then divide the shared cost by each service's share of the resources.

Non-production by design

Non-production environments (dev, QA, staging, UAT and load test) rarely carry a steady load, yet they often run around the clock. They are also the lowest-risk place to save, because a short interruption costs little.

Three settings cover most of the waste:

  • Off-hours schedules. A time-sensitive environment scales down, or is destroyed, outside its active hours, such as nights and weekends.
  • A fixed lifespan. A short-lived environment, such as one for a feature branch, a pull request or a load test, tears itself down after a set time.
  • Spot capacity. A non-production cluster can run on spot nodes. An interruption costs little there, and the discount is large.

In Facets, these are settings on the environment. Time-sensitive environments describes the schedules and lifespans, and a non-production cluster can use the SPOT node plan. Every environment comes from the same blueprint, so a short-lived copy behaves like the long-lived one, and environments become a commodity that you can create and remove without a project. Environment management shows how teams use this.

Purplle cut non-production infrastructure costs by 70%.

Production: commit to the base, run spot where restarts are safe

Production needs more care, but the same idea applies: decide per service, once, and write the decision down.

Spot capacity sits between two other options. Reservations and savings plans give the largest discount for a long commitment. On-demand capacity gives full flexibility at full price. Spot gives a deep discount with no commitment, but the cloud can take the nodes back, sometimes for hours.

  1. Record which services tolerate restarts. A service that restarts cleanly can run on spot. A service that cannot should not.
  2. Keep the rest on on-demand capacity you can reserve. The base capacity for services that cannot restart is known in advance, so you can commit to it. Check the savings plan recommendation before you size that commitment.
  3. Run restart-tolerant services on spot, with a fallback. When spot capacity runs out, the node group falls back to on-demand nodes and alerts the team, and moves back to spot when it returns.

When this is part of each service's definition, nobody has to decide it again during an incident.

See spend per environment, and find what sits idle

Rules prevent most waste. You still need to see what you spend, and find what slipped through.

  • Spend per environment. Cloud Cost Explorer (Enterprise plan) shows the cost of each environment in a blueprint for AWS and Azure accounts, with daily breakdowns and the trend over the last 7, 30 or 90 days.
  • Idle resources. The Praxis wasted-spend scan reads your AWS, GCP and Azure accounts with read-only access. It finds resources that bill but do little work, such as unattached disks, orphaned snapshots and idle load balancers, and returns a ranked report with an estimated monthly saving for each. It changes nothing.

These are the first two steps of the trust ladder: an agent observes and recommends, and a person decides what to remove. A database with no connections may be a warm standby kept for disaster recovery, and only your team knows. With a record like this across every environment, an audit becomes a report instead of a project.

Who owns cost

Platform teams write the rules. Everyone ships.

The platform team writes the cost rules once, in modules and policies, and reviews the rules instead of every change. Each product team sees its own spend and owns it, with cost as a metric next to performance and availability. The decentralized cost governance model compares this with a central war room. Platform teams write the rules explains the split of work in general.

For more on cost, read the SaaS cloud cost optimization strategies, the quiet $1M leak in your engineering org, standardization in security, cost, compliance and observability and environment management, or watch the Kubernetes rightsizing webinar.

Read why Facets puts standards in contracts, or book a demo.

Frequently asked questions

Tags

#platform-engineering#cloud-cost-optimization