← Back to work

ML systems · API · 2026

FraudLens

A real-time fraud-scoring API that answers one question for an analyst — which transactions to investigate, and why — with leakage-safe features, SHAP explanations, and a hybrid ML-plus-rules risk engine.

Python tests — API, leakage, idempotency
139
transactions in PostgreSQL (synthetic)
5M
ML / rules weighting in the risk score
70 / 30

Architecture

Select a stage to explore it.

01 · FastAPI

POST /score-transaction validates the raw transaction strictly: unknown fields and precomputed features are rejected, so a client can never inject its own risk signals.

dbt staging → intermediate → marts on PostgreSQLDocker multi-stage, non-root imagesTerraform for AWS ECS Fargate, RDS, S3 · GitHub Actions CI

01 · Problem

A fraud team has limited investigation capacity. A model that outputs a probability is not enough: an analyst needs a ranked queue, a reason for every flag, and confidence that the score was not computed with information the system could not have had at the time.

02 · What I built

A synchronous scoring service: FastAPI validates an incoming transaction, the server rebuilds behavioral features from PostgreSQL history, a trained model scores it, SHAP explains it, and a risk engine turns the probability and a set of deterministic rules into a score and recommended action. Results are persisted and surface in an investigation queue.

Around the service sit an ingestion pipeline with schema validation and checksums, a dbt analytics layer, a Streamlit dashboard backed entirely by PostgreSQL, Docker images, Terraform definitions for an AWS deployment, and CI workflows.

03 · Engineering decisions

Features are generated server-side rather than accepted from the client, which prevents training/inference mismatch and blocks fabricated inputs. The temporal cutoff is strict (< T), and the dataset's precomputed fields that carried leakage are rejected at validation. Scoring is idempotent through a PostgreSQL upsert, and persistence happens before the response so the API never reports a result it failed to store.

04 · Limitations

The 5M-row dataset is synthetic (generated to mimic Nigerian banking patterns), so model scores say more about the pipeline than about real-world fraud. Latency has not been stress-tested at scale, drift monitoring and retraining are not implemented, and the API has no authentication. These are documented in the repository rather than hidden.

05 · Lessons learned

In fraud work, the leakage controls are the product. Most of the effort went into making sure a score could be defended — what data it used, when that data existed, and why the system acted on it.