# GCP Cloud SQL Committed Use Discount Opportunity

> Flags steady production Cloud SQL instances where a 1-year committed use discount beats on-demand, priced from live rates.

Source: https://zop.dev/integrations/gcp/recommendations/gcp-cloud-sql-committed-use-discount-opportunity

---

## What a Cloud SQL commitment buys and locks in

Cloud SQL committed use discounts are spend-based. You commit to a consistent amount of usage,
measured as hourly on-demand spend, in one region for one or three years. Google's
[Cloud SQL CUD page](https://cloud.google.com/sql/docs/mysql/cud) lists the discount as 25% for
a 1-year term and 52% for a 3-year term, the same in every region. The discount applies
automatically to CPU and memory of MySQL, PostgreSQL and SQL Server instances in that region,
including Enterprise and Enterprise Plus editions.

The limits matter as much as the rate. Shared-core machine types such as `db-f1-micro` are
excluded, and so are storage, backups, IP addresses, outbound data transfer and licensing. Usage
above the commitment is billed on demand. And a commitment cannot be cancelled once bought.

## Sizing a commitment from your own data

List instances with their tier and labels, which is where production status usually shows:

```bash
gcloud sql instances list \
  --format="table(name,region,settings.tier,settings.userLabels)"
```

Then chart `cloudsql.googleapis.com/database/cpu/utilization` and
`cloudsql.googleapis.com/database/memory/utilization` over the last 60 days in Metrics Explorer.
The lowest steady level across your production instances in a region is a safe commitment size.

## Four gates before a recommendation appears

1. The instance looks like production: its name contains `prod`, `production` or `live`, or an
   `env`, `environment`, `stage` or `tier` label is set to `prod`, `production`, `prd` or `live`.
2. ZopNight has at least 60 days of history for it, and it was running at least 70% of that time.
3. Measured CPU or memory utilisation averages at least 30%, so the commitment covers real load.
4. The instance has a known cost and Google's live rates show a positive commitment discount.

## When ZopNight holds back

If any gate fails, or utilisation has never been measured, there is no finding. A break-even
check then compares a commitment billed for all 730 hours of a month with on-demand for the
hours the instance really ran; when the commitment would cost more, the rule stays silent.
Non-production instances are never considered, however steady they look.

## How the saving is calculated

```text
saving = on-demand cost for measured running hours - 1-year commitment cost (730 h)
fallback when running hours are unknown: saving = monthly cost x live commitment discount
```

The finding quotes the resulting percentage for the instance.

## Buying the commitment

1. Confirm the instance, or its replacement in the same region, will run for at least a year.
2. Add up steady hourly spend across production instances in the region and commit to that
   baseline rather than peak.
3. Purchase the Cloud SQL commitment in the billing console's committed use discounts page for
   that region.
4. Review coverage monthly; spend above the commitment is simply billed on demand.

**Warning**
Cloud SQL commitments cannot be cancelled. Undersize rather than oversize.
