-2

I'm designing a simple rule engine. Let me start by giving an overview.

The engine is initialized with a configuration file which specific the rules to be run and also parameters that are intended to be used by these rules.

Example:

I have a incoming order object and I will would like to do some sanity check on it like the order quantity cannot be greater than some quantity X ( x is passed as a parameter to the engine. ) This is a simple example of a parameter being passed.

A complex example:

Some order Type.Some region.Some desk.Order Quantity = X

Some order Type.Some region.Some desk.Some trader.Quantity = y.

Some order Type.Some region.Some Product.Daily Volume = A

Some order Type.Some region.Some desk.Daily Volume = B

A lot of parameters like these are used to initialize the engine which are intended to be used by the rules.

Question:

How should these initialization parameters be passed to API ? -- JSON , XML ???

What is the best software design practice to represent and process and store these parameters so that the rules can use this information ( like what's the quantity allowed for a trader group ? to do sanity checks on the incoming order object )

I'm planning to implement this in C++

Thanks in advance

KodeWarrior
  • 3,538
  • 3
  • 26
  • 40

1 Answers1

3

Before jumping into creating a new rules engine you should really be aware of the complexity involved e.g. Rete Algorithm this makes sense if you plan to maintain over thousands of rules because from those numbers and up if you evaluate the rules sequentially it becomes prohibitive performance-wise, and performance is particularly important in a trading system. I would actually research and explore reusing an existing rules engine e.g. CLIPS, drools, JRules etc.

Another promising possibility is to embed some sort of scripting language within your process (usually possible in e.g. Java) that can access your in-memory domain model e.g. embed a Python interpreter and use it as your "rules engine". If you absolutely must implement your own then you can use yacc and lex but last time I used it I remember it wasn't really fun and you have to be aware of the complexities i.e. scalability might become an issue if you plan to have thousands or more rules.

For rule management i.e. book keeping, editing, annotating, versioning etc you will want XML and put the actual rule under a CDATA element.

SkyWalker
  • 13,729
  • 18
  • 91
  • 187