Module 6: Security & Cost Optimization

Cost monitoring + alerts

Cloud costs are a silent killer. Bills grow without you noticing until the end of the month. This capsule shows you how to monitor in real-time and set alerts to avoid surprises.


Why it matters

Real cases:

  • An indie dev gets a $40K bill after a viral post + autoscaling with no maximum.
  • A startup forgets its test infra, it keeps running for 6 months, $30K wasted.
  • A DDoS attack triggers autoscaling, a $1000+ bill in 24h.
  • A misconfigured S3 bucket with public reads, the bandwidth bill explodes.

Prevention is easy. Discovery without prevention is painful.


Set up billing alerts (on every provider)

AWS

AWS Console → Billing → Budgets → Create budget
- Monthly threshold: $50
- Alert at: 80% ($40)
- Email: you@example.com

Free. There's no reason not to enable it.

GCP

GCP Console → Billing → Budgets & alerts
- Set a monthly budget: $50
- Alert thresholds: 50%, 90%, 100%

Render / Railway / Fly.io / Vercel

Each platform has a billing dashboard + email alerts. Enable them.

Render specifically

Account → Billing → Spending notifications
Email me when monthly usage exceeds: $X

Set it up ASAP.


The cost monitoring dashboard

A daily check

The habit: every morning, check yesterday's spend.

Render dashboard → Billing → Daily usage chart

Look for spikes. $5/day is normal? Yesterday $50/day = investigate.

A weekly review

Friday afternoon:

  • Compare the week vs the prior week.
  • Identify trends.
  • Forecast the month.

A monthly retrospective

Total spent: $200.
Breakdown:
- Render compute: $80
- Supabase Pro: $25
- Upstash: $10
- Cloudflare: $0
- Bandwidth: $5
- ... etc.

Each line: justify it or optimize it.


Tools

Cloud-native dashboards

  • AWS Cost Explorer.
  • The GCP Billing Console.
  • The Render Dashboard Billing.

Built-in. Free.

Third-party

For multi-cloud / advanced:

  • Vantage (a cloud cost dashboard).
  • CloudHealth (enterprise).
  • Spot.io (auto-optimization).

For an SMB: cloud-native is enough.


What to monitor

Beyond the total $$:

  • A per-service breakdown: which services cost the most.
  • Per-environment: dev vs staging vs prod.
  • Trends: growing? stable?
  • Anomalies: an unexpected spike.
  • Resource waste: idle instances, unused storage.

Set up alerts that matter

Layer 1: hard caps

If monthly spend > $200: ALERT (email + Slack)
If monthly spend > $500: PANIC (page the on-call)

Hard limits. They can't be ignored.

Layer 2: anomaly detection

If today's spend > 3× the average: alert
If a single service's spend doubles week-over-week: alert

It catches gradual drift.

Layer 3: forecast alerts

Most clouds predict the end-of-month total based on the trend. Alert if the forecast > the budget.


Specific cost traps

Bandwidth

1 GB egress: $0.09 AWS, $0.085 GCP, $0.05 Render, $0 Cloudflare.

If your app serves 1TB/month directly from the origin: $50-90. If it goes through Cloudflare: $0.

Mitigation: a CDN for anything static.

Idle resources

A test environment running 24/7 even when nobody uses it.

A test Postgres DB on AWS RDS: $30/mo, used 5 hrs/mo.

Mitigation: a scheduled stop/start or spot instances.

Forgotten resources

You created an S3 bucket for a one-off project 2 years ago.
It has 500GB of data.
It costs $11.50/mo forever.

A quarterly audit: list all the resources, justify each one.

Logs and metrics

CloudWatch Logs ingested: 10TB/mo at $0.50/GB = $5000/mo.

Verbose logging with no retention policy.

Mitigation: log retention rules, sampling, structured logging.

Database backups

RDS automatic backups beyond the retention window: storage costs.

Configure the retention sensibly (7-30 days is typical).

Unused load balancers

An ALB: $20/mo + LCU usage.

Created for a project that's done. Still running. Forgotten.

A quarterly scan.


Cost-aware development

1. Optimize before scaling

A slow query → fix it (guide #12).
Don't scale to mask inefficiency.

Optimize once, save forever.

2. Right-size resources

An over-provisioned instance: 90% of the RAM unused.
Downsize → save 50%.

Audit periodically.

3. Reservations

For consistent loads:

  • AWS Reserved Instances: 30-70% savings vs on-demand.
  • Render annual plans: discounts.

For bursty ones: spot/preemptible (cheap but they can be revoked).

4. Free tiers

Many services have generous free tiers:

  • Supabase free: 500MB DB.
  • Upstash free: 10K commands/day.
  • Cloudflare free: bandwidth + DDoS.
  • Vercel free: small sites.

Stack free tiers for development and small projects.

5. Avoid premium features

  • "Premium support" $200/mo: rarely needed.
  • "Advanced analytics" $50/mo: there are built-in alternatives.
  • "Priority queues" $30/mo: scale what you already have.

Audit which paid features you actually use.


Budget calculator template

## My API Budget

### Monthly

| Service | Plan | Cost |
|---------|------|------|
| Render (4 instances) | Starter × 4 | $28 |
| Supabase | Pro | $25 |
| Upstash Redis | Free | $0 |
| Cloudflare | Free | $0 |
| Sentry | Team | $26 |
| SendGrid (email) | Essentials | $20 |
| **TOTAL** | | **$99/mo** |

### Quarterly review

- [ ] Verify all services still needed.
- [ ] Right-size instances.
- [ ] Cancel unused subscriptions.
- [ ] Review trends.

### Annual

- [ ] Negotiate enterprise discounts (if applicable).
- [ ] Consider reservations for stable workloads.
- [ ] Major architecture review.

### Alerts active

- [x] Render spend > $50/mo
- [x] Sentry issues spike (could indicate runaway loop)
- [x] Sentry crashes (DB issues)

Traps and common mistakes

1. No alerts set up.

"I'll check the bill at the end of the month." Too late.

2. Trusting the "free tier".

You hit the limit, it auto-charges. Or the "free tier" changes. Always set a hard cap.

3. Provisioning for peak load 24/7.

The peak is 2 hours/day. You pay for 24h. Use autoscaling with limits.

4. Forgetting test/staging environments.

You spin them up, forget them, the costs accumulate. Tag your resources, clean up weekly.

5. Logs with no retention.

Forever-stored logs = a forever-growing bill.

6. Multiple regions with no justification.

Multi-region multiplies the costs. Single-region is fine for 99% of SaaS.

7. A reserved instance commitment for an uncertain workload.

A 3-year commit on an instance you might not need in 6 months. Wasted $.

Reservations: only for stable, well-understood workloads.


Exercise: a cost audit

Step 1: list all the services + costs.

| Service | Cost/mo | Used? | Justified? |
|---------|---------|-------|------------|
| ... | | | |

Step 2: identify trimming opportunities.

  • Unused services → cancel.
  • Over-provisioned → downsize.
  • Unused premium features → downgrade.

Step 3: set up alerts.

  • Render: monthly > $X.
  • The cloud provider: a budget alert.
  • Anomaly: 3× a normal day.

Step 4: document it.

## Cost audit Q2 2026

Pre-audit: $150/mo.

Findings:
- Premium Sentry plan unused features → downgrade to Team. Save $20/mo.
- Test DB running 24/7 → schedule stop nights/weekends. Save $20/mo.
- Old S3 bucket forgotten → delete. Save $5/mo.

Post-audit: $105/mo. Saving $45/mo.

Alerts:
- Render > $80
- Total > $150
- Anomaly: 2× normal day

Step 5: a quarterly cadence.

A calendar reminder: every 3 months, repeat the audit.


Summary and next step

What you learned:

  • Set billing alerts with every provider. Free, a no-brainer.
  • Daily/weekly/monthly reviews: spotting trends + anomalies.
  • Cost traps: bandwidth, idle resources, forgotten ones, logs, backups.
  • Cost-aware development: optimize first, right-size, free tiers.
  • Quarterly audits as a discipline.

In the next capsule we go to cost optimization strategies: techniques to cut bills 30-70%.


Resources

  1. AWS Cost Optimization — reference.
  2. Vantage — a cost dashboard.
  3. Cloudflare for a free CDN — bandwidth savings.

Capsule 06 of 08 — Module 6 — Deployment & System Design Guide