Catalog My learning Blog
Full-Stack Developer Course: React, .NET and SQL Server · Phase 15 · Lesson 144 · 7 min read

FinOps for Developers: Cloud Cost as Design

On this page
  1. Learning Objective
  2. Concept Explanation
  3. Worked Example: Tags and Budgets, Lifecycle Rules, Telemetry Sampling and Policy Guardrails
  4. Real-World Examples
  5. Review Questions & Answers

Learning Objective

Understand the main drivers of cloud cost, measure unit economics, apply tagging, budgets and policies, reduce cost through right sizing, tiering and telemetry control without weakening security, and include cost in design reviews and pull requests.

Concept Explanation

Cloud pricing makes cost a property of architecture, and developers make architectural decisions daily: which database tier, how much to log, whether services chat across regions, how long to retain data. FinOps is the practice of bringing engineering, finance, and product together around cloud spending, with the idea that everyone who influences cost sees it and owns part of it. Start by making costs visible and attributable. Tag every resource with owner, environment, and application, enforce it with Azure Policy so untagged resources cannot be created, and use cost analysis views by tag. Set budgets with alerts at thresholds such as 50, 80, and 100 percent of the expected amount, sent to the owning team and not only to finance.

Absolute numbers are less useful than unit economics: cost per tenant, per active user, per thousand requests, or per document processed. If revenue per customer is 50 dollars a month and infrastructure per customer is 40, the business has a problem that no dashboard of totals will reveal, and if cost per request rises after a release, you have found a performance regression with a price. Track the ratio over time and use it to decide where optimization effort pays.

The cost drivers are predictable. Compute is often overprovisioned: right size by measuring actual CPU and memory use, scale down at night and on weekends for non-production environments, use autoscaling with sensible minimums, and commit to reservations or savings plans for steady baseline workloads, since one and three year commitments give large discounts. For databases, choose the service tier from measured need, and consider serverless tiers with auto-pause for intermittent use. Storage cost depends on tier and lifecycle: use lifecycle policies to move old blobs to cooler tiers and delete what is no longer required, which also serves the retention duties of Day 136. Network egress, data leaving a region or the cloud, is charged and is easy to forget, so avoid chatty cross-region calls, use a CDN for downloads, and keep services that talk a lot in the same region. Telemetry is a surprisingly large line item: logging every request body, or keeping every trace at full volume, can cost more than the servers, so sample traces, set log levels deliberately, drop noisy events, and tier retention.

Cost has security implications in both directions. A sudden unexplained rise in spend is a security signal: stolen credentials are commonly used to start large numbers of virtual machines for cryptocurrency mining, and unauthenticated or runaway endpoints in serverless designs produce a bill from abuse, so cost anomaly alerts belong in the security monitoring. Policies that restrict allowed regions and sizes of resources limit the damage a compromised account can do. Conversely, do not cut security to save money: disabling logs that you need for investigation, skipping backups, or removing redundancy for critical systems trades a small saving for a large risk. Make cost visible at design time by including an estimate in design documents and by running a cost estimation tool on infrastructure changes in pull requests, and revisit the decision to stay in the cloud rather than assuming it, since some companies with predictable, large workloads have moved parts of them elsewhere.

Cost driverLeversWatch for
ComputeRight size, autoscale, schedule non-production, reservationsIdle capacity and oversized instances
DatabaseRight tier, serverless with auto-pause for spiky useProvisioned capacity nobody uses
StorageLifecycle tiering, retention limits, delete orphansOld snapshots and unattached disks
NetworkSame-region traffic, CDN, compressionCross-region chatter and egress
TelemetrySampling, log levels, retention tiersFull payload logging and debug logs left on
CommitmentsReservations and savings plans for steady baselineCommitting before usage is understood

Worked Example: Tags and Budgets, Lifecycle Rules, Telemetry Sampling and Policy Guardrails

The Bicep sets a budget and lifecycle policy. The C# reduces telemetry cost, and the policy blocks expensive mistakes.

Bicep
// A monthly budget with alerts to the owning team.
resource budget 'Microsoft.Consumption/budgets@2023-05-01' = {
  name: 'budget-taskboard-prod'
  properties: {
    category: 'Cost'
    amount: 4000
    timeGrain: 'Monthly'
    timePeriod: { startDate: '2026-10-01' }
    filter: { tags: { name: 'app', operator: 'In', values: ['taskboard'] } }
    notifications: {
      at80: { enabled: true, operator: 'GreaterThan', threshold: 80, contactEmails: ['taskboard-team@example.com'], thresholdType: 'Actual' }
      at100: { enabled: true, operator: 'GreaterThan', threshold: 100, contactEmails: ['taskboard-team@example.com', 'finops@example.com'], thresholdType: 'Forecasted' }
    }
  }
}

// Storage lifecycle: cool after 30 days, archive after 180, delete after the retention period.
resource lifecycle 'Microsoft.Storage/storageAccounts/managementPolicies@2023-01-01' = {
  parent: storage
  name: 'default'
  properties: {
    policy: {
      rules: [ {
        name: 'age-out-uploads', enabled: true, type: 'Lifecycle'
        definition: {
          filters: { blobTypes: ['blockBlob'], prefixMatch: ['files/'] }
          actions: { baseBlob: { tierToCool: { daysAfterModificationGreaterThan: 30 }, tierToArchive: { daysAfterModificationGreaterThan: 180 }, delete: { daysAfterModificationGreaterThan: 1095 } } }
        }
      } ]
    }
  }
}
Code
// Azure Policy: deny resources without the required tags, and deny very large SKUs outside production.
{
  "if": { "anyOf": [ { "field": "tags['owner']", "exists": "false" }, { "field": "tags['app']", "exists": "false" } ] },
  "then": { "effect": "deny" }
}
C#
// Telemetry that does not cost more than the service: sample traces, keep errors, and drop noise.
builder.Services.AddOpenTelemetry()
    .WithTracing(t => t
        .SetSampler(new ParentBasedSampler(new TraceIdRatioBasedSampler(0.1)))                  // keep 10 percent of traces, following the parent's decision
        .AddAspNetCoreInstrumentation(o => o.Filter = ctx => !ctx.Request.Path.StartsWithSegments("/healthz"))   // health probes are not worth storing
        .AddSqlClientInstrumentation(o => o.SetDbStatementForText = false));                   // also keeps SQL text and parameters out of telemetry

builder.Logging.AddFilter("Microsoft.AspNetCore", LogLevel.Warning);                            // framework chatter off by default
builder.Logging.AddFilter("Microsoft.EntityFrameworkCore.Database.Command", LogLevel.Warning);  // queries are for development
// Errors are kept in full elsewhere: tail-based sampling in the collector keeps every trace that contains an error or is slow.
Code
Cost review in a design document or pull request
  Estimated monthly cost at expected load, and at 10 times the load.
  Cost per tenant or per 1,000 requests after the change, compared with before.
  Egress paths: does any hot path cross a region or leave the cloud?
  Telemetry: what is logged per request and how long is it kept?
  Idle cost: what does this run overnight in dev and test, and can it scale to zero?
Weekly, someone reads the top ten cost changes and the anomaly alerts, and asks why each moved.

Use the anomaly alerts as a security control as well. If a resource group's spend triples overnight with no deployment to explain it, treat it as a possible compromise until proven otherwise.

Tags attribute every resource, budgets alert the owning team, and unit economics show cost per tenant or per thousand requests. Right sizing, storage tiering and telemetry sampling cut waste, policies block expensive mistakes, and a cost anomaly is treated as a possible compromise.
Tags attribute every resource, budgets alert the owning team, and unit economics show cost per tenant or per thousand requests. Right sizing, storage tiering and telemetry sampling cut waste, policies block expensive mistakes, and a cost anomaly is treated as a possible compromise.

Real-World Examples

  • Dropbox moved most of its storage from Amazon Web Services to its own infrastructure between 2015 and 2016, and its 2018 filing to go public reported savings of about 75 million dollars over two years. It is the well-known case that at very large and predictable scale, the economics can favor owning infrastructure, although it required a large investment in engineering.
  • The software company 37signals announced in 2022 that it was leaving the public cloud, reporting that it expected to save around two million dollars a year in infrastructure costs after buying its own servers. Its founders presented the numbers publicly, and the debate that followed underlined that cloud cost deserves periodic scrutiny, particularly for stable workloads.
Key TakeawaysTreat cloud cost as a design constraint from the start, like performance or security, rather than a bill to explain afterwards. To do that, tag and attribute all spend, set budgets with alerts to the owning team, measure unit economics, and reduce cost by right sizing, scheduling, tiering storage, keeping traffic local, and controlling telemetry. Use policies to prevent expensive mistakes, treat cost anomalies as possible security incidents, do not cut logging or backups to save money, and add cost estimates to design reviews.

Review Questions & Answers

Totals rise with growth and hide whether the business is efficient, while cost per tenant, user, or request shows whether each unit of value is profitable and whether a change made it worse. They point to where optimization matters.

Stolen credentials are often used to start many virtual machines for cryptocurrency mining, and abuse of open endpoints in serverless designs runs up charges. A sudden unexplained spike should trigger an investigation, not just a budget conversation.

Logging full request payloads or keeping every trace at full volume produces very large data volumes that are billed for ingestion and retention. Sampling, sensible log levels, filtering noise, and tiered retention cut cost while keeping error traces.

Removing backups, redundancy for critical systems, and the logs needed for security investigation trade a small saving for large risk. Cost work should target waste, not the controls that protect the business.