Introduction

Conceptual

This document outlines the technical specifications and implementation plan for the NFM Payment Gateway. It aims to refactor and modernize the existing system concepts (from v2/v3 specifications) into a scalable, secure, and cost-effective microservices architecture leveraging a serverless-first approach on Google Cloud Platform (GCP). The system will handle recharge and payout transactions, manage users (House, Agents), devices, and provide comprehensive reporting.

The decision that the stakeholder have to make is to choose between the two options for the payment gateway.


Technology

To achieve a balance of development efficiency, scalability, cost-effectiveness, and low operational overhead, the following technology stack has been selected:

Frontend (Admin & Agent Platforms):

  • Framework: Next.js (React)
  • Styling: Tailwind CSS (utilizing pre-bought Tailwind UI Kit & Templates, and Catalyst for UI components)
  • Data Grids: AG-Grid
  • Deployment: Google Cloud Run (for SSR capabilities and consistent deployment)
  • Backend Microservices:
    • Language/Runtime: Node.js with TypeScript
    • Framework: Express.js (lightweight, excellent for serverless functions and APIs)
    • Deployment: Google Cloud Functions (for event-driven, simpler services) & Google Cloud Run (for more complex services or those needing longer execution/specific environments)
  • Database:
    • Primary Relational Store: Google Cloud SQL for PostgreSQL or AlloyDB
    • ORM (for Platform APIs): Prisma ORM
    • NoSQL Document Store (Specific Uses): Google Firestore (e.g., real-time device status, ephemeral data)
  • API Gateway: Google Cloud API Gateway
  • Messaging/Event Bus: Google Cloud Pub/Sub
  • Infrastructure as Code (IaC): Terraform
  • Caching: Google Cloud Memorystore for Redis (for API response caching, session data, etc.)
  • Monitoring & Logging: Google Cloud Operations Suite (Logging, Monitoring, Trace)
  • Authentication (UI Users): Firebase Authentication (integrates well with Next.js and serverless backends)
  • Authentication (API/Device): API Keys + JWT/Signed Tokens (managed by a dedicated auth logic within services or API Gateway)

This stack leverages TypeScript across frontend and backend for consistency, chooses widely adopted and well-supported serverless technologies on GCP, and utilizes Prisma ORM for efficient database interaction.


System Architecture

The NFM Payment Gateway will be a distributed system composed of decoupled microservices. Each service will have a specific responsibility, communicating via well-defined APIs (synchronously through an API Gateway) or asynchronously via an event bus (Cloud Pub/Sub).

High-Level Overview

System Context

The system interacts with several key actors:

  • House Administrators
  • Agents
  • Payment Devices
  • External Banking Systems

Available Solutions

1. Enterprise Microservices Architecture

A comprehensive, enterprise-grade implementation using Google Cloud Platform's managed services.

Features & Benefits

  • Full microservices architecture
  • Robust scalability
  • Comprehensive monitoring
  • Advanced deployment pipeline
  • Detailed technical documentation

2. Firebase Lightweight Solution

A simpler, cost-optimized implementation using Firebase and Firestore.

Features & Benefits

  • Full microservices architect
  • Zero infrastructure management
  • 78% cost reduction
  • Simplified development
  • Automatic scaling
  • Rapid implementation

Enterprise Architecture

Learn more about our Enterprise Microservices Architecture

Firebase & Firestore

Learn more how the Firebase solution works.

Compare Technical Solutions


Core Components

  1. Frontend Applications

    • Management Platform
    • Device Management
  2. Backend Services

    • User & Agent Management
    • Transaction Processing
    • Device Communication
    • Device Transaction Feed
    • Reporting System
  3. Data Storage

    • Transaction Records
    • User Profiles
    • Device Information
    • Audit Logs

Payout Automation Strategy

Both technical solutions support two approaches for payout automation:

1. Macro-based Automation (4-7 weeks)

  • Screen-based automation
  • Proven reliability
  • Lower complexity
  • Faster implementation

2. App Interception (8-12 weeks)

  • API-based automation
  • Better performance
  • Enhanced security
  • More flexible control

Learn more about Payout Automation


Implementation Timeline

Enterprise Solution

Phase 0: Setup              2-3 weeks
Phase 1: Core Services      3-4 weeks
Phase 2: Transaction Flow   4-6 weeks
Phase 3: Payout System     4-5 weeks
Phase 4: Reporting         3-4 weeks
Phase 5: Testing & Launch  3-4 weeks
Total:                    19-26 weeks

Firebase Solution

Phase 1: Core Features     4-5 weeks
Phase 2: Payout System     3-4 weeks
Phase 3: Enhanced Features 3-4 weeks
Total:                    10-13 weeks

Cost Comparison

Current System (Monthly)

Cloud SQL:          ฿10,384.86
Compute Engine:     ฿6,600.43
Total:             ฿16,985.29

Firebase Solution (Monthly)

Firebase Hosting:  ฿1,010
Firestore:         ฿1,200
Clerk:             ฿0 - ฿925
Total:             ฿2,210 - ฿3,135

Decision Factors

Consider these key factors when choosing a solution:

  1. Budget Constraints

    • Enterprise: Higher cost, more features
    • Firebase: Significant cost savings
  2. Timeline Requirements

    • Enterprise: 19-26 weeks
    • Firebase: 10-13 weeks or less
  3. Technical Expertise

    • Enterprise: Requires DevOps expertise
    • Firebase: Simpler operational needs
  4. Scalability Needs

    • Enterprise: Unlimited scaling
    • Firebase: Automatic scaling within limits