Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 33 additions & 29 deletions docs/features/costs.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
# Cost Estimates

deployml integrates with [Infracost](https://github.com/infracost/infracost) to provide cost estimates before deploying your infrastructure, helping you manage cloud costs effectively in academic settings.

## Overview

Cost analysis runs automatically during deployment, showing monthly cost estimates for your entire stack, cost breakdowns by component, and warnings if costs exceed your configured threshold. The process analyzes your Terraform configuration before deployment, allowing you to adjust your configuration based on estimates.
deployml integrates with [Infracost](https://www.infracost.io) to show infrastructure costs. Both commands read your Terraform configuration — they price always-on resources like Cloud SQL accurately, but usage-based services (BigQuery, GCS, Cloud Run) show $0 since costs depend on actual usage. Check the GCP Billing Console for real usage charges.

## Setup

Install Infracost and register for a free API key using the instructions [here](https://www.infracost.io/docs/#quick-start).
```bash
brew install infracost
infracost auth login
```

## Configuration
Run `deployml doctor` to confirm infracost is installed and authenticated.

Cost analysis is enabled by default. Configure it in your YAML file to enable or disable cost analysis, set a warning threshold in USD (default $100/month), and choose the currency for cost display.
## Commands

Here is an example of what this might look like:
```yaml
cost_analysis:
enabled: true # Enable/disable cost analysis (default: true)
warning_threshold: 50.0 # Warn if monthly cost exceeds this amount (default: 100.0)
currency: "USD"
bucket_amount: 200 # GB stored across GCS buckets
cloudsql_amount: 50 # GB of Cloud SQL storage
**Before deploying** — estimates cost from your config without touching any infrastructure:
```bash
deployml estimate
```

## Typical Costs
**While deployed** — scans your actual deployed Terraform workspace:
```bash
deployml costs
```

Here are estimated typical costs for several **GCP** services, but please do not simply believe these numbers without keeping track of costs yourself.
Both commands show a breakdown of which resources cost money and how much.

- Cloud Run services cost $10-30 per month depending on traffic.
- Cloud SQL PostgreSQL ranges from $7/month for small instances to $25+ for production.
- Google Cloud Storage costs approximately $0.020 per GB per month.
- BigQuery storage costs $0.020 per GB per month with query costs based on data scanned.
- Cloud VMs cost approximately $25 per month for medium instances.
- GKE clusters have no management fee, but you pay for VM instances and load balancers. Note that the GKE can get very expensive very quickly.
## Cost shown during deploy

`deployml deploy` automatically runs a cost estimate after `terraform plan` and shows it before the confirmation prompt:
```
Deploy stack? Monthly cost: ~$34.55 USD [y/N]:
```

## Configuration

```yaml
cost_analysis:
enabled: true # set to false to skip (default: true)
warning_threshold: 50.0 # warn if monthly cost exceeds this (default: 100.0)
```

## Typical costs (Cloud Run stack)

## Cost Optimization
A standard MLflow + FastAPI + Grafana deployment runs around **$34/month**, almost entirely Cloud SQL. Cloud Run, BigQuery, and GCS scale to zero and cost nothing at idle.

Here are some tips to keep the costs low while you are learning:
## Keeping costs low

- Use SQLite instead of Cloud SQL whenever possible, particularly for development purposes and when your data is small.
- Enable auto-teardown to prevent forgotten deployments.
- Use Cloud Run for variable workloads to take advantage of scale-to-zero pricing.
- Always `deployml destroy` when done — Cloud SQL bills continuously.
- Use `backend_store_uri: sqlite` instead of `postgresql` during development to eliminate Cloud SQL entirely.
23 changes: 23 additions & 0 deletions docs/tutorials/gcp-cloud-run.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Make sure `deployml doctor` passes before starting. You will need:
- `gcloud` CLI, authenticated (`gcloud auth login` and `gcloud auth application-default login`)
- Docker (running)
- Terraform
- Infracost (optional, for cost estimates):
```bash
brew install infracost
infracost auth login
```

## 1. Create a GCP Project

Expand Down Expand Up @@ -71,6 +76,16 @@ stack:
- `model_serving` — deploys a FastAPI container that pulls the latest registered model from MLflow on startup
- `model_monitoring` — deploys Grafana connected to the Postgres `metrics` database

## 3.5 Estimate Costs (Optional)

Check what the stack will cost before committing to a 20-minute deploy:

```bash
deployml estimate
```

No GCP credentials required, no infrastructure touched. A standard Cloud Run stack runs around **$34/month** — almost entirely Cloud SQL. See [Cost Estimates](../features/costs.md).

## 4. Build Docker Images

Build and push the service images to Artifact Registry:
Expand Down Expand Up @@ -152,6 +167,14 @@ You should see `offline_features`, `predictions`, `ground_truth`, and `drift_met

With the stack running, follow the [example walkthrough](example.md) to train a model, register it, serve predictions through FastAPI, and visualize drift metrics in Grafana.

## 8.5 Check Running Costs

```bash
deployml costs
```

Shows what your deployed stack is currently costing. Cloud SQL is the main driver at ~$34/month — everything else scales to zero.

## 9. Teardown

When you are done, destroy all infrastructure to avoid ongoing charges:
Expand Down
Loading
Loading