Build a Shipping Cost Calculator With Pluggable Pricing Rules
Last updated: November 29, 2026
Quick Overview
Design a shipping cost calculator where the base rate depends on weight and zone, and adjustments such as Prime free shipping, oversize surcharges, and promotional discounts can be added, removed or reordered by configuration without changing the calculator.
Amazon
November 29, 20260
0
0 solved
Design a shipping cost calculator where the base rate depends on weight and zone, and adjustments such as Prime free shipping, oversize surcharges, and promotional discounts can be added, removed or reordered by configuration without changing the calculator.
A design-for-extension question in the style of Amazon SDE technical screens. The interviewer checks use of the strategy or chain-of-responsibility pattern, a clear rule ordering contract, money in integer cents, and an explanation trail for customer support.
What the Interviewer Expects
- Separate base rate strategy from adjustment rules
- Define a rule interface and an explicit ordering
- Use integer cents and never go below zero
- Produce a breakdown explaining each adjustment
- Make rules unit-testable in isolation
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you load rule configuration at runtime safely?
- How would you A/B test a new surcharge?
- How do you prevent two discounts from stacking when they should not?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Shipment has weight in grams, destination zone (1 to 8), dimensions, and customer flags (is_prime). Rules apply in configured order, each seeing the running total. Output total cents and a list of (ru...
High-Level Design
BaseRatestrategy:price(shipment) -> centsfrom a weight-tier and zone table.Ruleinterface:apply(shipment, running_cents) -> delta_cents(0 means not applicable).- Concrete rules: `Ov...