Design Usage Billing for One Account
Design an object model that turns one account's metered service usage and applicable rates into a deterministic itemized invoice.
Design a usage-billing service for one account. The source exercise supplies usage and a rate for every consumed service.
For this exercise, assume usage records fall inside one closed monthly billing period, each record has a stable usage ID, service, quantity, unit, and occurrence time, and rates have effective time ranges.
Produce an immutable invoice with one line per service and unit, using one currency and decimal arithmetic with rounding once per invoice line. Duplicate usage IDs must be charged once; reject negative quantities, unknown services, incompatible units, overlapping applicable rates, and uncovered usage.
Exclude taxes, discounts, payment collection, persistence, distributed scaling, and multi-account authorization. Design the responsibilities, public contracts, and calculation interaction without assuming a particular programming language or framework.