Back to flagship systems

Case study / Explainable decision service

Fraud Rule Engine

A .NET 10 service that evaluates transaction events against eight rule shapes, persists every outcome, and returns an explainable Approve, Review, or Decline decision.

Private sourceSynthetic demo
  • Eight rule shapes
  • Three decisions
  • Versioned explanations
  • Retry-safe assessments
  • C#
  • .NET 10
  • ASP.NET Core
  • PostgreSQL 17
  • Entity Framework Core
  • OpenTelemetry
  • Docker

Guided case study

Follow an assessment from signal to explanation.

Move through the reasoning in six short chapters, or read every chapter with JavaScript disabled.

01 / Problem

Turn signals into a decision a person can inspect.

The useful output is more than a fraud flag. Each transaction needs a bounded score, one of three decisions, and the full reason from every rule that ran.

02 / Constraints

History, retries, and changing policy all affect correctness.

Some rules need recent rows, others need a 90-day aggregate, repeated events must return the original assessment, and an old decision must remain explainable after thresholds change.

03 / Architecture

IO stays at the edges of a pure decision core.

The API validates and authenticates, the application layer loads customer context, pure domain rules evaluate it, and PostgreSQL persists the transaction, assessment, and rule outcomes atomically.

04 / Decisions

Rules report severity while one policy owns scoring.

Low, Medium, and High signals map to central weights. Review begins at 40, Decline at 75, and scores stop at 100. Every assessment carries a rule-set version and configuration fingerprint.

05 / Evidence

Tests exercise the boundaries that change the answer.

Domain and architecture tests protect the dependency direction, while integration tests use real PostgreSQL for idempotency, persistence, filtering, keyset pagination, and health behavior.

06 / Limits

The portfolio evaluator is deliberately smaller than the service.

This page runs a synthetic, client-side version of the eight decisions. It does not call the private API, store transactions, or represent a production fraud verdict.

Chapter 1 of 6: Problem.

Synthetic evaluator

Change a transaction. Inspect every rule.

This client-side demonstration stores nothing and never represents a real financial decision.

Synthetic ruleset: portfolio-demo-1. All calculations stay in this page.

25of 100
DecisionApproveReview at 40. Decline at 75.
Clear

High value transaction

ZAR 6000.00 is below the ZAR 25000.00 threshold.

Clear

High-risk category

Groceries is not in the configured category watchlist.

Clear

Denied merchant

The synthetic merchant is not on the configured deny list.

Clear

Unusual hour

The local transaction hour 14:00 falls outside the unusual-hour window.

Clear

Transaction velocity

1 transactions in 15 minutes is below the threshold of 5.

Clear

Impossible travel

0 km/h does not exceed the card-present travel ceiling.

Medium / 25 points

First-time merchant, high value

The merchant is new, the baseline has at least 10 transactions, and the amount is at least ZAR 5000.00.

Clear

Amount escalation

The baseline count and five-times-average conditions are not both met.

Synthetic transaction evaluated. Score 25. Decision Approve.

01 / Engineering problem

Context changes what a transaction means.

A transaction alone cannot answer questions about velocity, travel, or a customer baseline. The service must combine current and historical context without letting retries create conflicting assessments.

02 / Durable decisions

The explanation is part of the result.

Designed the domain model, rule pipeline, scoring policy, API boundary, PostgreSQL persistence, operational signals, and real-database integration coverage as one coherent back-end system.

01

Load context before running rules

Rules stay synchronous and testable because recent history and long-term aggregates arrive in one evaluation context.

02

Persist every rule outcome

Triggered and clear outcomes both carry reasons, so a stored assessment explains why each rule did or did not contribute.

03

Make retries return the original result

A unique event boundary and transactional persistence prevent duplicate deliveries from creating two decisions.

04

Keep reads stable as data grows

Keyset pagination avoids large offsets and reduces skipped or repeated rows while new assessments arrive.

03 / What this demonstrates

Back-end decisions that remain inspectable under change.

The system joins domain modelling, persistence, security, observability, and tests around one rule: a decision should carry enough evidence to explain itself.

Discuss an explainable service