Skip to content
Mohamed Naser

Commodity Murabaha, Explained for Engineers

Before the story of scaling from ten orders to five thousand, here is what we actually run: what a commodity Murabaha is, why every step is legally load-bearing, and why stock has to exist as individually coded units.

Commodity Murabaha, Explained for Engineers
  • commodity murabaha
  • murabaha process
  • islamic finance
  • sharia compliant financing
  • murabaha platform
  • islamic banking technology
  • tawarruq
  • SPV
  • time deposit
  • special purpose entity
  • fintech saudi arabia
  • system design
SECTION 01

What LYNK is, and what we do

LYNK is a Saudi fintech platform that provides the infrastructure for commodity Murabaha financing. When a bank or finance company wants to extend Sharia-compliant financing to a customer โ€” a personal loan, an SME facility, a credit card settlement โ€” the funds cannot simply be lent at interest. Instead, the financing must be structured as a real trade: the institution buys a genuine commodity, sells it to the customer at cost plus an agreed profit (the Murabaha), and the customer sells it on for liquidity. LYNK is the marketplace and execution engine that makes that entire trade real, digital, and fast.

In practice, we operate three things:

  • A commodity marketplace. LYNK runs a local commodity market where approved suppliers list real inventory โ€” steel, gasoline, and other qualifying goods โ€” tracked down to the individual unit, with live availability and pricing. For institutions that prefer international commodities, LYNK also integrates directly with Bursa Malaysia's Suq Al-Sila' (BSAS) commodity trading platform.
  • An execution engine. Financial institutions create Murabaha orders through the LYNK portal or entirely through our API from their own loan-origination systems. Orders can run in manual mode, where an officer confirms each step, or in AUTO mode, where the whole cycle โ€” purchase, ownership transfer, sale, completion โ€” executes without human intervention.
  • The record of the trade. Every step produces its legal evidence: purchase confirmations, wakala (agency) agreements, ownership certificates, and sell confirmations, plus wallets, settlement, and SADAD invoicing around the money side.

One machine, many financial products

The same Murabaha machinery serves very different financial products. What changes between them is who the parties are and what the financing is for โ€” never the legal sequence of the trade itself:

ProductLenderBorrowerWhat it serves
Normal lending The financial institution The institution's customer Classic Murabaha: personal finance, SME facilities, credit-card settlement
SPV (Special Purpose Vehicle) An SPV โ€” a separate legal entity the institution creates to isolate financial risk The financial institution itself Structured finance: large or specialized Murabaha deals, ring-fenced from the institution
Time deposit A client placing funds with the institution for a fixed term The financial institution itself A Murabaha-based investment: the deposit earns profit through Murabaha โ€” the Sharia-compliant alternative to an interest-bearing term deposit
SPE (Special Purpose Entity) An external third party An external customer Murabaha execution as a service: the institution manages the entire transaction between two independent parties without being either party to the contract

Note what the table implies for the machinery. In normal lending the institution is the lender; in SPV and time-deposit orders the same Murabaha flow runs in reverse โ€” the institution becomes the borrower, commodity ownership starts under the external lender's name, and every certificate is issued accordingly. SPE then combines both: an external lender and an external customer, with the institution purely as transaction manager. Yet all four products run through the same pipeline, the same coded commodity units, and the same ownership ledger โ€” the ownership flow simply supports the institution being lender, borrower, or neither. One performance investment serves every product at once.

The products are also part of the scaling story. Before SPV and time deposit became first-class products, each such deal was executed through a workaround: manually registering a new company to represent the SPV or deposit client, order by order. That workaround at volume pushed the platform past 32,000 registered entities โ€” exactly the kind of scale event the rest of this series is about โ€” and turning these flows into proper financial products with a reversed ownership flow removed it.

Our clients are the financial institutions; their customers are the borrowers and depositors; the suppliers and traders provide the commodity side of the market; and LYNK administrators oversee the whole exchange. The platform's job is to let an institution turn "approve this financing" into a completed, fully documented, Sharia-valid trade โ€” in seconds.

SECTION 02

The Murabaha process โ€” and why every step must happen

A commodity Murabaha on LYNK is a sequence of real transactions, each with a distinct legal meaning. Nothing in this sequence is ceremonial; each step transfers actual ownership of actual commodity units, and each must complete before the next may begin.

Local market Financial Customer Open market / supplier inventory institution (borrower) Spec. Entity 1 ยท PURCHASE 2 ยท MURABAHA SALE 3 ยท SALE FOR CASH real units, held cost + profit, deferred via wakala, distinct buyer cash price instalments liquidity to customer commodity ownership payment
The Murabaha trade cycle: ownership of real commodity units moves market โ†’ institution โ†’ customer โ†’ market, with payment flowing back at each hop. Each transfer is a genuine sale evidenced by certificate โ€” and the sequence cannot be reordered.
  1. Order created & approved The institution submits the financing order โ€” amount, customer, market, commodity preferences. Depending on its roles setup, a supervisor approves it. A trade request is born.
  2. Purchasing Commodity The platform finds eligible commodity units on the market that cover the financing amount, places them on hold, and executes the purchase. The institution now genuinely owns specific, identified units of a real commodity. Sharia requires this ownership to be real โ€” you cannot sell what you do not own.
  3. Borrower Ownership The institution sells the commodity to the customer at cost plus the agreed profit, payable in instalments โ€” this sale is the Murabaha. Ownership of the units transfers to the customer, evidenced by certificate.
  4. Sale to market The customer โ€” typically through a wakala appointing the institution or platform as agent โ€” sells the commodity back to the open market for cash. This provides the liquidity the customer needed. The commodity must move to a genuinely different buyer, which is why trade-rotation rules and, in newer flows, a Specialized Entity govern who may buy it.
  5. Murabaha Completed & settlement Funds flow to the customer, certificates are finalized, the order completes, and the commodity units settle back into the market's books, ready to serve a future order.
LYNK's Murabaha Details screen showing all five steps completed with green checkmarks: Purchasing Commodity in 1 second with its commodity certificate, Contract Signed in 28 seconds confirmed via API by the lender, Borrower Ownership Certificate in 0 seconds with its certificate, Client Wakala in 0 seconds, and Murabaha Completed in 0 seconds with the sell confirmation certificate โ€” on 15 August 2026.
The process as users see it: a real order completing every legal step, with a downloadable certificate generated at each transfer of ownership. The platform's own steps are near-instant โ€” Purchasing Commodity in 1 second, Borrower Ownership, Client Wakala, and Murabaha Completed in 0 seconds each. The only wait, 28 seconds at Contract Signed, is the lender confirming through their own API โ€” the customer's time, not the machine's.

Stock is code โ€” and every code must be traceable to its owner

The deepest consequence of the legal structure sits in how stock exists at all. On LYNK, a supplier's registered stock is not a quantity in a column โ€” it is minted into individual units, each represented by its own unique code. Sharia requires the sale of identified, specified goods, not an abstract balance: when an institution buys "500 units of steel," it must be knowable which 500 units, and when the customer takes ownership, those exact coded units must now belong to that customer.

A busy commodity warehouse with tall racks of stock and workers moving pallets.
A commodity market is a real warehouse before it is a database. LYNK's job is to give every unit on those shelves a code, an owner, and a history.

So every unit lives as its own record carrying its code, its status (free or reserved), which order is holding it, who owns it now, and who owned it before. And every time ownership changes hands, the database itself โ€” via a trigger, so no code path can forget โ€” appends a row to an append-only ownership ledger. Pick any unit code, at any time, and the platform can replay its full legal history: supplier โ†’ institution โ†’ customer โ†’ market, order by order.

Supplier stock e.g. 500 units of steel minted one row per unit, each with a unique code UNIT 8FA3-72 status: FREE owner: Supplier S-014 UNIT 8FA3-72 status: RESERVED ยท hold_for #812 owner: Supplier S-014 UNIT 8FA3-72 status: FREE ยท settled owner: Customer C-1042 held owned every ownership change fires a DB triggerโ€ฆ OWNERSHIP LEDGER ยท APPEND-ONLY 8FA3-72 ยท Supplier S-014 โ†’ Institution L-001 ยท order #812 ยท purchase 8FA3-72 ยท Institution L-001 โ†’ Customer C-1042 ยท order #812 ยท murabaha sale 8FA3-72 ยท Customer C-1042 โ†’ Open market ยท order #812 ยท sale for cash any code, any time โ†’ full legal chain of ownership
Stock as code: supplier inventory is minted into individually coded units. Each unit tracks its status, the order holding it, and its current and previous owner โ€” and a database trigger appends every ownership change to an append-only ledger, so any unit's code replays its complete legal history.

This design is what makes the platform legally sound โ€” and it is also one of our hardest engineering challenges. A single financing order holds hundreds or thousands of units; five thousand concurrent orders means millions of unit rows being held, transferred, and settled at once, where two orders must never hold the same unit โ€” not even for a millisecond โ€” and where losing a single ledger entry would break a chain of ownership that has to stand up to audit. Much of the scaling story in Part 2 โ€” the lock contention, the index engineering, the race-condition hunts โ€” is really the story of keeping this per-unit, per-user tracking intact under industrial load.

The constraint we cannot optimize away Every performance engineer's instinct โ€” skip the step, batch the work, fake the intermediate state, reorder the sequence โ€” is forbidden here by design. The purchase must precede the sale. The units must be individually identified and genuinely held. The ownership chain must be complete and documented. A Murabaha with a shortcut in it is not a slow transaction; it is an invalid one. Sharia compliance is a hard correctness constraint, exactly like double-entry accounting โ€” so all throughput must come from architecture, never from relaxing the rules of the trade.
SECTION 03

The goals: what "a better platform" means for LYNK

Institutions do not create Murabaha orders one at a time. A consumer-finance company disburses hundreds of loans in a morning; a bank settles credit-card Murabaha in bursts; campaign days multiply everything. Our definition of a better platform therefore comes down to two primary goals, in tension with each other:

Goal 1 โ€” Maximize the number of transactions we can handle at one time

Every concurrent order competes for the same commodity inventory, the same database rows, and the same workers. Capacity is not one number but a system of targets we test against continuously:

TargetMeasureWhere we've proven it
Concurrent volume5,000+ orders per runRoutine daily pre-production stress tests; 5,200 end-to-end
Per-order speedsub-second stepsPurchase averages 0.26s, P99 within 1s โ€” see Section 04
Reliabilityโ‰ฅ 99.9% completion99.92โ€“100% across 2,500โ€“5,200-order campaigns
API responsiveness~1.2s create-orderMeasured while 5,000 orders flowed through the pipeline
Autonomyzero-touch runsFull AUTO cycle incl. Auto Complete Sell, unattended

Goal 2 โ€” Every transaction must be Islamically legal

The second goal bounds the first. Whatever the load, each of those thousands of orders must individually satisfy the full legal sequence: real units found, genuinely held, actually purchased, ownership truly transferred, sold onward to a legitimately distinct buyer, and every link evidenced by certificate. This has concrete engineering consequences:

  • Strict per-order sequencing. Each order's pipeline is a state machine whose steps cannot be skipped or reordered โ€” parallelism must come from running many orders side by side, never from cutting corners inside one.
  • Real inventory, really held. Units are locked and tracked individually; two orders may never "own" the same unit, even for a millisecond, which is why hold/lock logic and race-condition work dominate our database engineering.
  • Evidence as a deliverable. Certificates and ownership records are legal artifacts. We may move their generation off the critical path (produce the PDF at download time), but never remove them.
  • Rules even in the fast path. Trade-rotation limits and the Specialized Entity flow exist so the onward sale is genuinely valid. When we tested relaxing rotation from 2 to 1, the change was justified to the business on Sharia-structure grounds โ€” and only adopted after tests proved performance was unaffected either way.
#1 #2 #3 โ‹ฎ ร—5,000 CreatePurchaseOwnershipSellComplete CreatePurchaseOwnershipSellComplete CreatePurchaseOwnershipSellComplete holds units โ€” exclusively Shared commodity inventory โ€” each unit belongs to at most one order at a time
Where the two goals meet: throughput comes from running thousands of pipelines side by side, while Sharia validity forces every pipeline through the same strict sequence โ€” and all of them compete for exclusive holds on the same pool of real commodity units.
The thesis of this series A platform that is fast but cuts legal corners is worthless, and a platform that is compliant but handles ten orders is a prototype. LYNK's engineering story is the pursuit of both at once: industrial throughput for transactions whose every step is a genuine, documented, Sharia-valid trade.
SECTION 04

How we test our performance

Claims like "seconds per step" mean nothing without a way to prove them โ€” so performance testing is a standing routine, not an occasional event. Thousands of orders are created through the API in controlled pre-production runs (today's standard is 5,000 orders per run, daily), every order records how long each Murabaha step took, and each run is distilled into the same set of statistics per step. Every change to the platform is judged against that history: if the numbers move the wrong way, the change is caught within days.

A presenter pointing at a large bar chart on an easel.
Every test run ends the same way: someone pointing at a chart. The numbers below are what we point at.

How to read the numbers

The fairest way to describe thousands of order timings is to imagine lining every order up, fastest to slowest, and reading values off that line:

  • Min / Max โ€” the single fastest and single slowest order in the run. Max shows the worst thing that happened to anyone.
  • Avg (average) โ€” total time divided by number of orders. Useful, but it hides outliers: a thousand fast orders can bury ten terrible ones.
  • P25, P50, P75, P90, P95, P99 (percentiles) โ€” "P" followed by a number reads as: that percentage of orders finished within this time. P25 = the fastest quarter of orders; P50 is the median โ€” the typical order, half faster and half slower; P99 means 99 of every 100 orders were at least this fast โ€” only 1 in 100 was slower. P90/P95/P99 describe the unluckiest customers' experience, which is exactly what averages hide โ€” so those are the numbers we hold ourselves to.
MIN P50 P90 P99 MAX every order in the run, sorted fastest โ†’ slowest the slow tail โ€” what averages hide
Percentiles, visually: sort every order in the run from fastest to slowest. P50 is the middle of the line (the typical order), P90 leaves only the slowest 10% to its right, and P99 sits at the edge of the slow tail โ€” the amber bars an average would quietly smooth away.

Here is what those statistics look like from a real run today, for the three fully automated steps (values in whole seconds โ€” a "0" means the step completed in under a second):

Step Performance Results from a stress-test run. Purchase: min 0, avg 0.26, max 3 seconds; P25 and P50 are 0.0 and P75 through P99 are 1.0. Borrower Ownership: min 0, avg 0.03, max 1; every percentile 0.0 except P99 at 1.0. Sell: min 0, avg 0.04, max 1; every percentile 0.0 except P99 at 1.0.
A real run's report card. Reading Purchase: the typical order (P50) finished in under a second, the average was 0.26s, 99 of every 100 orders (P99) finished within 1 second, and the single worst order of the whole run (Max) took 3 seconds. Borrower Ownership and Sell average 0.03โ€“0.04s with even their P99 at 1 second. Two years ago the purchase step alone averaged nearly 12 seconds with a worst case of 65 โ€” Part 2 tells that story.
SECTION 05

None of this came easy

Everything described above โ€” five legal steps in seconds, millions of tracked units, four products on one pipeline โ€” is where the platform ended up. It is not where it started. In January 2025, a test of just ten automated orders left four of them stuck. Between that day and today's routine 5,000-order runs stand fifteen hard-won battles โ€” the first ten fought in the code and the database, the last five in the infrastructure underneath it:

  • CASE 01Everything waited for everything. The first order couldn't purchase until all 49 others finished searching โ€” and the first "stuck orders" root cause was a disk at 98%.
  • CASE 02The database fought back. Deadlocks and lock timeouts that took three rounds of fixes โ€” the last one cut the worst order from 65s to 14s.
  • CASE 03A timeout nobody knew existed killed the first 11 orders of a 300-order run โ€” and triggered a summer-long campaign on the purchase path.
  • CASE 04Every certificate cost a browser session. Tuning Chrome bought headroom, a PHP engine bought 7ร— โ€” but the winning move was a business decision: generate on demand, and the cost per step fell to 0 seconds.
  • CASE 05"Which units can this customer even buy?" โ€” answering it scanned millions of rows per order, until a settled flag, and finally a precomputed eligibility ledger, made it a 0.1s lookup.
  • CASE 06Pay 1,000,000 exactly, using only the banknotes in your wallet. The commodity-combination search that once died in gateway timeouts now answers in milliseconds โ€” with a hard 3-second stop.
  • CASE 07The platform attacked itself: one job dispatched 22,400 times in hours, one query executed 114,000 times โ€” fixed for an 85% query reduction.
  • CASE 08A bug-fix quietly added 2 seconds to every order โ€” caught within a week, only because a baseline existed.
  • CASE 09The unit ledger under siege: 94 million reads on one index, race conditions on exclusive holds, and a caching experiment that had to be rolled back.
  • CASE 10Everything is a job โ€” and jobs died silently. No retries, no overlap guards, locks that never expired: a transient blip froze an order, and two servers could grab the same work. Retry with escalating backoff became the road to 0 failed transactions.
  • CASE 110.5 seconds of work inside a 7.5-second step โ€” the latency was hiding between the jobs, and fixing it made another step 3ร— slower before it made everything faster.
  • CASE 12Every split leaves something new to run. 3 worker containers became 122 processes across 22 queues โ€” including one pinned forever at a single worker, on purpose.
  • CASE 13The workers were running last month's code. Jobs finished, follow-ups never started, and no error was raised anywhere โ€” every deploy had been updating the web tier and none of the workers.
  • CASE 14The boring failures: full disks (twice), a 32,000-company integer overflow, and connection exhaustion at full worker scale.
  • CASE 15Three machines became two at identical queue concurrency โ€” after discovering one node had been serving 100% of the traffic while another sat out of rotation for six months.

โ† Blog