NTH Module - National Transaction Hub
Overview
The National Transaction Hub (NTH) is the central payment switch in the SAMPARK ecosystem, similar to NPCI's role in India's payment infrastructure. It acts as the core routing engine that facilitates inter-bank transactions, manages settlement processes, and ensures seamless communication between Payment Service Providers (PSPs).
Service Details
Port: 3005
Container Name: nth-service
Role: Central payment switch and transaction router
Technology: Node.js with Bun runtime
Architecture
Core Responsibilities
Transaction Routing: Routes payments between different PSP banks
Settlement Coordination: Manages inter-bank settlement processes
Message Processing: Handles Kafka-based event processing
Switch Logic: Implements payment switch logic for different transaction types
Network Management: Maintains participant registry and routing tables
Technology Stack
Runtime: Bun
Framework: Express.js + TypeScript
Message Broker: Apache Kafka
Caching: Redis Stack (shared instance)
Containerization: Docker
Service Dependencies
Infrastructure Dependencies
Kafka: Message broker for event-driven architecture
Zookeeper: Kafka cluster coordination
Redis Stack: Shared caching and session management
Docker Network: kafka-network for inter-service communication
Integration Points
PSP Banks: All four bank services for transaction routing
TPAP Applications: Indirect integration through PSP banks
Environment Variables
Transaction Processing
Supported Transaction Types
1. UPI Transactions
Flow: TPAP → PSP → NTH → PSP → TPAP
Routing: Based on VPA resolution
Settlement: Real-time gross settlement
2. IMPS Transactions
Flow: Remitter Bank → NTH → Beneficiary Bank
Routing: Based on IFSC code and account number
Settlement: Immediate settlement
Transaction Flow Architecture
Kafka Integration
Message Patterns
The NTH processes various Kafka topics for different transaction types:
Producer Topics
nth.transactions.processednth.settlements.initiatednth.routing.decisionsnth.system.events
Consumer Topics
bank.*.transactions.outboundbank.*.transactions.statustpap.*.payment.requests
Event Processing
Routing Engine
Bank Registry
The NTH maintains a registry of all participating banks:
Routing Logic
VPA-based Routing (UPI)
Parse VPA to extract bank identifier
Lookup bank service from registry
Route transaction to appropriate PSP
Handle response and settlement
IFSC-based Routing (IMPS)
Extract bank code from IFSC
Validate account details
Route to destination bank
Process settlement
Settlement Engine
Settlement Process
Transaction Aggregation: Collect completed transactions
Net Settlement Calculation: Calculate net positions between banks
Settlement Instruction: Generate settlement instructions
Confirmation: Confirm settlement completion
Settlement Types
Real-time: Individual transaction settlement
Batch: Periodic batch settlement
Net Settlement: Net position settlement between banks
Redis Usage
Caching Strategy
Transaction Cache: Active transaction status
Routing Cache: Bank routing information
Rate Limiting: Transaction rate limiting per bank
Session Management: Temporary transaction data
Cache Keys Pattern
API Endpoints
Health Check
Response:
Transaction Status
Response:
Bank Registry
Response:
Message Processing Architecture
Event-Driven Processing
The NTH operates on an event-driven architecture using Kafka:
Message Schemas
Transaction Request Schema
Error Handling & Resilience
Circuit Breaker Pattern
The NTH implements circuit breakers for bank integrations:
Retry Mechanism
Failed transactions are retried with exponential backoff:
Error Response Format
Performance & Scalability
Throughput Optimization
Async Processing: Non-blocking I/O for high throughput
Connection Pooling: Efficient resource utilization
Message Batching: Batch processing for high-volume transactions
Load Balancing: Horizontal scaling capabilities
Caching Strategy
Hot Cache: Frequently accessed routing information
Write-Through: Transaction status updates
TTL Management: Time-based cache expiration
Monitoring & Observability
Key Metrics
Transaction Volume: TPS (Transactions Per Second)
Success Rate: Transaction success percentage
Latency: Average/P95/P99 response times
Error Rate: Failed transaction percentage
Logging
Structured logging for transaction traceability:
Health Checks
Comprehensive health monitoring:
Development Setup
Local Development
Clone and navigate to NTH directory:
Install dependencies:
Set up environment variables:
Start dependencies (Kafka, Redis):
Run seed data:
Start development server:
Docker Development
Start NTH service with dependencies:
View real-time logs:
Testing
Test Categories
Mock Services
For testing, mock bank services are available:
Security
Transaction Security
Message Signing: Cryptographic message signing
Replay Protection: Nonce-based replay attack prevention
Input Validation: Strict input sanitization
Rate Limiting: Per-bank transaction rate limits
Network Security
TLS Encryption: All inter-service communication encrypted
Network Isolation: Docker network segmentation
Access Control: Service-to-service authentication
Compliance & Auditing
Transaction Audit Trail
Complete transaction logging for compliance:
Regulatory Compliance
Transaction Reporting: Automated regulatory reporting
Data Retention: Configurable data retention policies
Privacy Protection: PII data handling compliance
Deployment
Production Deployment
Kubernetes Deployment
Configuration Management
Environment-based Configuration
Feature Flags
Dynamic feature toggling:
Last updated

