# The research desk and the execution pipeline run on two different clocks

Date: 2025-09-25
Category: Interview Preparation
Tags: Quantitative Trading, Technology Selection, Latency
Summary: When discussing the boundary between Python and C++, it is rarely a question of which language is superior; what truly determines the choice is the different time scales of the two pipelines and how much one is willing to pay for determinism

The first time I seriously read a job description for high-frequency trading was on a very ordinary afternoon. The screen was full of C++17, lock-free, kernel bypass. I closed the page and went to make a cup of tea. Back then I mainly used Python for data processing and considered myself fairly proficient, but that JD planted a very specific doubt: is this toolkit I have only good for prototyping?

That doubt lingered for a long time. Only later did I figure out that it's hard to answer because the question itself presupposes that languages have absolute rankings. Languages have no absolute capability ceiling, only degrees of fit with a scenario. Put Python on a nanosecond-level order path and of course it's a toy; put C++ into a backtest script that needs eight changes a day and it's equally hard to use.

What's really worth discussing isn't which language is stronger, but what timescale this code runs on.

## Two clocks

If you only look at lines of code, most of the logic in a quant team really is written in Python. Strategy ideas, data cleaning, backtesting, parameter search—all on this side. The core metric on this side isn't latency, it's how long it takes from an idea to seeing a backtest curve.

The other side is execution. From the strategy emitting an order to it reaching the exchange, it has to pass through risk control, the gateway, serialization, the network card. This side looks at determinism and tail latency; averages mean little. A single occasional jitter of a few hundred microseconds can eat a whole day's spread.

The two clocks also define "correct" differently. Correctness in the research phase means reproducible results and fast changes; correctness in the execution phase means the same input, with every run's duration falling within the same narrow band. The enemy of the former is code that's too convoluted; the enemy of the latter is uncertainty.

> Research code can be slow, but it can't be hard to change; execution code can be hard to write, but it can't be uncertain.

This explains why the same person can get completely different evaluations in interviews on the two sides. Someone who writes a very usable backtest framework may be utterly unable to explain the cost of memory allocation on the critical path; someone who can hand-write a lock-free queue may write research code that they themselves can't read three months later. The two test different abilities; they just happen to both be called "can write code."

So betting on the wrong track is more fatal than not being skilled enough. Interview for a core engineering role with a researcher's preparation and you'll be grilled on pointers and cache lines; interview for a research role with a low-level optimization mindset and you'll be seen as not caring about iteration speed. This isn't a matter of level, it's a matter of coordinates.

I also don't quite buy the linear process of "write it in Python first, then translate to C++." It sounds reasonable, but in practice it hits an old problem: the two codebases diverge. The research side changes a boundary condition, the execution side doesn't follow, and the gap between backtest and live trading turns into an investigation with no answer.

The approaches I've seen fall roughly into two categories. One is to converge the core computation into a library that both Python and the execution side call, with the binding layer doing only type conversion; the other is to accept the divergence but pin both sides' outputs with the same historical data, running a reconciliation on every change. The former is clean, at the cost of the core library's interface needing to be designed very restrainedly—you can't just add parameters for research convenience. The latter is flexible, at the cost of an extra step, and that step is very easily skipped when rushing for progress.

Neither is perfect. The first slows things down during strategy exploration; the second slowly fails after the team changes hands. Which to choose depends more on team size than on technical preference.

There's a very plain criterion: if you need to change parameters ten times a day, any language that requires compilation becomes a burden; if you only emit one signal a day, those tens of seconds of compilation don't matter at all. Frequency determines the tool, not the other way around.

This criterion also fails sometimes. Parameter search is a research action, but it may need to run for several hours, and that part of the work is actually better thrown into batch processing in a compiled language. So the boundary isn't drawn by person, it's drawn by the duration and call frequency of the task. The same person may switch back and forth between several tools in a single day.

## The hard part of Python isn't syntax

When interviews ask about Python, they rarely ask about syntax. They ask about understanding of the runtime and memory, because these things determine how the code behaves in production.

- The first time I wrote a backtest, I used row-by-row iteration and ran it all night without a result; after switching to vectorization it finished in a few minutes. The lesson isn't "don't write loops," it's that you have to know what the interpreter does on each line.
- The GIL is similar. Many people know that multithreading doesn't help CPU-bound tasks; but few can clearly explain why NumPy can release the GIL at the底层 and why multiprocessing has to pay a serialization cost.
- Views and copies are another pitfall. Chained indexing may get you a copy, and memory suddenly doubles; that common warning in pandas is actually the same problem through a different exit.
- For millions of small objects, you can consider restricting instance attributes to save the dictionary behind each object. This kind of optimization isn't elegant, but it's very practical when memory is tight.

What these points have in common is that none of them belong to "can you write it," but to "do you know where the cost is."

Vectorization also has a cost, just a less intuitive one. A single broadcast operation may copy temporary arrays several times larger in memory; once the data reaches a certain scale you hit the memory wall and end up working around it with chunking. So "don't write loops" is only half the sentence; the other half is "watch the intermediate results."

I value the latter kind of answer more. Someone being able to recite the definition of the GIL and someone being able to explain why a piece of code still only saturates one core on a multi-core machine are two different levels. The former can be prepared the day before an interview; the latter usually comes from having been burned.

So if I were to evaluate a candidate with a Python background, I'd care more about how they describe the pitfalls they've stepped in than how many features they can list. Whether the description contains costs, whether there's "at the time I thought it was like this, later I found it wasn't"—these details are hard to fake.

## Where to draw the boundary

At the system design level, there are usually three ways to connect Python and the execution side, each with lower latency and higher complexity than the last.

Binding is the most direct. C++ uses pybind11, Rust uses PyO3, and researchers can call the underlying order book implementation right in a notebook. The benefit is that backtest and live trading share one set of logic; the downside is that Python's garbage collection and GIL bring jitter to latency, so it's better suited to backtesting and non-critical paths. This "non-critical" line has to be drawn clearly in advance, otherwise it's easy to gradually move the heavy work into the binding layer.

Shared memory plus a ring buffer is another. Signal generation and execution are split into two processes, passing structs through a block of shared memory in between. The benefit is isolation: if the research process crashes, the execution gateway is still there and can still cancel orders. The cost is that both sides must agree on the memory layout; change a field and you have to change both sides in sync, and once this layout goes live it's hard to move.

What isolation brings isn't just fault tolerance, but also a place to blow the whistle. When the strategy process has a problem, the gateway can independently execute a cancel-all without waiting for the upper layer to recover. This action must be reserved at the design stage; it can't be added afterward.

For serialization, fixed-length binary encoding saves a layer of parsing compared to general-purpose protocols, at the cost of freedom in schema changes. When fields are stable this trade is a good deal; when the protocol is still being adjusted frequently it's torture. I learned this the hard way once: to make the structure tidier, I changed an optional field to fixed-length, and afterward every time a field was added I had to change the parsing code on both sides.

A lazier approach is to simply not let the two sides talk directly, and use files or a database for exchange. Latency is poor, but troubleshooting is extremely easy. This choice is often undervalued in low-frequency strategies—people prefer to discuss architecture rather than admit they only run a signal once a week.

## The line across the boundary

Cross-boundary monitoring is an easily omitted part. Each side has its own logs, but what is truly useful is the end-to-end one: at what moment the signal is generated, at what moment the order is sent, and whether the difference in between is queuing, computation, or network. Without this chain, all performance discussions are guesswork.

Reconciliation is the least sexy part of this structure, and also the part that cannot be omitted. Run backtests and live trading with the same market data, compare execution prices and execution times trade by trade, and stop to investigate when the difference exceeds a threshold. This sounds like testing, but it is actually part of the model; without it, none of the preceding architectural choices can be verified.

## Where Rust fits

My judgment on Rust is fairly simple: it suits new modules with relatively independent logic. Things like risk-control gateways and market-data parsing have clear boundaries, can block a class of problems at compile time, and have a clean toolchain. Newly written modules have no historical baggage, so the cost of using it is lowest.

Legacy systems are another matter. Millions of lines of C++, plus vendor SDKs that only provide C interfaces—the payoff of a rewrite is hard to justify. Rust's FFI can do it, but the cross-language boundary itself is a new failure surface, and when problems occur, neither side is easy to debug. Moreover, such systems usually have a group of people familiar only with the original toolchain, and the organizational cost of migration is often higher than the technical cost.

There is also a frequently overlooked factor: people. It is easy to hire someone willing to write Rust; it is not easy to hire someone who both understands low latency and is willing to maintain this codebase long term. Language choice affects the recruiting funnel, and this is rarely factored in at project inception.

Learning cost must also be counted. Ownership and lifetimes are an advantage when writing concurrent code, and a burden when writing business glue. For a service that only does market-data parsing, the payoff is obvious; for a service that frequently changes fields, just handling borrows will consume a lot of time.

So whether "Rust will replace C++"—I do not have an answer for now. What is certain is that on an execution path with ten years of accumulation, the newness of a language is not the decision variable; migration risk is.

As for the phrase "writing strategies in Rust," I think it mostly conflates two things. The research efficiency of a strategy has nothing to do with execution determinism; what language you use to write research code depends on who on the team will maintain it.

If I must give a preference: use Rust for new modules, continue using C++ on old paths, and separate them with a thin FFI layer, with neither side trying to persuade the other. This solution is not pretty, but it can survive for a long time.

Back to the original question. I am now reluctant to answer "Is Python a toy?" because it leads the discussion into a language war, and language wars have no winners.

A more practical question is two numbers: what is the cost of one error on this path, and what is the cost of one change. The former determines whether C++ is needed; the latter determines whether it can be avoided. When both numbers are small, any language will do; when both are large, every choice is a compromise.

These two numbers change with the business. When latency requirements are pushed down, my judgment changes accordingly. So the above are not conclusions, only a set of criteria I currently use for trade-offs.
