📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📰 Building a Cross-Border Remittance System for Bhutan National Bank

Building a Cross-Border Remittance System for Bhutan National Bank

Building a Cross-Border Remittance System for Bhutan National Bank

Most of the software I've written is invisible to the people who use it. Remittance is different. Behind every transfer is a person in one country sending money to someone in another, and they care about two things: that it arrives, and that it's safe on the way.

From February 2023 to May 2024 I was a Senior .NET Developer at Fintech Solutions in Kathmandu. There I led the development of two remittance products: iSend Remit, our own in-house product, and BNB Remit, which we built for Bhutan National Bank. I've already written about one narrow slice of that work, signing and encrypting payment payloads in C#. This post steps back and looks at BNB Remit as a case study: what it had to do, how the pieces fit together, and what I learned.

A quick note before I start. I can't share client code or internal details, so the code samples here are generic examples written for this post, not code from the project. Where I describe the product, I'm using what Bhutan National Bank publishes about it.

The problem

BNB Remit is Bhutan National Bank's mobile and web app for person-to-person money transfers from Australia to Bhutan. The bank runs it with Transcash International, an Australian company licensed as iPay Remit. Money is deposited directly into the receiver's account at BNB or at another bank in Bhutan.

According to the public BNB Remit page, the app today covers:

  • registration with a phone number, and sign-in with a phone number or email
  • KYC and email verification
  • adding and managing beneficiaries
  • checking the exchange rate before sending
  • payout straight into a bank account in Bhutan

For a customer, that's a short, simple list. For the people building it, every item touches something sensitive: identity checks, bank account details, exchange rates that change, and money that has to land in exactly one place, exactly once.

The way I describe this work on my portfolio is "a B2B fintech solution for remittance, SaaS and secure cross-border payments". The B2B part matters. We weren't only building an app for end users. We were building a system that a bank and its partners had to trust.

BNB Remit launched in March 2024 for Bhutanese living in Australia, as reported by BBS. Work on it started about a year earlier, around March 2023, shortly after I moved into the senior role at Fintech Solutions.

The brief was simple to say and hard to build: the bank needed a cross-border payment system, so that money sent from abroad could reach accounts in Bhutan. They chose Fintech Solutions for two reasons: the company's reputation in remittance, and how fast it could move money from one country to another.

My role

I led the development team. Alongside leading, I built the API integration with the bank myself. My main job there was to fetch transactions from the pool, filter out the ones meant for BNB, and send them to the bank's API over a secure, encrypted connection.

The stack at a glance

The main building blocks were:

Area What we used
APIs ASP.NET Core
Moving money Payment APIs
Processing AWS Lambda and a serverless architecture
Storage Amazon S3
Keys and secrets AWS Secrets Manager
Transaction security Symmetric and asymmetric encryption, digital signatures
Releases CI/CD pipelines with GitHub Actions

At a high level, a transfer moved through the system like this:

  1. A customer sends money, in most cases from Australia.
  2. The transaction arrives in the pool accounts.
  3. From that pool, a filter picks out only the transactions going to Bhutan.
  4. Those transactions are sent to Bhutan National Bank through a secured, encrypted API.
  5. The bank pays the money into the receiver's account.

Rather than walk through every component, I'll focus on the decisions that shaped the system, and what each one taught me.

Lesson 1: Design for "exactly once"

In most apps, if a request is sent twice, the worst case is a duplicate row. In remittance, a duplicate request can mean sending someone's money twice. Mobile networks drop, users tap the button again, and clients retry on timeouts. The system has to assume any request might arrive more than once.

The standard answer is idempotency: the client sends a unique key with each transfer, and the server remembers which keys it has already handled. Here's a generic example of the idea in ASP.NET Core.

// Example only: an idempotent "create transfer" endpoint.
[HttpPost("api/transfers")]
public async Task<IActionResult> CreateTransfer(
    [FromHeader(Name = "Idempotency-Key")] Guid idempotencyKey,
    CreateTransferRequest request,
    CancellationToken ct)
{
    // Seen this key before? Return the original result instead of sending money again.
    var existing = await _db.Transfers
        .AsNoTracking()
        .FirstOrDefaultAsync(t => t.IdempotencyKey == idempotencyKey, ct);

    if (existing is not null)
        return Ok(TransferDto.From(existing));

    var transfer = Transfer.Create(idempotencyKey, request.BeneficiaryId, request.Amount, request.Currency);
    _db.Transfers.Add(transfer);

    try
    {
        await _db.SaveChangesAsync(ct); // a unique index on IdempotencyKey backs this up
    }
    catch (DbUpdateException)
    {
        // Two identical requests raced each other and the unique index stopped the second one.
        _db.ChangeTracker.Clear();
        var winner = await _db.Transfers
            .AsNoTracking()
            .FirstOrDefaultAsync(t => t.IdempotencyKey == idempotencyKey, ct);

        if (winner is null) throw;
        return Ok(TransferDto.From(winner));
    }

    return CreatedAtAction(nameof(GetTransfer), new { id = transfer.Id }, TransferDto.From(transfer));
}

Two details make this work. First, the check in code isn't enough on its own: two requests can arrive at the same moment, both see "no existing transfer", and both try to insert. The unique index in the database is what really guarantees one transfer per key. Second, the same idea has to carry on downstream. If a payment partner supports its own idempotency or reference ids, pass a stable one through, so a retry on your side doesn't become a second payment on theirs.

Lesson 2: Trust nothing until it's verified

A remittance system talks to a lot of parties: the mobile and web app, the bank, payment partners and other services. Every one of those connections is a place where a message could be read, changed or faked.

On the remit projects we secured transactions with symmetric and asymmetric encryption and digital signatures. I covered the details in the signing and encrypting post, but the short version is:

  • Encryption keeps the payload private. Signatures prove it wasn't changed and who sent it. You need both.
  • Sign the exact bytes that go on the wire, not an object you serialise again later.
  • Verify first, then process. Never act on a message and check it afterwards.
  • Fail loudly. If verification fails, reject the message and alert someone. No silent fallbacks.

Most of the hard problems weren't the algorithms. They were agreeing on formats and rules with the other side, and writing code that refuses to carry on when something doesn't check out.

The bank applied the same rule to us

The bank lived by this rule too, and I saw it first-hand when we needed their sandbox. We couldn't reach it directly. The bank allowed access from only one IP address at our company, and even that wasn't a direct door. From that address we connected to a remote desktop, and from inside it to a second remote desktop, which was where the sandbox had been set up for us.

It was slow to work with, but it showed me how a bank handles security: nobody is trusted by default, including the vendor building its software.

SOAP, not JSON

The integration detail that took the most effort was the API style. The bank's transaction services were SOAP, which is common in banking, where core systems are long-lived and hard to change. Our team worked with JSON every day, and SOAP is not as easy. If you don't have experience with it, the schemas alone take real time to get right.

We had the bank's API documentation, but the documents and the real behaviour didn't always match, so we had to find the differences ourselves. Account verification was one example: the response carried a lot more than we needed, and we had to pick out our own data from it and leave the rest.

Our answer was an abstraction layer that converted SOAP to JSON. The rest of the system kept working with JSON, and only one small part had to know SOAP existed.

The mistake: skipping tests

One more honest lesson from this integration. We wrote the code, we were sure it was correct, and we thought it didn't need testing. That was a blunder. Never think that way. Always test, and never trust your own code without tests, even if you have 15 years of experience.

Lesson 3: Secrets live outside the code

A payment system has a lot of secrets: signing keys, encryption keys, API credentials for partners, database passwords. On these projects we used AWS Secrets Manager, so keys and credentials were loaded at runtime instead of sitting in appsettings.json or a Git repo.

The rule I took away is simple: configuration can hold the name of a secret, never the secret itself. That one habit makes rotation possible, keeps keys out of source control, and lets you control exactly which service can read which secret. I'll go deeper on this in a future post about Secrets Manager in .NET.

Lesson 4: Serverless for the right jobs

We used AWS Lambda and a serverless architecture alongside the ASP.NET Core APIs, with S3 for storage. Serverless is a good fit for work that is event-driven or comes in bursts: something happens, a function runs, and you don't pay for an idle server in between.

It also brings its own rules. The big one for payments is that a function can run more than once for the same event. For example, when Lambda is invoked asynchronously and the function fails, AWS retries it. So lesson 1 applies here too: every handler must be safe to run twice.

Here's a generic example of a function that runs when a file lands in S3:

// Example only: a Lambda function triggered by an S3 upload.
using Amazon.Lambda.Core;
using Amazon.Lambda.S3Events;

public class Function
{
    public async Task Handler(S3Event s3Event, ILambdaContext context)
    {
        foreach (var record in s3Event.Records)
        {
            var bucket = record.S3.Bucket.Name;
            var key = record.S3.Object.Key;

            // Log what happened, never the contents of the file.
            context.Logger.LogInformation($"Processing object {key} from {bucket}");

            // Lambda may retry a failed event, so this must be safe to run twice.
            await ProcessIfNotAlreadyDoneAsync(bucket, key);
        }
    }
}

Other things worth planning for: cold starts on functions that sit on a user-facing path, timeouts on anything that calls a slow external API, and logging that never includes customer data.

On our side, the payment filtering I built ran on Lambda, and it was the part of the design I liked best. Each function runs separately, so one doesn't disturb another. And we could choose the compute for each function on its own, so every one was sized for the job it does.

Lesson 5: One platform, more than one client

Fintech Solutions had its own remittance product, iSend Remit, and we built BNB Remit for a bank. Work like this pushes you to think about what is the same for every client and what is specific to one.

Whatever the codebase looks like, partner-specific things like currencies, partner endpoints and key names belong in configuration, not in if (partner == "...") checks scattered through the code. A generic example:

// Example only: partner-specific settings in configuration, validated at startup.
public sealed class RemitPartnerOptions
{
    public string PartnerCode { get; init; } = "";
    public string SendCurrency { get; init; } = "";        // e.g. "AUD"
    public string ReceiveCurrency { get; init; } = "";     // e.g. "BTN"
    public Uri? PayoutApiBaseUrl { get; init; }
    public string SigningKeySecretName { get; init; } = ""; // a name in the secret store, never the key
}

builder.Services
    .AddOptions<RemitPartnerOptions>()
    .BindConfiguration("RemitPartner")
    .Validate(o => o.SendCurrency.Length == 3 && o.ReceiveCurrency.Length == 3,
        "Currency codes must be three-letter ISO codes.")
    .Validate(o => o.PayoutApiBaseUrl is not null, "PayoutApiBaseUrl is required.")
    .ValidateOnStart();

ValidateOnStart is the important line. If a setting is missing or wrong, the app refuses to start, instead of failing on the first real transfer.

We learned this one the hard way. iSend Remit was the in-house product, and Bhutan National Bank was its first client. There was no plan to white-label the software at the beginning. Once the bank came on board, iSend Remit was reworked so it could run for any company under its own brand.

Making the app dynamic took our team most of the project's time. That's when it became clear to me: build software so it can be white-labelled easily. Don't hard-code anything. It has to be dynamic.

Lesson 6: Automate the release path

We implemented CI/CD pipelines with GitHub Actions. In a payments system, a manual deployment is a risk in itself: a missed step or a wrong config file on a live system that moves money is a bad day for everyone. A pipeline makes every release the same, every time, and gives you a record of what went out and when.

I use the same approach on my own apps today, which I wrote about in From Manual Deployments to GitHub Actions.

On this project the pipeline covered the usual path: build the app, test it, deploy it.

The release at the bank was a different story, and it was not easy. The bank did not allow the app to be deployed remotely. For security, it had to be done on site, so our project manager and DevOps travelled to Bhutan and deployed the whole app from there.

What I'd do differently

If I built BNB Remit again today, the biggest difference would be AI. We built it without the AI coding tools I use now. In the AI era, the same project would go much faster.

I'd also carry two lessons from above into day one: test everything, however sure I am of the code, and design for white-labelling from the start instead of adding it later.

What this project taught me

  • Money must move exactly once. Idempotency isn't an extra. It's part of the design from day one, backed by the database.
  • Security is a contract. Encryption and signatures only work when both sides agree on every detail, in writing.
  • Always test. However experienced you are, code isn't correct until it's tested.
  • Keys belong in a secret store. Config holds names, not secrets.
  • Serverless is a tool, not a default. Use it for event-driven work, and make every handler safe to retry.
  • Configuration beats branching. Partner differences go in validated settings, not scattered if statements.
  • Automate releases. On a system that moves money, the boring, repeatable path is the safe one.

Final thoughts

Remittance looks simple from the outside: pick a beneficiary, enter an amount, press send. Building BNB Remit showed me how much has to go right behind that one button, from verifying every message to making sure a retry never becomes a second payment.

Those lessons now shape how I approach any .NET system that handles money or sensitive data, whatever the industry.

Have you worked on a payments or remittance system? What was the hardest part to get right? Tell me in the comments.

X / Twitter LinkedIn

Comments (0)

No comments yet. Be the first!

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me