Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RazorTrace

AI-Powered Payment Failure Intelligence & Revenue Recovery on Microsoft Azure

Observe → Correlate → Diagnose → Validate → Recover → Measure

RazorTrace is a payment infrastructure intelligence system that correlates payment telemetry, application failures, and network conditions to determine why a payment failed and choose a safe recovery strategy.

Instead of treating every timeout or failure as a reason to retry, RazorTrace distinguishes between network faults, provider degradation, provider latency, and genuine bank declines before taking action.

AI diagnoses. Policy controls. Infrastructure executes.


Why RazorTrace?

Payment failures are not always payment problems.

A transaction may fail because of:

  • network packet loss or connectivity failure
  • provider latency
  • provider HTTP errors
  • temporary service degradation
  • genuine bank rejection
  • an unknown outcome where the provider processed the payment but the response was lost

Blindly retrying these failures can cause duplicate transactions or unnecessary payment attempts.

RazorTrace combines infrastructure telemetry with AI-assisted diagnosis and deterministic recovery policy to make safer decisions.


Architecture

RazorTrace Azure Architecture

RazorTrace runs inside a controlled Microsoft Azure environment containing two Linux virtual machines.

  • Application VM hosts the RazorTrace API, telemetry, AI integration, recovery logic, metrics, and dashboard.
  • Gateway VM hosts the Provider and Bank simulators while also acting as the network fault-injection layer.
  • Azure AI Foundry / Azure OpenAI provides AI-assisted root-cause diagnosis using gpt-4.1-mini.
  • Azure Monitor and Log Analytics provide supporting infrastructure observability.

Core Decision Pipeline

flowchart LR
    A[Payment Request] --> B[Observe]
    B --> C[Correlate]
    C --> D[AI Diagnose]
    D --> E[Policy Validate]
    E --> F[Recover]
    F --> G[Measure]
    G --> H[Dashboard]
Loading

How It Works

A normal synthetic payment follows:

Merchant / Test Client
        ↓
RazorTrace Gateway API
        ↓
Provider Simulator
        ↓
Bank Simulator

When a payment fails or times out, RazorTrace builds a structured incident using payment and network evidence.

Payment Failure
      ↓
Telemetry Collection
      ↓
Incident Correlation
      ↓
AI Root-Cause Diagnosis
      ↓
Deterministic Policy Validation
      ↓
Safe Recovery
      ↓
Revenue & Incident Metrics

The AI returns:

  • root cause
  • confidence
  • supporting evidence
  • recommended recovery action

Supported actions include:

RECONCILE · RETRY · WAIT · STOP

The AI does not directly execute financial actions.


Validated Failure Scenarios

Scenario Payment State Diagnosis Safe Action
Provider latency TIMEOUT PROVIDER_LATENCY RECONCILE
Provider HTTP 503 FAILED PROVIDER_UNAVAILABLE / DEGRADATION WAIT / RETRY
Genuine bank decline DECLINED GENUINE_DECLINE STOP
Network failure TIMEOUT NETWORK_FAILURE RECONCILE

Why this distinction matters

A timeout does not automatically mean retry.

For example, the Provider may have successfully authorized a transaction while the response was delayed beyond the Gateway timeout.

RazorTrace treats this as an unknown outcome and reconciles with the Provider before taking further action.

This prevents unsafe duplicate retries.


Safe Recovery Example

During the Provider latency experiment:

Provider Delay
      ↓
Gateway TIMEOUT
      ↓
Network HEALTHY
      ↓
PROVIDER_LATENCY
      ↓
AI recommends RECONCILE
      ↓
Policy validates RECONCILE
      ↓
Provider reports AUTHORIZED
      ↓
Payment becomes CAPTURED

The transaction was recovered without blindly creating another payment attempt.


Revenue Intelligence

RazorTrace tracks the business impact of payment infrastructure failures.

Metric Description
Total Transactions Number of synthetic transactions processed
Timed Out Payments entering an unknown timeout state
Recovered Transactions Failed/timed-out payments safely recovered
Recovery Rate Percentage of recoverable failures successfully recovered
Revenue At Risk Value associated with infrastructure failures
Revenue Recovered Value successfully recovered
Duplicate Retries Prevented Potential unsafe retries avoided through reconciliation

Example Recovery Run

Metric Result
Transaction Amount ₹2,499
Original State TIMEOUT
Final State CAPTURED
Recovery Action RECONCILE
Recovery Rate 100%
Revenue Recovered ₹2,499
Duplicate Retry Prevented Yes

These values are from a synthetic validation scenario and are not production payment benchmarks.


Dashboard

The RazorTrace dashboard provides a live view of payment intelligence and recovery metrics.

RazorTrace Recovery Dashboard

It displays:

  • total transactions
  • revenue at risk
  • revenue recovered
  • recovery rate
  • timed-out payments
  • duplicate retries prevented
  • transaction status
  • correlated incident
  • AI diagnosis
  • recommended action
  • recovery result

Failure Injection

RazorTrace includes a controlled Azure networking laboratory for reproducing infrastructure failures.

Tested conditions include:

  • latency
  • packet loss
  • jitter
  • bandwidth restriction
  • TCP rejection
  • silent packet drop
  • HTTP 500
  • HTTP 503
  • slow provider response
  • provider outage
  • genuine bank decline

Example network fault:

sudo iptables -I INPUT 1 \
  -s <SERVER_PRIVATE_IP> \
  -p tcp \
  --dport 8002 \
  -j DROP

The fault is removed after testing:

sudo iptables -D INPUT \
  -s <SERVER_PRIVATE_IP> \
  -p tcp \
  --dport 8002 \
  -j DROP

Azure Services

Azure Component Purpose
Azure Virtual Machines Hosts RazorTrace and the network/payment lab
Azure Virtual Network Provides isolated application and gateway networking
Azure Route Table Routes controlled traffic through the gateway
Azure AI Foundry / Azure OpenAI AI-assisted incident diagnosis
Azure Monitor VM and infrastructure monitoring
Log Analytics Supporting observability

The implementation intentionally avoids unnecessary cloud services to keep the prototype focused on the core payment intelligence workflow.


Technology Stack

Layer Technology
API Python, FastAPI
HTTP Client HTTPX
Runtime Uvicorn
AI Azure AI Foundry / Azure OpenAI
Model GPT-4.1-mini
Networking Linux routing, iptables, tc/netem
Cloud Microsoft Azure
Dashboard HTML, CSS, JavaScript
Service Management systemd
Testing Python scenario tests

Project Structure

RazorTrace/
├── config/
│   └── .env.example
│
├── docs/
│   ├── architecture/
│   └── screenshots/
│
├── infrastructure/
│   └── azure/
│       └── README.md
│
├── scripts/
│   └── merchant_client.py
│
├── services/
│   ├── ai/
│   ├── bank/
│   ├── dashboard/
│   ├── gateway/
│   ├── metrics/
│   ├── provider/
│   ├── recovery/
│   └── telemetry/
│
├── tests/
│   ├── test_provider_latency.py
│   ├── test_provider_503.py
│   ├── test_bank_decline.py
│   ├── test_network_failure.py
│   └── videos/
│
├── requirements.txt
├── .gitignore
└── README.md

Configuration

RazorTrace uses environment variables for deployment-specific configuration.

Copy:

config/.env.example

and configure values for your environment.

Example:

PROVIDER_URL=http://127.0.0.1:8002

AZURE_OPENAI_ENDPOINT=https://<your-resource>.services.ai.azure.com
AZURE_OPENAI_API_KEY=<your-api-key>
AZURE_OPENAI_DEPLOYMENT=gpt-4.1-mini

Never commit real API credentials.


Running the Services

Create a Python environment and install dependencies:

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Start the Bank Simulator:

uvicorn services.bank.main:app --host 0.0.0.0 --port 8003

Start the Provider Simulator:

uvicorn services.provider.main:app --host 0.0.0.0 --port 8002

Start RazorTrace:

uvicorn services.gateway.main:app --host 0.0.0.0 --port 8001

Dashboard:

http://127.0.0.1:8001/dashboard

In the Azure lab environment, the dashboard is accessed through SSH port forwarding rather than intentionally exposing it publicly.


Testing

Each major failure condition has an independent scenario test.

python tests/test_provider_latency.py
python tests/test_provider_503.py
python tests/test_bank_decline.py
python tests/test_network_failure.py

Recorded test demonstrations are available under:

tests/videos/

Test Evidence

Scenario Recording
Provider latency & reconciliation Video
Provider HTTP 503 Video
Genuine bank decline Video
Network failure Video

Development Evidence

Selected implementation screenshots:

Unified Telemetry & Correlation

Unified Incident Correlation

AI Diagnosis

AI Provider Latency Diagnosis

Safe Reconciliation

Safe Recovery

Revenue Recovery Metrics

Revenue Metrics


Key Takeaway

Traditional payment monitoring often tells engineers that a payment failed.

RazorTrace attempts to determine:

Why did it fail, what evidence supports that diagnosis, and what is the safest thing to do next?

By combining payment telemetry, network observability, AI-assisted diagnosis, deterministic policy validation, safe reconciliation, and revenue-impact measurement, RazorTrace turns payment failures into actionable infrastructure intelligence.


Author

Sanjay Narayanan V, Electronics and Communication Engineering


License

This project is licensed under the MIT License. See the LICENSE file for details.

RazorTrace

Observe. Correlate. Diagnose. Validate. Recover. Measure.

About

AI-Powered Payment Failure Intelligence & Revenue Recovery on Microsoft Azure

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages