Problem statement
Design the object model and core APIs for a discount and pricing rule engine that evaluates a shopping cart and produces a final, itemised price. The engine holds a catalog of promotions authored by a merchandising team, decides which ones apply to a given cart, and returns the adjusted line items plus a breakdown of every discount that fired.
Operating context. One in-process library called synchronously during checkout of a storefront (think a mid-size online shop). A cart carries line items (product id, unit price, quantity, category tags) and a customer context (membership tier, first-order flag, coupon codes entered). Promotions come in several shapes: a flat percent or fixed-amount off, a buy-X-get-Y (BOGO) offer, a tiered spend threshold (spend more, save more), a category-wide markdown, and coupon-gated variants of any of these. Rules carry a priority and a stacking policy: some combine with others, some are exclusive and suppress the rest. New promo shapes are added every quarter by engineers who should not have to touch the evaluation loop. Money is integer minor units; results must be deterministic and reproducible for auditing.
Out of scope. Persistence and the admin UI that authors rules, tax and shipping computation, currency conversion and multi-currency carts, inventory and stock checks, and the HTTP/checkout transport. Focus on the in-process object model, not any storage or network layer.
What to produce. The class hierarchy (the rule abstraction and its concrete variants, the cart and line-item model, the evaluation service, and the result/breakdown types), the public API each type exposes, and the evaluation flow. Be explicit about: how a rule decides whether it applies and what adjustment it emits; how priority orders rules and how the stacking policy resolves exclusive-vs-combinable conflicts; how BOGO and tiered rules read cart state without corrupting it mid-pass; and how a brand-new promo type is added without editing the engine that runs the rules.
Requirements
This assessment is a Premium feature.
The statement above is free to read. The functional and non-functional requirements, and the graded canvas that scores your design against them, come with Premium.
Topics
- System Design LLD
- Oop Solid
- Patterns Strategy
- Patterns Command
- Extensibility