Tuesday, June 10, 2025

Sindhudurg — Building a Scalable API Fortress for Fraud Detection

 

๐Ÿ›ก️ Sindhudurg — Building a Scalable API Fortress for Fraud Detection

When Chhatrapati Shivaji Maharaj built Sindhudurg Fort, he did it not just with stones — but with vision.
Strategically placed on the coast, Sindhudurg was a gateway, a shield, and a statement: “Swarajya watches every entry.”

So when I began building the Fraud-Free Swarajya project, the API Gateway — the place where every transaction first arrives — had to be named Sindhudurg.


๐Ÿ” The Role of Sindhudurg

This is the entry point of the system. A Spring Boot application that:

✅ Accepts payment transaction requests
✅ Calls the AI module (tanaji) over HTTP
✅ Applies fraud rules (dadoji)
✅ Stores the transaction into PostgreSQL (ramchandrapant)
✅ Caches previous scores via Redis (jiva)
✅ Exposes Prometheus metrics for monitoring (kanhoji)

All while returning a real-time fraud risk score with explanation and recommendation.


๐Ÿ—️ Spring Boot Clean Architecture

We followed a layered approach:

  • Controller Layer — Exposes /api/v1/fraud-score

  • Service Layer — Orchestrates logic (AI + Rules + Cache + DB)

  • Client Layer — Uses WebClient to call tanaji (Python FastAPI)

  • DTO Layer — Separate request and response objects

  • Entity Layer — JPA-backed PostgreSQL persistence


๐ŸŒ Talking to AI with WebClient

Instead of embedding ML in the same codebase, we call tanaji over HTTP:


WebClient webClient = WebClient.builder().build(); Mono<FraudScoreResponse> response = webClient .post() .uri("http://tanaji:8000/score") .bodyValue(request) .retrieve() .bodyToMono(FraudScoreResponse.class);

Decoupling AI from business logic makes the system flexible and testable.


๐Ÿง  Redis Integration (Jiva)

To avoid re-scoring the same transaction, we cache responses in Redis:

String cached = redisTemplate.opsForValue().get(transactionId);
if (cached != null) return parse(cached);

Fast, idempotent, and aligns with real-world payment infrastructure.


๐Ÿ“ˆ Monitoring with Prometheus (Kanhoji)

We expose /actuator/prometheus metrics using Micrometer. This includes:

  • API call latency

  • Cache hits

  • Errors

These metrics are pulled into Grafana to visualize fraud scoring patterns.


๐Ÿณ Docker-Ready Microservice

Sindhudurg runs as a container and connects with others via Docker Compose:

services: sindhudurg: build: ./sindhudurg ports: - "8080:8080" environment: - TANAJI_URL=http://tanaji:8000


✅ Sample Request

curl -X POST http://localhost:8080/api/v1/fraud-score \ -H "Content-Type: application/json" \ -d '{ "transactionId": "txn001", "userId": "user123", "amount": 5000, "currency": "INR", ... }'



๐Ÿ“œ Trivia & Legacy: Why the Name Sindhudurg?

Before we wrap up, here are a few fascinating facts about the real Sindhudurg Fort — which inspired the name of this module:

  • ๐Ÿ️ Built on an island!
    Sindhudurg Fort was constructed by Chhatrapati Shivaji Maharaj in 1664 on the island of Kurte in the Arabian Sea, off the Malvan coast in Maharashtra.

  • ๐Ÿงฑ Over 50,000 kg of lead!
    The foundation stones were secured using molten lead to make the fort impenetrable. Think of it as the 17th-century version of bulletproofing!

  • ๐Ÿ‘ฃ Only fort with Shivaji Maharaj’s handprint and footprint.
    This is the only เค•िเคฒ्เคฒा (fort) where Chhatrapati Shivaji Maharaj’s เคชूเคœाเคธ्เคฅเคณ holds his actual handprint and footprint — making the fort not just strategic, but sacred.

  • ๐ŸŽฏ Built for coastal surveillance.
    Sindhudurg wasn’t just a fort — it was a sentinel guarding against naval invasions, much like our API guards digital transactions.

  • ๐Ÿšช Invisible entrance by design.
    The main gate is camouflaged and not visible from outside — a clever architectural move to confuse enemies, mirroring how our service quietly but smartly filters and flags risky traffic.


⚔️ Just like the original Sindhudurg stood between the kingdom and coastal invaders, this API module is the first barrier against fraud in the digital empire.

 


๐Ÿงญ What’s Next

In the next post, we’ll dive deep into tanaji, the AI engine — including model training, scoring logic, feature extraction and a lot of fun facts about Tanaji Malusare a legend himself.

But for now — our digital fortress is operational.


๐Ÿ› ️ Repo: github.com/pcm1984/fraud-free-swarajya
๐Ÿ“– Intro Blog to start with if you are seeing this for the first time: 
Building Fraud-Free Swarajya: My AI Journey Inspired by Shivaji Maharaj

"A kingdom must defend its gates before expanding its reach."
— Inspired by Sindhudurg.

No comments:

Post a Comment