Follow a Single Observation
A market-data listener receives a trade, waits for a database write, computes a decision, and submits an order. During that wait, more messages arrive. An unbounded promise chain hides the backlog until memory grows or decisions are based on old data.
Splitting that callback is useful only if the boundaries define how work is queued and what happens when a consumer falls behind. Moving the same unbounded queue into another module does not resolve the failure.
Consider a service observing one product. Its connector validates a market message and attaches receipt time. A recorder persists the observation. A state consumer updates the fields needed by a decision function. That function emits a recorded intent rather than calling an SDK directly.
The public-data-first example implements a small starting point. The same observation can feed a display whose requirements differ from the recorder's: a price label can replace an old value, while a trade recorder cannot silently drop an intermediate trade.
| Component | Owns | Failure handling |
|---|---|---|
| Exchange connector | Native topics, request fields, identifiers, and decoding. | Report the affected connection or operation. |
| Recorder | Durable observations and replay boundaries. | Stop claiming complete recording after a lost write. |
| State consumer | Fields required by one application calculation. | Mark the affected scope for recovery when a gap matters. |
| Decision function | Deterministic output from explicit inputs. | Record a refusal when required inputs are unavailable. |
| Executor | Persisted command identity and dispatch checks. | Reconcile unknown submissions before considering another attempt. |
Bound the Work
A queue needs limits on count, bytes, or age appropriate to its consumer. A full display queue may coalesce updates by symbol. A full recorder queue means the dataset may be incomplete, so the recorder needs to stop or recover the missing interval.
CPU-heavy computation can move to a worker thread, but the transfer queue still needs a limit. Measure processing time and queue age through the normal application entrypoint. A fast isolated SDK example cannot reveal a slow downstream calculation.
Keep Product Differences Visible
The connector constructs the right client for the account and product. It preserves native order and execution IDs alongside application IDs. Quantities are interpreted using that product's instrument rules before an executor sends a request.
The Binance, Bybit, and Coinbase comparison shows why a generic symbol string is insufficient routing information. Unsupported capabilities should be explicit at the boundary rather than silently substituted.
Recover and Stop Deliberately
After a reconnect, recovery belongs to the state or recorder that needs it. A price display may resume on a fresh observation while a historical calculation remains paused for backfill.
During shutdown, stop accepting new decisions, block queued dispatches, finish or record pending writes, and retain unresolved commands for the next process. Closing the socket does not cancel exchange orders. Those are separate operations with their own outcomes.
Related articles
Continue from here