Quant Memo
Foundational

Logging and Structured Events

Why a trading system needs a running record of what it did and why, and why that record should be structured, machine-readable data rather than free-text sentences a human has to read one at a time.

A trade executes at an unexpected price at 3:47am and someone needs to reconstruct exactly what happened: what signal fired, what the system believed the price was at the time, what risk checks it ran, and what order it actually sent. If the system's only record of its own behavior is a scattering of print() statements or free-text log lines like "placing order for AAPL", answering that question means manually scrolling through megabytes of text hoping the relevant lines are still there and are specific enough to reconstruct the sequence of events. Logging is the practice of a system recording what it did as it runs; the question this concept addresses is what form that record should take.

A plain-text log line like "Order sent: AAPL qty 100 at 3:47:02" is readable by a human scanning it in the moment, but painful to search, filter, or aggregate later — answering "show me every order over $50,000 sent in the last hour" means writing a fragile text-parsing script that breaks the moment the log message's wording changes even slightly. Structured logging records the same information as data instead of a sentence — typically as key-value pairs or JSON, like {"event": "order_sent", "symbol": "AAPL", "qty": 100, "price": 147.32, "timestamp": "2026-07-24T03:47:02Z"}. The content is identical; the difference is that a structured event can be queried, filtered, aggregated, and fed into a dashboard directly, because a machine can parse qty: 100 reliably in a way it can't reliably parse "100" out of an arbitrary sentence.

Worked example. A risk check silently fails to block an oversized order overnight. With free-text logging, an engineer greps the log file for the word "risk" around the relevant timestamp and finds a line reading "risk check passed for order" — technically true, but with no record of what limit was checked against or what the actual order size was, because that detail was never captured, only implied by the sentence's author at the time. With structured logging, the same event was recorded as {"event": "risk_check", "result": "passed", "limit": 100000, "order_value": 98500, "symbol": "TSLA"} — the engineer can query every risk_check event from that night in seconds, see the order value sat just under the limit, and immediately spot that the limit itself was configured with a stale value, rather than piecing together a guess from prose.

What this means in practice

Structured events are what make dashboards, alerting, and post-incident investigation actually tractable at the volume a trading system generates — thousands or millions of events a day is not something a human reads line by line under any circumstances, structured or not, but it is something a query engine can summarize instantly. Logging isn't optional insurance bought after something goes wrong; the events that matter are the ones a system was never told to specifically anticipate, so the practical rule is to log liberally and structurally by default, because the alternative to "too much logging" is usually "the one event you needed wasn't recorded at all."

Structured logging records events as machine-readable key-value data rather than free-text sentences, making a system's history queryable, filterable, and aggregable — the difference between reconstructing an incident in minutes versus manually scanning thousands of log lines hoping the detail you need was written down in words.

Related concepts

Practice in interviews

Further reading

  • Fowler, Martin. "Structured Logging", martinfowler.com
ShareTwitterLinkedIn