Problem statement
Design the service that computes sales tax, VAT, or GST for a shopping cart at checkout, given a versioned set of jurisdiction rules, and produces an auditable, reproducible record when the order is committed.
Operating context. For each cart the service receives ship-to and bill-to addresses, line items with taxability categories, and the customer's tax status (e.g. exempt). It resolves the applicable jurisdictions (country, state/province, county, city, special districts) and rates from a rules dataset that changes constantly as thousands of jurisdictions update rates. The storefront calls the service on every cart change for a live estimate, then again at order commit to freeze the final numbers. A committed tax result must be reproducible and stored immutably for tax filing and audit years later. Peak is about 30000 calculation calls/sec.
Out of scope. Sourcing and legal interpretation of the raw rate data, tax filing and remittance to authorities, currency conversion, and invoice PDF generation. Assume a rules-authoring pipeline delivers validated, versioned rate datasets.
What to produce. A high-level architecture covering: how the versioned rules dataset is modeled and served for fast jurisdiction resolution, how a calculation is made deterministic and reproducible, how live estimates differ from the immutable committed record, how rule-dataset updates roll out without downtime or mid-cart inconsistency, and how committed records are stored for long-term audit. Sketch the components and trace a calculation from cart input to a per-line tax breakdown, and a commit to a stored immutable record.
Functional requirements
- Compute per-line and total tax for a cart from its addresses, line items, taxability categories, and customer tax status.
- Resolve the applicable jurisdictions and rates from a specific version of the rules dataset.
- Return a breakdown that names each jurisdiction, its rate, and the rule-dataset version used.
- Recompute and freeze tax at order commit, persisting an immutable record for filing and audit.
- Honor tax-exempt customers and product-level taxability categories in the calculation.
Non-functional requirements
- Serve 30000 calculation calls/sec at peak (from live cart updates) with p99 < 100 ms.
- Deterministic and reproducible: identical inputs plus a rule version always yield the identical result.
- Roll out rule-dataset updates spanning thousands of jurisdictions with zero downtime.
- 99.99% availability at checkout; degrade safely (bounded, flagged estimate) if a jurisdiction lookup stalls.
- Retain immutable committed-tax records 7+ years (~50 TB) with tamper-evident integrity.
Topics
- System Design HLD
- Commerce Tax
- Data Versioning
- Correctness Determinism
- Compliance Audit