A simulated prop-trading firm: traders buy an evaluation, trade perpetual futures on live market data, and move to a funded account if they stay within the risk rules.

A prop-trading firm sells evaluations. A trader pays a fee, trades a simulated account, and is funded if they reach a profit target without breaking the drawdown or daily-loss rules. No order reaches an exchange, but the money is real: fees, payouts and the pass-or-fail decision all depend on the simulated account being right.
That makes the requirements those of a small exchange back office: fills that reflect the real market, balances that can't drift, rules applied the same way every time, and a record behind every number a trader or support agent might question.
A NestJS modular monolith runs as separate PM2 processes chosen by role: API and socket gateway, market ingest, task workers, risk detection, outbox relay and admin API. They share one PostgreSQL database, and Redis carries market frames and pub/sub. Splitting by process rather than by service keeps deploys simple while letting the busy paths scale and fail on their own.
One ingest process holds a fenced leadership grant and streams order books and trades from Hyperliquid. It writes the latest decision frame for each instrument to Redis through a Lua compare-and-set on epoch and sequence number, so a demoted leader can't overwrite newer data. Everything is also appended to a compressed archive that can be replayed.
Every change that touches money (a fill, a fee, funding, a payout) is a financial command. It runs in one database transaction that claims an idempotency record and rejects a retry whose payload differs, takes per-account advisory locks under a lock timeout, posts ledger journals, and appends domain events and outbox rows. If any step fails, none of it happened.
The ledger is double-entry. Journals are inserted as drafts and can only move to posted; database triggers refuse a journal with fewer than two entries or a non-zero sum, and posted rows can't be edited. Amounts use exact decimals, and a test fails if floating-point maths appears in the calculation code.
A relay claims outbox rows with FOR UPDATE SKIP LOCKED and publishes them to Redis, where the socket gateways push account updates to the trader. Scheduled work such as resting orders and breach checks runs on a Postgres task queue built on the same pattern, so there is no separate message broker to operate.
Breaches are detected on the server in two passes. The live pass reacts as soon as a floor is touched and, until it's confirmed, refuses fills that would add exposure; the settled pass judges from the market archive, including accounts the live pass couldn't price. Rules are pinned to an account when it's created, so editing a program doesn't change the rules for traders already in it.
Market prices can be fast and approximate; account state has to be authoritative. The two are handled by different parts of the system.


Built end to end: live order book, trades, candles and an account stream over Socket.IO, an order ticket that shows entry price, margin and fee estimates before an order is sent, and panels for positions, open orders and history. P&L and margin update as prices move.
Market and limit orders, take-profit and stop-loss, reduce-only closes, position reversal and leverage changes, netted into one position per instrument.
Orders walk the observed order book within slippage bounds. An order that would fill too far from the price, or beyond the depth the feed shows, is cancelled with a specific reason.
Profit targets, drawdown and daily-loss floors, consistency rules, and automatic progression from evaluation phases to a funded account.
An admin panel for accounts, breaches, a risk desk, KYC review and manual actions.
Every 15 minutes a job compares each account's stored balances with sums taken directly from the ledger, and checks journal balances and event sequences.
Jobs, events and money changes commit together, and there is one system to back up and monitor. The cost is a throughput ceiling and more load on the primary database. The relay numbers are enough for now, and because events already go through an outbox, moving to a broker later is a contained change.
With triggers, a bug in any process, or a manual SQL fix, can't post an unbalanced journal or edit a posted one. The trade-off is logic in two places and migrations that need more care.
Filling at the mid price would let traders profit from fills no real exchange would give them. Walking the real book is fairer but depends on feed quality, so the fill rule is documented for traders.