Tarrek Osama

Port Said local time

Colour theme

Selected workCircuit 1 · Money

Gold trading engine

No two buyers can take the same piece of gold

My role
Architect and builder
When
AcuteBusiness · 2024 – present
Where it stands
Company product
buyershmaclockstocktaken · refused
verify → lock → commit · each piece sold once

What I built

A high-concurrency gold trading system for Estore, with the geo-spatial delivery engine and the digital wallet integration around it.

Why it mattered

Prices change in fractions of a second, and many people can try to buy the same item at once. Without care, two orders could both succeed for one piece of gold, or a trade could go through at a stale price.

Try itPlay the buyers. Buy a piece of gold, send a second buyer for the same piece at the same instant, or send a wallet request with a forged signature, and watch what reaches the stock.
  1. 1Signature
  2. 2Lock
  3. 3Commit

pieces in stock3

last serial soldnone

No orders yet.

Illustration running in your browser. It shows the real system’s approach in simplified form; names and numbers are invented, and nothing here touches the real system.

What made it difficult

  • Everyone arrives at once

    Concurrent orders can reach for the same item in the same instant.

  • Prices don’t wait

    Price fluctuations are measured in fractions of a millisecond, so a trade can’t be half-done when the price moves.

  • Balances are a target

    Wallet requests come from clients, and a changed payload must never change a balance.

How I solved it

  1. Lock, then trade

    Redis atomic locks guard each trade, so concurrent orders for the same item are handled one at a time.

  2. Two-phase commit

    A trade is prepared first and committed only when every part agrees, which prevents race conditions mid-trade.

  3. Every piece has a serial

    Inventory is tracked by serial number, so stock can never be sold twice or go missing.

  4. The backend owns the balance

    Wallet requests are signed with HMAC and the backend is the single source of truth, so a tampered payload cannot change a balance.

  5. Delivery fees from the map

    MySQL Spatial (GIS) checks which district polygon an address falls in, and the fee follows from that point-in-polygon test.

What I delivered

The trading core of Estore, an asset-trading product at AcuteBusiness.

Guarantees by design: no race conditions on a trade, strict inventory integrity, tamper-proof wallet balances.

Around it: a geo-spatial delivery engine and the digital wallet integration. No trading volumes are published here.

Built with

  • Laravel
  • Redis atomic locks
  • MySQL
  • MySQL Spatial
  • HMAC signatures