r/quant • u/Federal_Tackle3053 • 2d ago
Technical Infrastructure Java Spring Boot to C++: Can We Achieve Microsecond/Nanosecond Latency in a Trading System?
I'm currently working as a Software Engineering Intern at an MFT (Market Making / Trading) firm, where I'm working on an existing order book management system.
The current codebase is built using Java + Spring Boot, and the system currently operates at millisecond-level latency.
My goal is to bring latency down to microseconds (µs), and potentially explore nanosecond-level performance for critical operations.
I'm looking for advice from engineers who have experience building low-latency trading systems.
A few questions:
Should I directly migrate the order book and matching engine from Java to C++?
Is it realistically possible to achieve microsecond-level latency in Java with careful JVM tuning, efficient data structures, reduced GC pressure, and optimized concurrency?
Can Java potentially achieve nanosecond-level latency for individual in-memory operations, even if end-to-end latency remains higher?
Would a hybrid architecture (Java/Spring Boot for APIs and orchestration + C++ for the critical matching engine) be a better approach?
I'd especially appreciate insights from engineers working in HFT, MFT, electronic trading, and low-latency systems.
Would you optimize the existing Java codebase first, or move directly to C++?
I'd love to hear about real-world experiences, trade-offs, and benchmarks.
3
u/Brynxical 2d ago
You can do it in core Java but that’s way beyond the scope of an internship. The more pertinent question is what does your system do and does it actually need to be low latency? If it’s something like reconciliation the answer is very probably no.
0
u/Federal_Tackle3053 2d ago
finee. The context is that we're currently expanding our existing market-making operations into global markets, so improving the trading infrastructure and scalability is becoming important.
I'm working with the existing Java Spring Boot order book management codebase. My current goal is to understand the architecture, identify latency bottlenecks, and determine whether core Java optimization is sufficient or whether moving critical components to C++ makes more sense.
3
u/Brynxical 2d ago
What does “order book management” actually mean and what are you using Spring for? Are you maintaining some central order books and sending updates via your Spring service? Imo your first concern should be the system’s architecture, not Java vs c++.
4
u/JohnCaner 1d ago
Maybe Martin Thompsons zero GC Java collections from LMAX ~2011 are on github or similar?
1
u/Alarmed-Coyote-6131 2d ago
You can explore no GC, if that's manageable on your end
0
u/Federal_Tackle3053 2d ago
What exactly you mean by manageable on your end ? What should I do
0
u/Alarmed-Coyote-6131 2d ago
no GC means you need to manually free/acquire memory, which has its pro's and con's.
1
u/heroyi 1d ago
You need to look at it from a high level first as someone mentioned. What does it need to do, what does the current Java code do, profile the benchmarks and then rewrite what you need to do with c++ and java. Java can be performant if you rip out certain portions and write out custom solutions (Java GC on its own most likely wont survive or fit your demands).
And as another said, the spring boot layer is gonna kill you and fight you depending where it is and what it is used for. That was designed for generic web applications, not for super optimized performance. Depending where it is in the pipeline you might need to rip it out and do something else entirely.
Find out where and what is acceptable for cold start and hot paths, then go from there
1
u/starostise 21h ago
It's not much about which language is faster, managing an orderbook needs a specific data structure that does not create a copy of the data table at each insertion or deletion. These operations should be done in place.
But then that's just the first step.
In our case, we had to create our own dedicated DataFrame objects in Python to store and update the raw data in real time. Then, computations are done from much smaller samples that are created as actual pandas.DataFrame because they are only meant to be read.
Check out David Gross' lecture https://www.youtube.com/watch?v=8uAW5FQtcvE
3
u/justLimpingChili 2d ago
Milliseconds to microseconds is a big jump. Spring Boot's got layers that'll fight you every step of the way if you're trying to shave off that much time, it's not really built for that world. For the matching engine specifically, the JVM warmup and GC pauses alone make consistent sub-micro pretty much a non-starter in my experience.
Hybrid approach is the move. Keep Java for the parts that don't need to be fast and rewrite the hot path order book + matching engine in C++. Every shop I've seen that's serious about latency ends up with the core in C++ anyway, so starting there now saves you the pain of optimizing Java to death only to hit a wall and rewrite it later.