Why rulii

I've been a software consultant for about 25 years, a lot of it in the financial sector. If there's one rule I've learned, it's that rules change. And when they do, we spend hours trying to find them, change them and retest the system.

Where the rules end up

Here's what I've seen over and over, and God knows I've done it myself. We write the business rules and slot them into the business tier, right in with the business logic and the data access. That works fine when there are six of them. But when a system has a lot of rules, or the rules keep changing, you can't find anything. A small change has a large blast radius. You spend hours hunting for the rule, and then even longer retesting everything around it.

As a consultant, I didn't mind at first. It paid the bills.

But as I got older, I wanted a better way. I wanted rules I could isolate, test on their own, and change without touching half the system.

What was already out there

So I went looking. IBM had ILOG JRules, which we assessed. And there was Drools.

Drools we actually used. Around 2008 we ran it in a client's lending platform. It does what it advertises, but it just didn't solve the problem the way we wanted it to.

We needed to run the rules in a predictable manner, and a Rete engine isn't meant for that. It looks at the facts, works out which rules match, and decides for itself what fires next. Perhaps it was us choosing the wrong tool for the job.

The learning curve was steep for the average developer. It kind of reminded me of my late nights fighting Prolog in my CS courses. And when something went wrong, the debugging was hard to follow. You weren't asking "what does this line do?" You were asking "why did the engine fire that?"

It just thought differently from the rest of our code. So we moved away from it and went back to what we knew best, putting the rules in the business tier. After all, it paid the bills.

So I wrote one

After running into the same problem with other clients, I decided to do something about it. I started ruling-class around 2017 in my spare time, and finally released it in 2019. Through word of mouth, several of my former clients took to it and put it into production. Some of them still run it today.

Most of what you see in rulii today was already in there in some form. Rule sets went in nine days after the first commit, in July 2019. A first version of rule flows followed a week later. The validation rules started that September, and there were 38 of them by the end of 2021. Bean validation was under way by then too. It's all on GitHub, 523 commits of it, most of them before 2022.

By 2024, ruling-class had done what it set out to do. It was a simple engine that ran the rules.

What it lacked was a functional style, where you build a rule from lambdas, and proper builders so developers could easily put together rules, rule sets and rule flows. Even the core pieces, the condition, the action and the function, were redesigned.

So I rewrote it from the ground up, based on the feedback I'd had on ruling-class. Well, mostly. Some of the original code is still in there.

The rewrite went faster than the original. I'd already done the thinking, years earlier, and this time I had AI to help me polish, test and document it.

Since then, rulii has gone into production as well.

As for the name, I just like rulii.

Rules are first-class citizens

With rulii, your business rules become first-class citizens, like your controllers, managers, services and DAOs or repositories. They're isolated, so you can manage them independently. They get their own lifecycle. Rules written in XML, for example, can be loaded from outside the application, so changing one doesn't mean rebuilding it.

You can test them in isolation too. You stop worrying about "how do I get this data?" and only worry about "given this data, do these rules hold?" Your blast radius is now just the rules themselves.

It's plain Java

A rule in rulii is a condition and what to do when it holds. You write it as a Java class with a few annotations, or as a couple of lambdas. That's it. The compiler checks it, your IDE refactors it, and you test it with JUnit like everything else you write. The home page shows the same rule written each way.

When something goes wrong, you put a breakpoint in it. At least now you should be able to answer "what does this line do?"

Rules that belong together go in a rule set, and they run in the order you put them in. I did mention that mattered to us.

When you need more than a list, there's a rule flow. That's where you say what runs first, what runs only if something else passed, what runs in parallel, and what happens when something fails.

Validation runs on the same engine. The usual checks are built in, and the Bean Validation annotations you already have on your classes run as rules too.

And then there's the explorer. It shows you every rule, rule set and flow in a running Spring Boot application, in plain English, with a flowchart. Remember "you can't find anything"? Now you can.

There's no server to run and no new language to learn. The core engine is one jar. If you want everything, there are four libraries: the engine, the Spring integration, Bean Validation and the explorer.

What it's not for

rulii isn't the answer to everything, and I'd rather tell you now than have you find out in production.

It doesn't do inference. Rules run in the order you give them, and one rule firing doesn't send the engine back to reconsider the others. If you have a large body of facts and rules that need to reason about each other, that's what a Rete engine is for. This time it would be the right tool for the job.

There are no decision tables and no authoring screen yet. Today, rules are written by developers, in Java or XML. The explorer lets anyone read them, but it's read-only.

A rule flow isn't a workflow engine, at least not yet. It runs inside your application, start to finish, in memory. If you need a process that waits three days for someone to approve something, you'll need something else for now.

Both of those are on my list. If you'd use them, tell me, because that decides what gets built next.

The Bean Validation library isn't a certified implementation, and it doesn't run the TCK. It covers what an ordinary bean needs, and the differences are written down.

It needs Java 17 or later, and the explorer needs Spring Boot.

And it isn't backed by a large company. It's backed by me, and has been since 2017.

Picking the right tool

I've picked the wrong tool before, as you've read. So here's how I'd choose.

Plain Java. If you have a dozen rules and they rarely change, write the if statements. You don't need a rule engine, and you don't need me.

Drools. If your rules need to reason about each other over a lot of facts, or your business people work in decision tables or DMN, use Drools. It does all of that and rulii doesn't. It's also more to learn, as I found out.

Easy Rules. If you're on Easy Rules today, you already think about rules the way rulii does: plain Java, small, no ceremony. It's been in maintenance mode since December 2020, with bug fixes only. rulii is where I'd go next. It's the same idea, with rule flows, validation and the explorer. It runs in production today, and it gets regular releases. There's a migration guide for the move.

Hibernate Validator. If all you need is to validate beans, it does the job. It's the reference implementation and it's certified, so if that matters where you work, stay with it. rulii makes sense when a check is really a business rule. @NotNull and @Email are easy. "The order can't exceed the customer's credit limit" isn't, and in rulii you validate the bean with that rule, by name. That gives you flexibility too: what the rule does can change without touching the class. The constraints you already have keep working, and everything runs on one engine. I've written up a worked example.

rulii. If you have enough rules that you can't find them any more, they change often, and you want them in plain Java where your team can read, test and debug them, that's what I built it for.

Over to you

I put a lot of effort into building rulii because I needed it, and I'll keep at it for the same reason. It's open source, under Apache 2.0, and it runs in production.

If you find yourself managing a lot of rules, even if they're just for validating incoming data, try rulii. If something's wrong or missing, say so. If you'd rather fix it yourself, pull requests are welcome.

And if your rules stay in the business tier, I understand. After all, we do have bills to pay.