Skip to content

Improve Price Calculation Logic and Accuracy #2

@songk1992

Description

@songk1992

Summary

The current price calculation logic in rustcost-core works for basic scenarios but lacks the precision needed for more complex or cloud-aligned cost models. Improving the calculation engine will ensure more reliable outputs and better alignment with real-world billing structures.

Problem

Some pricing formulas are overly simplified, do not account for edge cases, or don't match how cloud providers calculate usage-based costs. This can lead to inaccuracies when modeling workloads with varying compute, storage, or network characteristics.

Goals

Refine the internal cost computation logic to improve accuracy.

Support more granular pricing components (e.g., per-GB, per-request, per-CPU-hour).

Handle tiered, variable, or region-specific pricing more correctly.

Improve numeric precision and rounding behavior.

Proposed Improvements

Introduce a more modular calculation pipeline to support complex pricing structures.

Add validation for intermediate calculation values.

Improve unit conversions (e.g., MiB ↔ GB, seconds ↔ hours).

Add test cases covering edge scenarios and multi-factor cost formulas.

Document the calculation model to ensure consistency across crates.

Expected Benefits

More accurate and reliable cost outputs.

Consistent results between UI, dashboard, and core engine.

Foundation for future cloud-provider-specific pricing models.

Notes

These improvements should remain backward compatible with existing APIs but allow future extensions such as spot pricing, tiered billing, and usage-based modifiers.

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions