Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Validation rules are often business rules in disguise and change often. How would you decide what belongs in annotations and what belongs in a rules engine or domain code over the long term?

I sort rules by how stable they are and who owns them. Annotations fit simple input rules that rarely change, such as required fields, lengths and formats. Rules that change often or need a business owner to decide them belong in domain code, or in a rules engine when the business must change them without a release, accepting that an engine brings its own tooling and testing costs. Wherever a rule lives, it must be testable and documented, and I would review rules with their business owners on a regular schedule.

Background to this question

Many validation annotations are business rules in disguise. @Max(10000) on a transfer amount looks like input validation, but it is really a limit the risk team set, and the risk team will change it next quarter, maybe differently per country. When such rules are hard-coded in annotations, every change needs a developer, a release and a hunt for copies. When everything moves into a rules engine, simple checks become hard to test. A senior engineer has to draw the line and keep it sensible for years. In this answer, we will build a way to classify rules, look at what annotations, domain code and rules engines each cost, keep rules testable and documented, and set up a review habit with the business.

1Telling Input Rules From Business Rules

The first step is to notice which kind of rule we are looking at. An input rule describes what a well-formed request looks like, independent of the business situation: an email has an @, a quantity is a whole number, a country code has two letters. These rules come from the shape of the data and almost never change.

A business rule describes what the business allows: a transfer above 10,000 needs approval, premium customers may have five open orders, discounts cannot be combined in Germany. These come from policy, regulation or strategy, they change when the business changes, and someone outside engineering owns the decision. The quick test I use is: if a product manager or compliance officer could ask us to change this value next month, it is a business rule, whatever annotation it currently hides behind.

Classifying rules
RuleChangesOwnerHome
email well formedalmost neverengineeringannotation
name at most 100 charactersrarelyengineeringannotation
transfer limit 10,000quarterlyrisk teamdomain code with config
max open orders by customer tieroftenproductdomain code
discount eligibility by countryweekly, campaign-drivenmarketingrules engine or config

2Annotations for Stable, Simple Input Rules

Annotations are excellent for input rules. They sit right on the field, Spring checks them before our code runs, they appear in generated API documentation, and every Java developer can read them. Their limits are exactly what business rules need: values are compile-time constants, they cannot load data or depend on who is calling, and changing them means a release.

Java
public record TransferRequest(
@NotBlank @Size(max = 34) String iban, // input rule: stays an annotation
@NotNull @Positive BigDecimal amount, // input rule: stays an annotation
@Max(10000) BigDecimal amountLimitHidden) {} // business rule in disguise: move it out

So I would keep input rules in annotations and move any annotation whose value comes from a policy decision into the domain.

3Domain Code for Rules With Business Meaning

For most business rules, plain domain code is the best home: a method on a domain object or a small policy class in the service that owns the data, with the changing values in configuration. It can load context, such as the customer's tier, give precise error codes, and be unit tested like any other code.

Java
@ConfigurationProperties("transfer.limits")
record TransferLimits(BigDecimal standard, BigDecimal premium) {}
@Component
class TransferPolicy {
private final TransferLimits limits;
TransferPolicy(TransferLimits limits) { this.limits = limits; }
Decision check(Customer c, BigDecimal amount) {
BigDecimal max = c.isPremium() ? limits.premium() : limits.standard();
return amount.compareTo(max) <= 0 ? Decision.ALLOW : Decision.needsApproval("LIMIT_EXCEEDED");
}
}
// standard 10000, amount 12000 -> needsApproval(LIMIT_EXCEEDED)

Notice that the rule now has a name, TransferPolicy, that business people can recognise in a conversation. Changing a limit becomes a configuration change, and changing the logic is a normal, reviewed code change with tests. For most companies, this covers the large majority of business rules.

4When a Rules Engine Is Worth Its Cost

A rules engine, such as Drools or a decision table service using the DMN standard, lets rules be written in a business-friendly form and changed at runtime, sometimes by business users themselves. That is valuable when rules change very often, there are hundreds of them, and the business must change them without waiting for a release, as in insurance pricing or campaign eligibility.

But an engine is a system of its own. It needs editors, versioning, deployment of rule sets, and above all tests: a rule changed by a business user at 5 pm can break checkout at 6 pm, and the usual code review and CI do not see it. The rule language is another skill to hire for, and debugging why a rule fired is harder than reading Java. So I would only introduce an engine when the change rate and ownership clearly demand it, and then with its own test suite of example cases that every rule change must pass before activation.

Step throughChoosing a home for a rule
  1. Is it about the shape of the input?
    YesAnnotation on the DTONoIt is a business rule
  2. Must the business change it without a release?
    YesConsider a rules engineNoDomain code
  3. Is the change rate high enough to pay for an engine?
    YesRules engine with its own testsNoDomain code with config values
  4. Document it in the rule catalogueowner, location, tests

4 steps in order. Play them, or step through them one at a time.

5Keeping Rules Testable, Documented and Reviewed

Wherever a rule lives, two things are not negotiable. It must be testable with concrete examples, such as a standard customer transferring 12,000 needs approval, and those examples should be readable by the business owner, so they can confirm the rule says what they meant. And it must be documented in a small rule catalogue: the rule in plain words, the owner, where it lives in the code or engine, and the tests that cover it.

Then rules need a rhythm of review. I would schedule a short review per domain with its business owners, say twice a year, going through the catalogue: is each rule still needed, are the values still right, and are any rules firing far more or less than expected? Logging rule decisions with their codes makes that conversation factual. Over years, this is what keeps validation from turning into an archaeology project.

6Follow-up questions

Is configuration enough instead of a rules engine?

Often, yes. If the logic is stable and only values change, such as limits per tier or per country, putting the values in configuration or a database table edited through an admin screen gives the business control without an engine. An engine is needed only when the logic itself changes frequently.

How do you test rules that business users change at runtime?

With a suite of example cases stored next to the rules, run automatically before a new rule version is activated, plus the ability to roll back to the previous version. Many teams also run new rule versions in shadow mode first, comparing decisions with the current version on real traffic.

Where should a rule that both the frontend and backend need live?

In the owning backend service, with an endpoint that the frontend calls for early feedback. The backend always enforces it on the real request, so the frontend copy is only a convenience and can never become a second, diverging source of truth.

7Conclusion

In this answer, we separated stable input rules, which fit annotations, from business rules that change often and need a business owner, which fit domain code with configuration values or, when the change rate justifies the tooling and testing cost, a rules engine. Wherever a rule lives, it should be testable with concrete examples and documented in a catalogue, and we review the catalogue with business owners periodically.

What to say in the interviewAbout 90 seconds aloud

Open with

My first step is to classify the rule. If it describes the shape of the input, like an email format, a maximum length or a required field, it is stable and owned by engineering, and annotations are the best home: Spring checks them early and they show up in the API docs.

Then, if they want more

If someone in the business could ask to change it next month, like a transfer limit or the number of open orders per customer tier, it is a business rule, even if it currently hides in an @Max annotation.

Most business rules I would put in domain code, a named policy class in the service that owns the data, with values that change often in configuration. That gives precise error codes, access to context, and normal unit tests and code review.

I would only bring in a rules engine like Drools or DMN decision tables when rules change so often that the business must change them without a release, because an engine adds editors, versioning, a new skill set and a real testing problem, since changes bypass CI.

Wherever rules live, they need tests written as concrete examples the business can read, and a small catalogue with the owner and location. And I would review the catalogue with the business owners regularly, using logs of which rules fire, so unused rules get removed.

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 documentation below. 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 "Validation rules are often business rules in disguise and change often. How would you...": https://scrivio-interview-library.netlify.app/spring-boot/request-validation/d774c090c1/