Intelligent Payment Routing
Choose the payment processor for each card transaction in your Spring Boot service, with a Deep Netts neural network that learns which route keeps the most money for the merchant.

- 98.3 %
- of the possible gain captured (minimal, simulated payments)
- 5 routes
- with eligibility rules and availability (extended)
- 29 features
- from 13 transaction fields (extended)
- JDK 25
- Spring Boot 4.1 · Deep Netts core 4.0.5
The cheapest processor is not always the best choice
A merchant can send each card payment to one of several processors. They charge different fees and approve different kinds of payments at different rates.
A declined payment is a lost sale. Fees are known in advance, but approval rates have to be learned from past payments – that is what the model learns.
How it works
Describe the payment
Amount, cross-border or domestic, online or in store, debit or credit card, and the fraud score from the merchant’s risk system.
Encode it
The amount on a log scale, flags as 0 or 1 – every value between 0 and 1. The extended version derives 29 features, from card brand to hour of day.
Score every route at once
One multi-class Deep Netts network with one output per processor scores all routes in a single prediction.
Pick and fall back
The highest-scoring route wins. The extended version first removes ineligible or unavailable routes and returns a ranked list to retry down after a soft decline.
Inside the model
The network from the minimal version, neuron by neuron, in its real size.
Point at an input or an output to see what it is and how it is computed.
- One score per processor, summing to 1
- The highest score is the recommended processor
one output per route
Source: minimal/…/RoutingModel.java, PaymentEncoder.java, Processor.java
Walk through the code
Real files from the minimal version. Pick a step to see the lines that do it.
@RestControllerpublic class RoutingController { private final RoutingModel model; public RoutingController(RoutingModel model) { this.model = model; } @PostMapping("/api/routing/recommendation") public RoutingRecommendation recommend(@Valid @RequestBody Payment payment) { return model.recommend(payment); }}Two versions in one repository
Start with the minimal version to see the whole integration in a few files; move to the extended one for the full lifecycle.
The smallest complete integration of Deep Netts in a Spring Boot application.
- 3 processors, 5 request fields, 1 endpoint
- Train, evaluate, save and load
- Compared with the cheapest processor and a simple rule
A routing service that covers the complete machine learning lifecycle.
- 5 routes with eligibility rules and availability
- 29 features from 13 transaction fields
- 5 endpoints plus Spring Boot Actuator
- Fee-based fallback when no model is loaded
- Monitoring and quality-gated retraining, manual or scheduled
REST API
| POST | /api/routing/recommendation | Recommend a processor | minimal |
| POST | /api/routing/decisions | Ranked routes for one transaction | extended |
| GET | /api/routing/routes | Routes with rules, fees and availability | extended |
| PUT | /api/routing/routes/{route}/availability | Take a route out of service or back | extended |
| GET | /api/routing/model | Active model and metrics | extended |
| POST | /api/routing/model/retrain | Retrain, kept only if it passes the quality gate | extended |
POST /api/routing/recommendationContent-Type: application/json { "amount": 120, "crossBorder": true, "online": true, "debitCard": false, "riskScore": 0.05}{ "processor": "GLOBAL_PROCESSOR", "modelScores": { "LOCAL_BANK": 0.0, "GLOBAL_PROCESSOR": 1.0, "RISK_SPECIALIST": 0.0 }, "baselineProcessor": "LOCAL_BANK"}Run it locally
- JDK 25 (required by Deep Netts 4.x)
- Maven 3.9 or later
- No external services – trains on simulated payments
- Both versions use port 8080, run one at a time
git clone https://github.com/deepnetts/spring-boot-transaction-routing.gitcd spring-boot-transaction-routing/minimalmvn spring-boot:run # in a second terminalcurl -X POST localhost:8080/api/routing/recommendation -H "Content-Type: application/json" -d '{"amount": 120, "crossBorder": true, "online": true, "debitCard": false, "riskScore": 0.05}'Ready for AI coding assistants
The repository ships a SKILL.md with the rules an AI coding assistant must follow (output order, encoder consistency, independent evaluation, honest reporting) and ready-made prompts.
explain-the-example.mdGuided walkthrough for a Java developer new to ML, without changing filesadd-processor-or-feature.mdAdd a processor or a model input, then re-evaluatetrain-on-own-data.mdReplace the simulator with your historical payments, with a fixed splitreview-a-model-change.mdReview uncommitted changes against the SKILL.md rules
Good to know
- Both versions train on synthetic data; the results are not estimates of real-world performance.
- In the minimal simulation a simple two-line rule already reaches 92.9 % of the possible gain – the example does not show that machine learning beats a tuned rule.
- Scores are not calibrated probabilities. Route availability is kept in memory on a single instance.