Analyzes infrastructure and service costs, evaluates cost impact of new features, and recommends optimizations for pay-per-use services.
Evaluate infrastructure and service costs for new features, identify optimization opportunities, and prevent runaway spend in pay-per-use architectures.
Triggered by the code reviewer when any of the following apply:
| Trigger | Examples |
|---|---|
| New database listeners | Real-time subscriptions, snapshot listeners |
| New serverless function triggers | On-write, on-create, on-delete, scheduled |
| Storage increase | Image uploads, export files, backups |
| Per-user scaling |
| New documents/records created per user |
| High-frequency reads | Queries called on every screen load |
| External API calls | Third-party services billed per call |
| Operation Type | Cost Driver | Questions to Ask |
|---|---|---|
| Database reads | Per document read | How many docs per call? Call frequency? |
| Database writes | Per document write | How often? Per user action? Per event? |
| Serverless invocations | Per invocation + compute time | What triggers it? Unbounded triggers? |
| Storage | Per GB stored + per GB transferred | Average file size? Retention policy? |
| External API | Per request or per unit | Rate limits? Caching possible? |
Use this projection model:
Daily cost = (ops_per_user_per_day × active_users × cost_per_op)
Break-even users = budget_per_day / (ops_per_user_per_day × cost_per_op)
| Scale Tier | Active Users | Use for |
|---|---|---|
| Early | 100 | Sanity check |
| Growth | 10,000 | Planning |
| Scale | 100,000 | Ceiling risk |
| Pattern | Risk | Fix |
|---|---|---|
| Unbounded listener on large collection | O(collection_size) read on every change | Filter or paginate |
| Fan-out write per user action | Writes × followers on every post | Batch or queue fan-out |
| No caching of expensive query | Same data re-fetched every screen load | Cache with TTL |
| On-write function triggered by own writes | Infinite loop risk | Guard with conditional check |
| No retention policy on storage | Files accumulate forever | Add lifecycle rule |
| N+1 query pattern | 1 query to list + 1 per item | Batch fetch or denormalize |
Priority order:
Define alerts at these levels:
| Level | Action |
|---|---|
| 50% of monthly budget | Notify team |
| 75% of monthly budget | Review spend, pause non-critical jobs |
| 90% of monthly budget | Escalate to decision maker |
| 100% of monthly budget | Auto-disable non-critical services if possible |
## Cost Impact Analysis
**Feature**: [Feature name]
**Review date**: [Date]
### New Operations Introduced
| Operation | Trigger | Est. calls/user/day | Cost/op | Cost at 10k users/day |
|-----------|---------|--------------------|---------|-----------------------|
| [op] | [trigger] | [N] | [$ ] | [$ ] |
### Risk Findings
| # | Severity | Pattern | Location | Recommendation |
|---|----------|---------|----------|----------------|
| 1 | High | Unbounded listener | file:line | [Fix] |
### Projection Summary
| Scenario | Daily Cost | Monthly Cost |
|----------|-----------|-------------|
| 1k users | $ | $ |
| 10k users | $ | $ |
| 100k users | $ | $ |
### Verdict
APPROVE / REQUEST CHANGES
**Blocking issues**: [list or "None"]
**Recommended optimizations**: [list]
Include: