Quick revision
The short answer
Rules written as strategy classes are versioned, reviewed and tested like any other code, but every change needs a release. A rules engine or DSL lets business users change rules quickly, yet those changes then need their own testing, review, audit and rollback, which is easy to underestimate. Often the best answer is a middle path: parameterised strategies driven by validated configuration, with feature flags, and the decision should rest on how often rules change, who must change them and what auditors require, with a shared suite of pricing examples that every change must pass whichever way we go.
What to remember
In this answer, we saw that rules in code are safe and auditable but need a release for every change, while a rules engine gives business users speed at the price of building testing, review, audit and rollback for rule changes. A middle path of parameterised strategies driven by validated, versioned configuration and feature flags often covers most changes. The choice depends on how often and how rules change, who must change them, and audit needs, and a shared suite of pricing examples guards every change.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Rules written as strategy classes are versioned, reviewed and tested like any other code, but every change needs a release. A rules engine or DSL lets business users change rules quickly, yet those changes then need their own testing, review, audit and rollback, which is easy to underestimate. Often the best answer is a middle path: parameterised strategies driven by validated configuration, with feature flags, and the decision should rest on how often rules change, who must change them and what auditors require, with a shared suite of pricing examples that every change must pass whichever way we go.
Why this question is asked
Requests for a rules engine usually come from real pain: the business waits two weeks for a developer to change a discount from 10 to 12 percent. But the engine is a long-term commitment. It moves part of the system's logic out of the codebase into a place with different tools, different people and different failure modes, and it is hard to take back once hundreds of rules live there. Interviewers ask this to see whether a senior engineer can find the real problem behind the request and weigh speed against control over several years. In this answer, we will look at what rules in code give us, what a rules engine really demands, the middle path of configurable strategies, the questions that decide between them, and the safety net we keep in every case.
1Understanding the Request First
Before comparing technologies, we find out what is slow today. We look at the last year of pricing changes: how many there were, how many were only new numbers such as rates and thresholds, and how many were new logic, such as a bundle discount that never existed before. We also measure the lead time from request to production and see where it goes. Often the code change takes an hour and the wait comes from the release train, which is a delivery problem a rules engine will not fix.
Suppose the data shows 120 pricing changes last year: 95 were parameter changes, 20 were new combinations of existing rule types, and 5 were genuinely new logic. That pattern points strongly towards configuration, not a full engine, because most changes do not need new logic at all.
2What Rules in Code Give Us
Strategy classes in code get every safety mechanism the engineering organisation already has. Every change is in version control with an author and a reason, it is reviewed by someone who understands the pricing model, it runs through unit and integration tests, and it can be rolled back by redeploying the previous version. For audit, the git history is a precise record of what rule was live when.
The cost is that every change, however small, needs a developer and a release. If releases are weekly, the business waits up to a week for a number change, and developers spend time on work that feels clerical to everyone involved.
3What a Rules Engine Really Demands
A rules engine, such as Drools, or a home-made DSL evaluated at runtime, lets rules be edited outside the code and take effect without a deployment. That is real speed. But all the safety we listed above does not come with it automatically. Rules are now logic, written by people who may not think about edge cases like negative totals or overlapping discounts. Somebody has to test them, review them, record who changed what and when for the auditors, and be able to roll back a bad rule at 6 p.m. on Black Friday. If the engine has no environment to try rules in and no versioning, a typo can reach every customer instantly.
There are other long-term costs too. The engine is a dependency with its own upgrade path and licence or operational burden. Its rule language is a second programming language that developers must learn and debug. And rule sets tend to grow until nobody understands their interactions, which recreates the original problem in a place with weaker tools.
| Option | Speed of change | Safety and audit | Long-term cost |
|---|---|---|---|
| Strategy classes in code | A release per change | Strong: review, tests, git history | Developer time per change |
| Configurable strategies | Minutes for parameters | Strong if configuration is validated and versioned | Moderate: admin UI, validation |
| Rules engine or DSL | Minutes for new logic | Only as good as the governance we build | High: engine, skills, rule sprawl |
4The Middle Path: Configurable Strategies
Between the two sits a design that often captures most of the benefit. We keep the rule types in code, as strategies, but make their parameters configuration: a PercentageDiscount with a rate, a ThresholdDiscount with a minimum and an amount, a BundleDiscount with a list of SKUs. Business users change the numbers and combine existing rule types through an admin screen. New kinds of logic still go through a release, which is rare if the data looks like our example.
- Pricing analyst edits parametersAdmin screen, draft version
- Validate and run the example suiteConstructors reject bad values
- All examples pass?Hundreds of known baskets and pricesYesRequest approvalNoShow failing examples
- Second person approvesRecorded for audit
- Activate behind a feature flagOne market or a percentage first
- Monitor revenue and errorsRoll back to the previous version if needed
6 steps in order. Play them, or step through them one at a time.
Notice the compact constructor that rejects nonsense values. Every configuration change goes through that validation and through the example suite before it is activated. Each version is stored with who approved it, which gives auditors their record. Feature flags let us activate a new rule for 5 percent of traffic or one market first, and rolling back is switching to the previous version.
5The Questions That Decide
Three questions settle most cases. How often do rules change, and what kind of change is it? A few parameter changes a month fit configuration; dozens of new logic changes a week might justify an engine. Who must make the change? If pricing analysts must own the logic itself, a constrained DSL or engine may be necessary; if they mostly tune numbers, configuration is enough. What do regulators and auditors require? In financial services or insurance, we may need to show which exact rule priced a given quote three years ago, which favours versioned artefacts, whether code or configuration, over freely edited rules.
We also think about reversibility. Moving from configurable strategies to an engine later is possible if the demand grows. Moving hundreds of rules out of an engine back into code is a painful migration. So when the evidence is unclear, starting with the middle path keeps our options open.
6The Safety Net We Keep Either Way
Whatever we choose, we build a suite of pricing examples: real baskets with their expected prices, agreed with the business, covering normal cases and edge cases like empty carts, maximum quantities and stacked promotions. Every change, a code change, a configuration change or a new engine rule, must pass it before going live. When the business changes a rule on purpose, they update the expected prices in the same change, which makes the effect of the rule visible. This suite is the contract between engineering and the business, and it is what makes speed safe.
7Follow-up questions
If we do choose a rules engine, what must be in place on day one?
Versioned rule sets with an author and approver per change, an environment to test rules against the example suite before activation, a fast rollback to the previous version, and audit logs that tie each priced order to the rule set version that priced it. Without those, the engine trades a slow release for unsafe production changes.
Who owns the rules after the change?
Ownership should be explicit. With configurable strategies, the pricing team owns the values and engineering owns the rule types and the validation. Writing that down avoids the situation where a bad price goes live and each side assumes the other checked it.
How do you avoid the release bottleneck without any new tooling?
Sometimes the honest fix is delivery: if a code change takes an hour but waits a week for the release train, continuous deployment for the pricing service may give the business the speed it wants while keeping rules in code.
8Conclusion
In this answer, we saw that rules in code are safe and auditable but need a release for every change, while a rules engine gives business users speed at the price of building testing, review, audit and rollback for rule changes. A middle path of parameterised strategies driven by validated, versioned configuration and feature flags often covers most changes. The choice depends on how often and how rules change, who must change them, and audit needs, and a shared suite of pricing examples guards every change.
Open with
I would start by looking at what actually changed last year, because a rules engine is a long-term commitment. If most of the pricing changes were new numbers and only a handful were new logic, the problem is the release cycle, not the absence of an engine.
Then, if they want more
Rules in code have real strengths: they are reviewed, tested, versioned in git and easy to roll back, and auditors can see exactly what was live. The cost is a developer and a release for every change.
A rules engine gives the business speed, but then rule changes need their own testing, review, approval, audit trail and rollback, and we take on a second language, a dependency, and the risk that rule sets sprawl until nobody understands them.
So I would usually propose a middle path: keep rule types as strategies in code, but make their parameters configuration that pricing analysts can edit, with validation in the constructors, versioning, a second approver and feature flags to activate changes gradually. New kinds of logic still go through a release.
The deciding questions are how often and what kind of rules change, who must change them, and what regulators need for audit. Whatever we choose, I would build a suite of real pricing examples agreed with the business, and every change, code or configuration, must pass it before going live. That suite is what makes faster changes safe.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Pricing rules are implemented as strategy classes in code. The business wants to change...": https://scrivio-interview-library.netlify.app/java/behavioral-patterns/0ab8e36745/