Files
cloud-services/services/cost

Cost Service

Per-vehicle cost estimation service for capacity planning and cloud vs on-prem comparison.

Overview

This service estimates the cost of running cloud services per VIN by:

  1. Querying vehicle activity from ClickHouse (message counts)
  2. Estimating resource usage based on activity level
  3. Applying cost rates for cloud vs on-prem hosting
  4. Storing aggregated cost data for reporting

Cost Estimation Methodology

Resource Estimates Per Active VIN

Activity Level Messages/15min CPU (cores) Memory (GB)
Low < 100 0.05 0.1
Medium 100-1000 0.075 0.15
High > 1000 0.10 0.2

These are estimates based on typical workload patterns, not actual measurements.

Cost Rates (per hour)

Resource Cloud (Azure) On-Prem
CPU/core $0.08 $0.02
Memory/GB $0.015 $0.004

Cloud Rates (Fudged Higher)

  • Based on Azure D-series VM pricing + 20% overhead
  • Includes: compute, managed services, networking, support
  • Intentionally conservative (higher) to show cloud costs

On-Prem Rates (Fudged Lower)

  • Based on 3-year hardware amortization
  • Assumes: owned hardware, minimal ops overhead
  • Intentionally optimistic (lower) to show on-prem savings
  • Does NOT include: datacenter costs, staff, power, cooling

Savings Calculation

Cloud Cost = (CPU_cores × $0.08 + Memory_GB × $0.015) × hours
On-Prem Cost = (CPU_cores × $0.02 + Memory_GB × $0.004) × hours
Savings = Cloud Cost - On-Prem Cost
Savings % = (Savings / Cloud Cost) × 100

Expected savings: ~70-75% with on-prem hosting.

API Endpoints

GET /cost/vin/{vin}

Cost summary for a specific VIN.

GET /cost/fleet

Fleet-wide cost summary with top cost VINs.

GET /cost/summary?period=day|week|month

High-level cost summary for a time period.

GET /cost/comparison

Cloud vs on-prem cost comparison with projected annual savings.

Configuration

Env Var Description Default
CLICKHOUSE_HOST Local CH for storing cost data localhost
REMOTE_CLICKHOUSE_HOST Dev cluster CH for VIN activity -
COLLECTOR_INTERVAL_MINUTES How often to collect metrics 15

Limitations

  • Resource estimates are approximations, not actual measurements
  • Cost rates are simplified and don't reflect all real-world factors
  • On-prem costs exclude significant operational overhead
  • Designed for business case illustration, not precise billing