Edmir Soares
Edmir Soares

[FULLSTACK_02] · Personal project · full stack

TradeFlow

Bitcoin trading simulator with double-spend prevention and financial precision.

  • React Native
  • Laravel 11
  • PostgreSQL
  • Redis
  • Docker
Source code on GitHub (opens in a new tab)
TradeFlow screens in black and yellow: login, BTC wallet balance and the buy and sell flow.

[01] Problem

Simulate real trading, with concurrent orders, money precision and live prices, without the shortcuts a demo usually takes.

[02] Solution

  • Two-layer lock against double-spend: a Redis distributed lock before any trade logic, plus lockForUpdate() inside a database transaction.
  • Money math with bcmath and DECIMAL(20,8) columns, never floats.
  • BTC price cached in Redis for 30 s; the app polls every 10 s with React Query.
  • A typed InsufficientFundsException becomes an HTTP 422 with a readable message, shown in a toast.

[03] Result

  • Users start with R$ 10,000 in virtual balance and always see a price at most 30 s old.
  • Every trade is logged with price, amount and timestamp.

[04] Architecture

  1. React Native app
  2. Laravel 11 API
  3. Redis · lock + price cache
  4. PostgreSQL · row lock