Quantefakt

· 6 min

Why we chose Java for a trading platform

A trading firm argued in 2020 that Java can compete with C++ in high-frequency trading. Our platform works in milliseconds. We chose Java for the speed of development, and where we needed more speed we wrote that part in C++.


In 2020, Jad Sarmo, then head of technology at Dsquare Trading, wrote Why we chose Java for our High-Frequency Trading application. His main argument is the speed of change: an improvement discussed in the morning can be in production in the afternoon. He also names the two things about Java’s runtime, the JVM, that can hurt a latency-sensitive system.

  • Garbage collection. The collector that frees memory can freeze the application for a moment.
  • Warm-up. Java starts every method slow and compiles it only after it has been called often enough, about 10,000 times. After a restart it starts over.

His answer was Azul’s Zing runtime. In his application, its garbage-collection pauses were about 180 times smaller than those of the standard HotSpot runtime of 2020.

We chose Java too. Our story is a little different.

Milliseconds, not microseconds

In high-frequency trading, where the reaction time is microseconds or even sub-microseconds, the usual choice is C++ or Rust, and the tools that simulate against an order book are mostly built the same way.

Our platform works in milliseconds, not microseconds. At that scale the scarce thing is not a few microseconds. It is speed of development.

Why Java

A trading application is more than market-data reception and order routing. Our platform, JATS, is a desktop client with:

  • Click trading and an order manager, to trade by hand at your broker.
  • Fast tables for orders, positions and market data.
  • Portfolio management, with limit and risk management.
  • ETF evaluation from the ETF’s basket files (PCF files).
  • Built-in basket algorithms.
  • Static data management, for instruments and other reference data.
  • Market data recording.
  • Algo control: start, pause, halt and stop your strategies and set their parameters, including strategies that run remotely in headless runners.
  • An integrated market replay and matching engine, which can use order-book data where the source has it.

Microseconds matter in one small part of that list. Speed of development matters in all of it. Java is fast to develop in, and a compiler checks every change, including the ones an AI agent writes. We made that case in Read-easy beats write-fast.

What Java costs

We measured it on a standard runtime in 2026.

Garbage collection. We use ZGC, the low-pause collector that ships with standard Java. The numbers come from the JVM’s own logs of four June 2026 sessions of a strategy on the platform: Java 21.0.8, ZGC in its older single-generation mode, a maximum heap of 12 GB.

SessionPausesLongest pause
8 June9000.032 ms (median 0.008 ms)
9 June1590.025 ms
10 June1950.029 ms
11 June4561.3 ms, one outlier

In none of the four sessions did the program have to wait for memory. These are the collector’s pauses, taken from the log, not the time from a market tick to an order, which we have not measured. But on a standard Java 21 the collector is no longer the part to worry about, and no special runtime is needed. Sarmo compared against the standard runtime of 2020. Ours is 2026’s.

Warm-up. It still matters. The warm-up window of one of our strategies opens at 09:15, when the strategy starts receiving the quotes of 300 stocks, and the live path runs on real pre-market data. With that many ticks and quotes, compilation starts within seconds. On 11 June the strategy’s quote handler was first compiled about a second after the window opened and reached the top compiler tier, tier 4, 17 seconds after that, at 09:15:18 New York time. The whole quote path was at tier 4 by 09:16:03, a quarter of an hour before the open.

Where we added C++

At the open, the market-data feed was late. To get the feed in as fast as possible, we wrote the reader in C++: about 2,500 lines. It is a separate process, and the data takes a short path through it:

  1. The TCP connection to the vendor.
  2. TLS, the encryption of the connection, handled by the Linux kernel itself (kernel TLS), so the kernel decrypts.
  3. WebSocket deframing.
  4. A scan of the JSON message by byte offsets, with no general-purpose parser.
  5. A fixed 64-byte binary record per message.
  6. A lock-free ring buffer in shared memory, one writer and one reader, in the style of the LMAX Disruptor.

The Java side maps the same memory and reads the records from there. Everything else stays Java.

It worked. On 18 June we checked the whole path, from the feed to the strategy, against the vendor’s own end-of-day file. At the open (09:30 to 09:35) the strategy received 824,089 trades where the end-of-day file, filtered the same way, has 824,100: 99.9987%, with every symbol within 13 trades. The small rest is the expected difference between a live stream and a corrected end-of-day record, not lost data. The end-of-day file is the vendor’s settled record of the day, with late reports, corrections and cancellations applied after the fact, while the live stream is what was sent at the moment. In a benchmark, the reader alone handles about 8.6 million events a second, against a peak feed of about 30,000 messages a second.

Then we found the real delay. Measured on 24 and 25 June from a cloud machine about 5 milliseconds from our market-data vendor’s data center, trades arrived at the open with a median delay of about 80 seconds, and the worst trade about 108 seconds. In a calm market the same trades arrive in 5 to 6 milliseconds. The probe that found it was plain Java, it kept up and dropped nothing. This is one probe on one subscription tier, and we never thought a delay like that could happen.

Log-scale chart of measured delays, from 1 microsecond to 1000 seconds. Java garbage-collection pauses: median 0.008 ms, longest 0.032 ms, one outlier at 1.3 ms. Trades arriving in a calm market: 5 to 6 ms. Trades arriving at the open: median 80 seconds. Shaded: below 10 microseconds, FPGA and a real-time OS; execution in milliseconds.

What to take from it

  1. Java is fast to develop in. For a platform that works in milliseconds, that is the scarce thing.
  2. Think the unthinkable. We built the fastest reader we could within a few days, and the delay was at the vendor. Measure from end to end before you blame the language.
  3. If you need more speed, add a C++ part for that job and keep the rest in Java. That is easier than delivering a whole application in C++. The foreign-function and memory API, final since Java 22 and part of the long-term-support release Java 25, lets Java call native code directly. Our reader is a separate process that shares memory with Java, and we have not moved to the API yet.
  4. Measure the collector before you buy a special runtime. With ZGC on a standard Java 21, its pauses were tens of microseconds in our sessions.

← All posts