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

  1. Transaction Routing: Routes payments between different PSP banks

  2. Settlement Coordination: Manages inter-bank settlement processes

  3. Message Processing: Handles Kafka-based event processing

  4. Switch Logic: Implements payment switch logic for different transaction types

  5. 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.processed

  • nth.settlements.initiated

  • nth.routing.decisions

  • nth.system.events

Consumer Topics

  • bank.*.transactions.outbound

  • bank.*.transactions.status

  • tpap.*.payment.requests

Event Processing

Routing Engine

Bank Registry

The NTH maintains a registry of all participating banks:

Routing Logic

VPA-based Routing (UPI)

  1. Parse VPA to extract bank identifier

  2. Lookup bank service from registry

  3. Route transaction to appropriate PSP

  4. Handle response and settlement

IFSC-based Routing (IMPS)

  1. Extract bank code from IFSC

  2. Validate account details

  3. Route to destination bank

  4. Process settlement

Settlement Engine

Settlement Process

  1. Transaction Aggregation: Collect completed transactions

  2. Net Settlement Calculation: Calculate net positions between banks

  3. Settlement Instruction: Generate settlement instructions

  4. 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

  1. Clone and navigate to NTH directory:

  1. Install dependencies:

  1. Set up environment variables:

  1. Start dependencies (Kafka, Redis):

  1. Run seed data:

  1. 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