A Spring Boot payment initiation platform with multi-tier caching and idempotent processing.
Payforge models the edge of a modern payment system: accept a transfer, validate it rigorously, and guarantee that client retries never create duplicate payments. Built for production-style concerns — latency, correctness under retries, and clean service boundaries.
┌──────────────────────────────────────┐
Client ────────► │ Payforge Edge API │
│ Validation · Idempotency · Caching │
└──────────────┬───────────────────────┘
│
┌────────────────────┼────────────────────┐
▼ ▼ ▼
Caffeine Redis PostgreSQL
L1 (in-process) L2 (shared) L3 (source of truth)
~ms ~ms durable
| Capability | Implementation |
|---|---|
| Create transfer | POST /api/v1/transfers |
| Input validation | Bean Validation + curated ISO-4217 currency catalog |
| Idempotent retries | Idempotency-Key header — same key returns the original result |
| Multi-tier cache | Caffeine (process) → Redis (shared, TTL) → PostgreSQL (durable) |
| Modular design | Edge API, domain library, and core service modules |
| Stack | Java 17 · Spring Boot · PostgreSQL · Redis (Lettuce) · Caffeine · Maven |
Payment clients retry when networks fail. Payforge treats every create as potentially a duplicate:
- Client sends
Idempotency-Key(or reusestransferId) - Edge looks up the key in Caffeine → Redis → PostgreSQL
- Hit → return the known payment (
DUPLICATE) without creating a new one - Miss → accept the payment (
ACCEPTED) for processing
Hot duplicate traffic is answered from process memory. On a miss, values found in Redis or the database are written upward so the next request is faster — a pattern used in high-throughput financial APIs.
| Module | Responsibility |
|---|---|
| edge | REST API, currency catalog, idempotency store (:8080) |
| domain | Transfer model, persistence contracts, response envelope |
| core | Processing service shell (:8081) |
Package root: dev.harsh.payforge · Edge packages: api, currency, idempotency, infrastructure
- Language: Java 17
- Framework: Spring Boot (Web, Cache, Data JPA, Data Redis)
- Data: PostgreSQL
- Caching: Caffeine + Redis
- Build: Maven (multi-module)
Requirements: JDK 17+, PostgreSQL, Redis
# Database & cache
createdb payforge
redis-server
# Build shared module, then start the edge API
cd domain && ./mvnw -q install -DskipTests && cd ..
cd edge && ./mvnw spring-boot:runAPI base: http://localhost:8080
curl -sS -X POST http://localhost:8080/api/v1/transfers \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: payDemo001' \
-d '{
"transferId": "payDemo001",
"amount": 1500.00,
"currency": "INR",
"payer": {
"holderName": "Ada Lovelace",
"accountNumber": "123456789012",
"routingCode": "HDFC0001234"
},
"payee": {
"holderName": "Bob Builder",
"accountNumber": "987654321098",
"routingCode": "ICIC0001234"
}
}'Replay the same Idempotency-Key after the payment is stored — the API returns the original transfer instead of creating another.
- Payment-domain thinking — initiation, validation, and retry safety as first-class concerns
- Systems design — multi-level caching, cache promotion, clear read/write paths
- Spring mastery — REST, validation, JPA, Redis, modular Maven structure
- API design — versioned routes, structured responses (
ACCEPTED/DUPLICATE), standard idempotency headers
Harsh Srivastava
github.com/HarshDevelops