Why most trading platforms break under load
Trading platforms fail in production for a predictable reason: they're designed and tested against calm markets, not volatile ones. A dashboard that renders smoothly with a tick every few seconds can completely lock up when a symbol starts printing hundreds of updates per second during a news event. If your architecture treats market data as an occasional update instead of a continuous, high-frequency stream, you will hit a wall the first time it matters.
The fix starts with separating concerns clearly. Ingestion, order processing, delivery to clients and rendering are separate layers, and each one has to be able to shed load without taking the others down.
| Layer | Owns | When overloaded or unsure |
|---|---|---|
| Ingestion | Exchange and broker connections, reconnects, and normalizing every feed into one schema | Resyncs from a snapshot and marks the data stale |
| Orders and risk | Order state, positions, limits and reconciliation with the broker | Refuses new orders until state is confirmed |
| Delivery | Fan-out of prices and order events to connected clients | Drops intermediate ticks, never the latest one |
| Interface | Rendering and user input | Shows a stale-data warning instead of an old price |
Ingestion: treat exchange feeds as unreliable by default
Exchange WebSocket feeds drop connections, send out-of-order messages, and occasionally duplicate updates. A production-grade ingestion layer needs automatic reconnect with exponential backoff, sequence-number gap detection, and a REST-based snapshot fallback to resync state after a disconnect.
We typically run ingestion as an isolated service (or worker) that normalizes data from multiple exchanges into one internal schema before anything downstream touches it. This means adding a new exchange later doesn't require rewriting your charting or order logic.
- Normalize symbols and price/size formats across exchanges immediately on ingestion
- Buffer and coalesce ticks server-side before pushing to clients to avoid overwhelming the UI thread
- Persist raw feed data briefly for replay/debugging when a trade dispute or bug report comes in
class BookFeed:
"""Applies order book updates in order and resyncs when one is missing."""
def __init__(self, symbol, rest_client, on_update):
self.symbol = symbol
self.rest = rest_client
self.on_update = on_update
self.last_seq = 0
async def start(self):
await self.resync() # always begin from a full snapshot
async def handle(self, msg):
seq = msg["seq"]
if seq <= self.last_seq:
return # duplicate or late message: ignore it
if seq != self.last_seq + 1:
await self.resync() # gap: local state can no longer be trusted
return
self.last_seq = seq
self.on_update(msg)
async def resync(self):
snapshot = await self.rest.order_book(self.symbol)
self.last_seq = snapshot["seq"]
self.on_update({"type": "snapshot", **snapshot})Order execution: idempotency and reconciliation are non-negotiable
Every order placement, cancellation, and modification should carry a client-generated idempotency key. Networks are unreliable; a client retrying a timed-out request must never risk placing the same order twice. On the backend, maintain an authoritative order state machine and reconcile it against exchange acknowledgements and fills on a fixed interval, not just on push events, so a missed WebSocket message can never leave your system with stale state.
Most broker and exchange APIs support this directly. Alpaca accepts a client_order_id on new orders and Binance accepts newClientOrderId, and both let you look an order up by that ID afterwards. Generate the ID once per trading intent, store it before the first attempt and reuse it on every retry.
For anything approaching low-latency execution, colocate your execution service close to the exchange's API endpoint and keep the hot path - order validation, risk checks, submission - free of any synchronous calls to your database or analytics services.
import uuid
async def submit(order, broker, store):
# One ID per trading intent: created before the first attempt, reused on every retry.
order.client_id = order.client_id or uuid.uuid4().hex
await store.save(order, status="PENDING_SUBMIT")
try:
ack = await broker.place(order, client_order_id=order.client_id)
except TimeoutError:
# Outcome unknown. Ask the broker before deciding anything.
ack = await broker.find_by_client_id(order.client_id)
if ack is None:
await store.mark(order, "UNKNOWN") # the reconciliation loop resolves it
return
await store.mark(order, ack.status, broker_id=ack.id)Related: Broker and exchange API integration
Order state: one record and defined transitions
Keep one authoritative record per order and let it move only along defined transitions. Events from the broker move an order forward. Nothing in your own code should mark an order filled because it expected a fill.
- PENDING_SUBMIT: saved locally, not yet acknowledged by the broker
- ACCEPTED: the broker has the order and has returned its own ID
- PARTIALLY_FILLED: one or more fills received, with quantity still open
- FILLED, CANCELED, REJECTED and EXPIRED: final states that never change again
- UNKNOWN: a request timed out, and only the broker's answer may move it on
Reconciliation: the broker is the source of truth
Push events get lost. On a fixed interval, and again after every reconnect, fetch open orders, recent fills and positions from the broker and compare them with your own records. The broker is the source of truth for what happened; your database is the source of truth for what you intended.
Every difference is either repaired automatically (a missed fill is applied, an UNKNOWN order is resolved) or raised as an alert that blocks new orders on that account until someone has looked. A position that differs from the broker's record is an incident, and it should page someone.
State management on the frontend
Most trading UI performance problems come from re-rendering the entire component tree on every tick. We use a normalized store (keyed by symbol/order ID) with fine-grained subscriptions, so a price update for one row only re-renders that row, not the whole order book or watchlist. Combined with virtualization for long lists (order books, trade history), this keeps frame rates stable even at high message rates.
const latest = new Map<string, Tick>(); // newest tick per symbol
let scheduled = false;
export function onTick(tick: Tick) {
latest.set(tick.symbol, tick); // overwrite: older ticks for the symbol are dropped
if (scheduled) return;
scheduled = true;
requestAnimationFrame(() => {
scheduled = false;
store.applyTicks([...latest.values()]); // one state update per frame
latest.clear();
});
}Load-test with a bad day
Record raw feed data from a volatile session and replay it against a staging environment at several times real speed. A calm-market test tells you nothing about the day the platform will be judged on.
Watch three numbers while it runs: the delay between the exchange timestamp and the price reaching a browser, the depth of every queue between layers, and the time from order click to broker acknowledgement. Decide in advance which one the system gives up first. For most platforms that is intermediate price ticks, and never order events.
A checklist before launch
Before real money moves through the platform, break it on purpose in staging and confirm it fails the way you designed it to:
- Kill the WebSocket connection mid-session: the feed resyncs, and the interface shows stale data while it does
- Time out an order request: no duplicate order is created, and the order resolves through reconciliation
- Restart the order service with orders open: state is rebuilt from the database and confirmed with the broker
- Deliver the same fill event twice: positions and P&L change only once
- Replay a high-volume session: queues stay bounded and the browser stays responsive
- Trip each risk limit: new orders are refused and an alert goes out
- Use the kill switch: every strategy stops and open orders are cancelled
What we recommend for new builds
If you're starting a custom trading platform from scratch, resist the urge to bolt real-time features onto a standard CRUD web app architecture. Design the ingestion and execution layers first, load-test them against replayed historical high-volatility data, and only then build the UI on top of a state layer that already assumes high-frequency updates.
Related: Custom trading platform development · Broker API integration
Related Articles
Ready to build something that ships?
Tell us about your project and get a scoped plan, timeline and quote - usually within one business day.
Not ready to chat? Hire through the Fiverr profile instead.