Skip to content

Case study 01 · Multi-tenant SaaS

Merchant Management System

A platform where payment providers onboard merchants, run KYB checks, take card payments and settle with merchants.

My role
Architect and developer (settlement, KYB, payments)
Team
4 engineers
Timeline
1 year, first commit to production
Status
In production
Client
fintech companies in Egypt
Stack
Laravel · Vue.js · PostgreSQL · Stancl Tenancy · Reverb · Docker · CyberSource · MPGS

The problem

Payment providers had no dashboard to manage their merchants. Onboarding and KYB checks, following payment transactions and settling with merchants all needed one place, and each provider's data had to stay separate from the others'.

The solution

A multi-tenant platform built from scratch. Each provider gets its own isolated database; the provider's team and its merchants both work in it.

  • KYB onboarding: draft, submit, review, approve or reject, with revision history and real-time collaboration.
  • Card payments: CyberSource and MPGS, plus a hosted payment page with checkout, payment links and invoicing.
  • Settlement: automatic and manual cycles, fee profiles, transaction splitting, bank accounts and multi-step approvals.
  • Security: OAuth2 scoped tokens, TOTP MFA with recovery codes, role-based access and audit logs.

The hardest problem

The settlement engine had to handle four things at once, and every amount had to be right:

  • each merchant can have its own fee rules (MDR profiles);
  • one transaction can be split between several parties;
  • automatic and manual settlement cycles run side by side;
  • generation must stay fast as transactions grow.

Correctness is protected by reconciling settlements against the underlying transactions, with unit and feature tests around the calculations.

My contribution

I designed the architecture and the database, and built the settlement engine, the KYB approval workflow and the CyberSource and MPGS integrations, in a team of four.

Architecture

Architecture: admins, merchants and customers use a Vue 3 app over a Laravel API; partner systems use an external API. The API calls CyberSource and MPGS, pushes live updates through Reverb, and uses a central database, tenant databases and Redis.
One Laravel API serves the admin and merchant portals, the hosted payment page and partner systems. Queue workers and a scheduler handle webhooks, exports and settlement.
Multi-tenancy: each request finds its tenant by header, URL or explicit setup, then Stancl Tenancy switches to that account's database. Central holds admins, KYB, fee templates and settlements; each tenant holds merchants, payments and transactions.
Each business account's merchants, payments and transactions live in its own database. Platform-wide data stays central, and links between the two are kept by ID.
KYB lifecycle: draft, submitted, checked, then approved or rejected. A submitted or checked application can be sent back for revision and returns to draft. Approval takes the merchant live.
Every status change is locked per application, and whoever submitted or edited an application cannot check, approve or reject it.
Payment to payout: payment request, checkout with the merchant's fee, card gateway, then the paid amount is split. A daily job adds splits to draft settlements, which move to ready, approved, processing and completed.
Fees and splits are worked out per merchant at payment time. Settlements are built from those splits, and an admin approves each one before payout.

Key decisions

Decision Why
A database per tenant (Stancl Tenancy) Each provider's data stays fully separate
Denormalised settlement data and composite indexes Settlement generation was the slow path
Real-time KYB review over WebSockets Reviewers and merchants see each revision as it happens

Results

In production companies in Egypt
Time to production 1 year · team of 4
Settlement generation 1,368 ms → 15 ms (91×)

Measured on a 1 GB synthetic transaction dataset, after a schema redesign, denormalisation and composite indexes.

Client details are confidential, so the client is described rather than named and no client screens are shown.

This project and its code are © MIMOCODES · All rights reserved.