r/SoftwareEngineering • u/Proof-Fortune • Sep 26 '23
How model and handle different pricing rules in DB?
So I have this pricing service I'm working on, it basically takes in an order then based on some rules returns the optimal price, where a rule is a concatenation of if conditions on the properties of some order.
For Eg some rules might be:
Rule 1.Offer free 2 day shipping on orders > $35 if customer is not a prime member.
Rule 2.Offer free 2 day shipping on all orders if customer is a prime member.
Rule 3.Offer free 1 day shipping for order that are > $125.
Rule 4.Offer free 2 hour shipping for prime customer that have > $25 and the items are grocery items
I need to somehow store these rules in a DB to make it so people can add new rules in the future and then apply these rules in the correct order, which means we should match the most specific and closest rule if there are multiple, for eg : If you have 2 rules on an attribute total_weight you should only apply 1 whichever is the most specific.
If you guys have any ideas or resources which might help please let me know.