Cross-border remittance platforms operate across networks where mobile connectivity drops, payment webhooks arrive out of order, and exchange rates move between quote generation and settlement. Building corridor workflows between Russia (RUB) and Central Africa (XAF / FCFA) requires treating every external call as retryable and every ledger write as append-only.
1. Quote Locking with Expiring FX Windows
Never compute an exchange payout amount on the fly during settlement. Separate quote creation from transfer execution so both the sender and the compliance ledger agree on the exact rate, fee, and payout figure before funds move.
interface FxQuote {
id: string;
sourceCurrency: "RUB";
targetCurrency: "XAF";
sourceAmountMinor: bigint;
payoutAmountMinor: bigint;
appliedRate: string;
expiresAt: Date;
}
export function isQuoteValid(quote: FxQuote, now = new Date()): boolean {
return quote.expiresAt.getTime() > now.getTime();
}
Storing amounts in integer minor units avoids floating-point rounding drift across multi-currency conversions and fee splits.
2. Enforcing Tiered KYC Daily Limits Atomically
Regulatory limits—such as daily RUB send caps per verification tier—must be checked inside the same serializable database transaction that reserves the user's rolling 24-hour volume. Checking limits in application memory invites race conditions when a client retries two requests concurrently.
-- Sum rolling 24h outbound volume before inserting a pending transfer
SELECT COALESCE(SUM(source_amount_minor), 0) AS used_volume_minor
FROM transfers
WHERE sender_id = $1
AND status IN ('RESERVED', 'SETTLING', 'COMPLETED')
AND created_at >= NOW() - INTERVAL '24 hours'
FOR UPDATE;
3. Client Idempotency Keys on Initiation
Mobile clients over unstable connections frequently time out after the server has already accepted a transfer request. Requiring an Idempotency-Key header keyed to (sender_id, idempotency_key) guarantees that a retried tap returns the original transfer state rather than initiating a duplicate payout.
export async function initiateTransfer(
senderId: string,
idempotencyKey: string,
payload: TransferInput,
db: DatabaseClient
) {
const existing = await db.transfers.findByIdempotencyKey(
senderId,
idempotencyKey
);
if (existing) {
return existing;
}
return db.transaction(async (tx) => {
await assertKycTierLimit(tx, senderId, payload.sourceAmountMinor);
return tx.transfers.create({
senderId,
idempotencyKey,
status: "RESERVED",
...payload,
});
});
}
4. Signed Webhook Reconciliation for Mobile Money Payouts
Disbursement providers such as MTN Mobile Money and Orange Money confirm final wallet delivery asynchronously. Webhook handlers should verify HMAC signatures against the raw request body, record the provider event ID in an inbox table, and transition the transfer state machine deterministically.
- Verify raw payload signatures before parsing JSON or touching business tables
- Deduplicate provider callbacks using a unique constraint on
provider_event_id - Keep terminal states immutable so a late
PENDINGwebhook never overwritesCOMPLETED
Summary
Reliable fintech backends come down to explicit state machines, integer ledger arithmetic, database-enforced idempotency, and defensive webhook verification rather than complex distributed frameworks.
