Rule engine
The rule engine applies the bank’s policy to each authorization, at the rules step: fraud, compliance,
routing, restrictions of a brand or a clientele. A rule is data: the bank writes, tests and activates it
without a deployment. Module ubo-rule-engine.
A rule’s model
Section titled “A rule’s model”| Element | Content |
|---|---|
| Identity | Name, description, category (protocol, fraud, compliance, limits, routing, custom), tags |
| Scope | Base (all the bank’s organisations), an organisation, a product; inclusions and exclusions card by card |
| Priority | Evaluation order; the first rule that declines decides |
| Form | Simple: a list of conditions and an action. Complex: a flow of nodes |
| Action | Approve, decline with a code, flag, ask for strong authentication, approve partially |
| State | Active or not; an inactive rule is never evaluated |
| Version | Each change creates a version; each version’s snapshot is kept |
The data dictionary
Section titled “The data dictionary”All the usable data are filed by object, with their type, an example and help:
| Object | Examples |
|---|---|
transaction |
amount (and in euros), currency, channel, type (purchase, withdrawal, credit), hour, weekday, recurrence, exemption |
trame |
the fields of the request received from the network (entry mode, ECI, terminal, merchant…), with their label |
carte |
status, product, network, type, form, BIN, expiry, creation and activation dates, language |
porteur |
KYC level, PEP, AML risk, nationality, country, age, seniority |
compte |
available, booked balance, overdraft, currency |
commercant |
name, MCC, country, city, new merchant for this card, terminal |
historique |
operations over 5 min, 1 h, 24 h; declines over 24 h; amounts today, 7 days, 30 days; withdrawals over 30 days; contactless since the last strong authentication |
authentification |
PIN entered and verified, cryptogram, CVV2, ECI, CAVV result |
appel.<node> |
the fields received from an external call, its status (success, timeout, error) and duration |
vars |
the variables computed by “Enrich” nodes or scripts |
reponse |
the response being prepared (readable fields, and those the bank may write) |
The history is read from a cache of the card’s recent activity (Redis), kept right by the database’s signals: it costs almost nothing at each authorization.
The nodes of a complex rule
Section titled “The nodes of a complex rule”Tests a data: equal, different, greater, lower, in a list, contains, starts with; conditions combine (and, or). Two outputs: true, false.
Queries a catalogue service (KYC, fraud score, merchant reference data) or a free address. Timeout per call (100 ms by default), retries (0 to 5), several operations in parallel, three outputs: success, timeout, error. An output not linked applies the node’s default (continue while flagging, or decline with a code).
Sets a variable: a value, a field, or a formula (vars.ratio = transaction.amount_eur / max(historique.amount_30d / 30, 1)), with min, max, abs, round, contains, in, if…
A Rhai script (embedded language, close to JavaScript) for computations a formula cannot do: it reads the objects and sets variables, without network or file access, cut beyond 10 ms or a number of operations.
Writes the fields free for the issuer in the response to the network (additional data, private data, balances shown at the ATM…). The fields carrying the decision (response code, approval code, approved amount) are only written by the Decision node: an inconsistent change is refused and traced with its reason.
Notify raises an alert and an event without blocking the operation. Decision approves, declines with a code (05, 51, 57, 59, 61, 62, 91…), flags, asks for strong authentication (1A) or approves partially.
Evaluation
Section titled “Evaluation”- The active rules applying to the card are selected: base, the card’s organisation, product, minus the card’s exclusions and plus its inclusions.
- They are evaluated by priority, with the operation’s context (the dictionary above).
- The first rule that declines decides the decline and its code; rules that flag add their alerts without stopping the operation.
- The whole step fits in a budget (800 ms by default, set per bank): beyond it, the remaining calls take the “timeout” output.
External calls, safely
Section titled “External calls, safely”| Guarantee | How |
|---|---|
| The card number never leaves | Only the token, the BIN, the last four digits and the other useful data can be sent |
| A service down does not slow everything | Circuit breaker: after several failures within a minute, the service is set aside for a few seconds, its calls take the “error” output; event rule.service_degraded |
| A call is made once | The same call (authorization, rule and version, node) is never repeated; a replay reuses the recorded answer |
| Secrets are protected | The services’ API keys are in the vault |
| Everything is traced | Each call: masked request, answer, duration, attempts, output taken; indicators per service for monitoring |
Versions, test and replay
Section titled “Versions, test and replay”- Test a rule before activating it: replay it on past operations (which would it have declined?); enter services’ answers to exercise each output.
- Replay a real decision as it was (versions of the time) or with today’s rules; measure the impact of today’s rules on a selection of decisions (500 at most).
- Past versions stay readable: a decision keeps the version that made it.

