A high-performance, modular backend architecture simulating an e-commerce checkout, payment processing, and internal wallet ledger system. Built with Node.js, gRPC, Protocol Buffers, PostgreSQL, Redis, and containerized with Docker & Docker Compose.
This project showcases a clean microservices architecture designed to handle high-concurrency order checkouts and wallet transactions with strict transactional integrity, idempotency, and low-latency RPC inter-service communication.
- Binary gRPC Communication: High-throughput, type-safe RPC calls using Protocol Buffers (
.proto) between services. - REST / HTTP API Gateway: Translates external client requests into internal binary gRPC calls.
- Transactional Double-Entry Wallet Ledger: ACID-compliant balance updates using PostgreSQL row-level locks (
SELECT ... FOR UPDATE). - Distributed Idempotency: Redis-backed idempotency layer preventing duplicate charges during network retries.
- Containerized Environment: Fully orchestrated multi-container setup via Docker Compose.
- Automated Testing & Benchmarking: Unit/integration tests with Jest and load/stress testing with k6.
βββββββββββββββββββββββββββ
β Client / Postman / UI β
ββββββββββββββ¬βββββββββββββ
β HTTP / REST (JSON)
βΌ
βββββββββββββββββββββββββββ
β API Gateway β
β (Express / Fastify) β
ββββββββ¬βββββββββββββ¬ββββββ
β β
gRPC (Protobuf) β β gRPC (Protobuf)
βΌ βΌ
ββββββββββββββββββββ ββββββββββββββββββββ
β Order Service βββββββββΊβ Payment Service β
β β gRPC β β
ββββββββββ¬ββββββββββ ββββββββββ¬ββββββββββ
β β
β β gRPC
β βΌ
β ββββββββββββββββββββ
β β Wallet Service β
β β (Ledger Engine) β
β ββββββββββ¬ββββββββββ
β β
βΌ βΌ
ββββββββββββββββββββ ββββββββββββββββββββ
β PostgreSQL β β PostgreSQL β
β (Orders DB) β β (Wallet DB) β
ββββββββββββββββββββ ββββββββββ¬ββββββββββ
β
βΌ
ββββββββββββββββββββ
β Redis (Locks / β
β Idempotency) β
ββββββββββββββββββββ
βββ TrendyPay/
βββ docker-compose.yml # Local multi-service orchestration
βββ .env # Global environment template
βββ README.md # Project documentation
β
βββ proto/ # Shared Protocol Buffer definitions
β βββ order.proto # Order service contracts
β βββ payment.proto # Payment processing contracts
β βββ wallet.proto # Wallet & ledger contracts
β
βββ services/
β βββ api-gateway/ # Public-facing REST Gateway
β β βββ Dockerfile
β β βββ package.json
β β βββ src/
β β β βββ clients/ # gRPC client stubs (Order, Payment, Wallet)
β β β βββ controllers/ # HTTP route controllers
β β β βββ routes/ # REST endpoints (/orders, /wallet, /checkout)
β β β βββ middlewares/ # Auth, error mapper, validation
β β β βββ server.js
β β βββ tests/
β β βββ gateway.test.js
β β
β βββ order-service/ # Order lifecycle & state machine
β β βββ Dockerfile
β β βββ package.json
β β βββ src/
β β β βββ config/ # DB & gRPC server config
β β β βββ db/ # Migrations, seeds & queries
β β β βββ handlers/ # gRPC method implementations
β β β βββ services/ # Business logic (Order creation, state transitions)
β β β βββ index.js
β β βββ tests/
β β βββ order.test.js
β β
β βββ payment-service/ # Payment gateway & router
β β βββ Dockerfile
β β βββ package.json
β β βββ src/
β β β βββ config/
β β β βββ handlers/ # gRPC payment handlers
β β β βββ providers/ # Wallet provider, mock 3rd-party provider
β β β βββ services/ # Idempotency checks & charge logic
β β β βββ index.js
β β βββ tests/
β β βββ payment.test.js
β β
β βββ wallet-service/ # Ledger & atomic balance engine
β βββ Dockerfile
β βββ package.json
β βββ src/
β β βββ config/
β β βββ db/ # Ledger tables & migrations
β β βββ handlers/ # gRPC balance & debit/credit handlers
β β βββ services/ # Atomic balance deduction with row locks
β β βββ index.js
β βββ tests/
β βββ wallet.test.js
β
βββ tests/ # Root integration & E2E tests
β βββ e2e/
β β βββ checkout-flow.test.js # End-to-end checkout & balance verification (Jest)
β βββ load/ # Performance testing with k6
β βββ checkout-load.js # High-concurrency checkout stress test
β βββ wallet-contention.js # Concurrent debit test on single wallet
| Component | Technology | Purpose |
|---|---|---|
| Runtime | Node.js (LTS) | Fast, asynchronous event-driven I/O |
| Inter-Service Protocol | gRPC + Protobuf | Low-latency binary serialization and strict API contracts |
| API Gateway | Express | HTTP/REST endpoints for client applications |
| Primary Databases | PostgreSQL | ACID-compliant relational storage for orders and ledger entries |
| Cache & Locks | Redis | Fast distributed lock acquisition & idempotency key caching |
| Containerization | Docker & Docker Compose | Isolated, reproducible development and execution environments |
| Unit & E2E Testing | Jest | Unit tests, mock stubs, and end-to-end assertions |
| Load Testing | k6 (Grafana) | Concurrency benchmarks, latency monitoring, and stress testing |
- Docker & Docker Compose installed.
- Node.js (v20+) (optional for local development outside containers).
- k6 (optional for running load tests).
git clone https://github.com/your-username/payment-microservices.git
cd payment-microservices
# Copy global environment variables
cp .env.example .envRun the entire platform (Databases, Redis, gRPC microservices, and API Gateway) with a single command:
docker compose up --build -dCheck the status of running containers:
docker compose ps| Method | Endpoint | Description |
|---|---|---|
POST |
/api/v1/orders |
Creates a new pending order |
POST |
/api/v1/orders/:id/checkout |
Processes checkout payment for an order |
GET |
/api/v1/wallet/balance?userId=... |
Retrieves user's current simulated wallet balance |
POST |
/api/v1/wallet/topup |
Adds funds to the user's wallet |
Tests run across all microservices via native ECMAScript Modules (ESM) using pnpm workspaces:
# Run unit tests across all workspace microservices
pnpm test
# Run all test suites with Istanbul code coverage reports
pnpm test:cov
# Run End-to-End checkout scenario test
pnpm run test:e2eSimulate thousands of concurrent checkout operations to verify transactional locks and idempotency behavior:
# Run checkout load test (50 Virtual Users over 30s)
k6 run tests/load/checkout-load.js
# Test wallet concurrency & prevent race conditions
k6 run tests/load/wallet-contention.jsβ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
β ------------------|---------|----------|---------|---------|-------------------
β All files | 100 | 64.28 | 100 | 100 |
β walletHandler.js | 100 | 64.28 | 100 | 100 | 7-48
β ------------------|---------|----------|---------|---------|-------------------
β Test Suites: 1 passed, 1 total
β Tests: 8 passed, 8 total
β Snapshots: 0 total
β Time: 0.685 s, estimated 1 s
β Ran all test suites.
ββ Done in 971msThe TrendyPay microservices architecture has been rigorously benchmarked using k6 to ensure stability, high availability, and strict ACID compliance under heavy concurrent load.
This test simulates sustained traffic spikes across the entire microservices ecosystem. It verifies that the API Gateway can seamlessly route payloads to the Order, Wallet, and Payment gRPC services without dropping connections or failing transactions.
Execution Command:
k6 run tests/checkout-load.js
Results & Metrics:
- Success Rate: 100% (0 failed HTTP requests out of 2,436 total requests)
- Throughput: 812 Iterations (Successfully completed the full 3-step checkout flow 812 times)
- Concurrency: 50 VUs (Handled 50 simultaneous virtual users over a 35-second ramped load)
- Response Time (p95): 155.57ms (95% of all requests completed in under 156 milliseconds)
- Check Validations: 100% Pass (Verified 201/200 status codes for Order Creation, Wallet Top-up, and Checkout)
This test aggressively hammers a single wallet account with simultaneous top-up requests to validate the PostgreSQL connection pooling and row-level locking (SELECT ... FOR UPDATE). It ensures that race conditions cannot overwrite data and that wallet balances maintain strict mathematical integrity under extreme contention.
Execution Command:
k6 run tests/wallet-contention.js
Results & Metrics:
- Transaction Integrity: Pass (Final balance accurately reflected all concurrent transactions without data loss)
- Success Rate: 100% (Zero
500 Internal Server Errorcrashes; pool efficiently queued all connections) - Concurrency: 20 VUs (Executed 40 rapid, shared iterations simultaneously against a single database row)
- Response Time (p95): 185.63ms (Maintained sub-200ms latency even while resolving database lock queues)
- Check Validations: 100% Pass (Verified clean 200/201 HTTP status codes for all rapid concurrent requests)