Low-Latency Architecture for Solana HFT

Data is arriving, yet the prices your application uses to make decisions are still out of date. In a Solana HFT application, you need to examine both the time spent computing and the time received data spends waiting before it informs a decision. Earlier updates may still be waiting for processing, a log write may be unfinished, or another market's update may be holding a lock. The way you organize your code changes these waits.
This article follows where incoming data waits and what can move forward when the design changes, using five patterns. You can also start with the symptom that matches your application and go directly to that section.
| What is happening in the application | Design to examine |
|---|---|
| Unprocessed data keeps growing the longer the application runs | 1. Arrival rate, processing rate, and limits on waiting |
| The next price cannot be processed while a record is being saved | 2. Separating decision-critical work from analytical logging |
| An update to market A makes an update to market B wait | 3. Splitting locks that protect independent state |
| The same preparation is repeated for every arrival | 4. Preparing unchanged parts in advance and reusing them |
| Decisions use old values even after the connection returns | 5. Distinguishing connection recovery from recovery of decision state |
The counts, prices, operation counts, and durations in the diagrams are illustrative models. They do not represent measured performance or trading outcomes.
Select a diagram to open the full-size image.
1. Compare arrivals with processing capacity and set limits on waiting
Consider an application that receives six events and can process two in each equal-length time interval. At the end of the first interval, four events remain unprocessed. A queue is where data waits to be processed.
Processing is moving forward, but four events have not yet been used for decisions.
Now scale the same ratio to 60,000 incoming events. Processing 20,000 leaves 40,000 waiting. On the right side of the diagram, each dot represents 100 events, and each group of 100 dots represents 10,000 events. Two groups have been processed, and four groups remain waiting.
The groups on the right are a way to show volume. They do not represent processing batches in the application.
The next interval begins with 40,000 events already waiting. Another 60,000 arrive and 20,000 are processed, leaving 80,000. The following interval ends with 120,000. Newly arriving prices must wait behind work that is already in the queue.
When arrivals continue to exceed processing capacity, the backlog keeps growing.
A queue helps absorb bursts: short periods when arrivals are concentrated. Increasing its capacity does not resolve a sustained processing deficit like the one in this example. In addition to the number of items and bytes retained, observe how long the oldest item has been waiting and set an acceptable limit. If the required freshness is no longer met, pause new trading decisions that depend on those values even if no updates have been lost.
What should happen when that limit is reached? In the next diagram, all eight available slots are full when two more updates arrive. If those two updates cannot be retained and are required for a decision, the application can no longer update its stored values correctly. Pause new trading decisions that depend on those values and resume after recovering the necessary updates.
A queue design also needs to define what happens after its limit is reached.
Review whether you can reduce the work or increase processing capacity. If a consumer needs only the latest complete state of the same entity, it may be possible to coalesce intermediate values into the latest one. For a process that accumulates deltas or needs intermediate events, however, omitting updates changes the result.
Pausing reception may also move the wait upstream. Consider gRPC flow control, which regulates the pace of sending and receiving, together with server-side filters that narrow the subscribed data and the application's actual processing capacity.[3][4]
Start with one queue and count how many events enter and leave during the same interval. Measure the age of the oldest data, including any wait before handing work to its processor. Check whether exceeding the limit can lose required updates and whether the affected decisions can be paused if a loss occurs.
2. Process the next price without waiting for a record to be saved
Consider a market price changing from 100 to 101. The application has applied 100, completed its decision, and is saving an analytical record. If the loop that handles incoming data waits for that save to finish, it cannot apply 101 even when the update arrives. The application's stored price remains 100.
The reason processing cannot begin for 101 is the wait for the record of 100.
Now hand the analytical record to an auxiliary queue with available capacity and let a separate operation save it. The receiving loop can return to the next input once the handoff is complete. It can apply 101 and proceed to a decision while the save for 100 is still in progress.
The following comparison keeps the save duration for 100, the arrival time of 101, and the time needed to process 101 the same. What changes is whether moving to the next input depends on the save finishing.
Even without shortening the work for 101 itself, you can reduce the wait before it begins.
The processing path required from receipt through decision and submission is called the hot path. In this example, analytical logging that does not need to delay the decision is moved off that path. Balance checks, risk-limit checks, and saves that must finish to preserve correctness stay where the requirements demand them.
The saving work still exists, so the auxiliary queue also needs capacity and waiting-time limits. A separate task does not necessarily run on a separate CPU. Long CPU-bound or blocking operations in Tokio, and long synchronous operations on the Node.js event loop, can prevent other work from progressing. When moving work, check where it will actually execute.[1][2]
Look for one save operation that your receiving loop waits for before returning to the next input. Determine whether its completion is a prerequisite for a decision. If it can be separated, compare the decision start time and the auxiliary queue's waiting time using the same input.
3. Do not make independent updates wait for the same lock
Consider an application that can update the prices of markets A and B independently. An update for B arrives after the update for A has started. If a single mutex protects both A and B, B has to wait until A releases that lock.
A mutex grants one operation at a time the right to access the protected data. If another operation is using it, an operation trying to acquire the same lock waits.[17]
B's data has arrived, but it is waiting for the shared lock held by A.
If A and B each modify separate values, one option is to protect them with separate locks. The upper half of the next diagram uses a shared lock; the lower half uses separate locks. Arrival positions and lock-holding durations for A and B are identical in both halves. The example assumes B's lock is free and there is execution capacity available for B. Tokio's official tutorial also describes mutex sharding for data with independent keys.[18]
B's blue bar has the same length. The removed portion is the pink waiting interval before it.
The blue bar covers the time from acquiring the lock to releasing it. In this example, B finishes while A is still updating. Separate locks do not remove a wait caused by B's own lock being in use or by other work occupying the available execution resources.
Before splitting a lock, establish which updates are independent. Even if the prices for A and B can be updated separately, a decision that uses both prices or a shared balance still needs a way to read the required values consistently. Values can change while an operation is suspended at an await, even on the same thread. Define which versions a decision reads, how it reads them, and the order in which updates are applied.
For example, if A and B read the same balance and each build an order, they may both count on spending the same funds. Shared values still need their own protection, such as a single owner that checks the balance and reserves funds for each order in sequence.
Another option is to give each state a single update owner and send update messages to it. This is the Single Writer principle. Splitting locks and choosing a single writer are separate design decisions. LMAX Disruptor describes Single Writer and processing dependencies, while Tokio describes managing state through messages to a dedicated task.[5][18]
Start with one lock that is actually causing contention and find out why A's work is making B wait. Separate only the parts that can be independent, then replay the same input to check whether lock waiting decreases while update order and decision results are preserved. If data is decoded in parallel, also check that decode completion order is not being mistaken for the required application order.
4. Prepare unchanged parts in advance to reduce work after arrival
Suppose every price update causes the application to parse the same fixed ID, derive a fixed address from the same inputs, and allocate working memory. This working memory is also called a buffer. Repeating these three preparations places the time spent preparing unchanged information on the path to each decision.
Preparation whose inputs do not change can be completed before the data arrives and reused. After arrival, the application checks the information that changed for this event, builds the final message to send, and signs that content.
Move unchanged preparation earlier, while keeping validation of the current content and signing after arrival.
Count what changes for three updates. Preparing three kinds of items for every event takes nine preparation operations. Preparing those three kinds once and reusing them sequentially takes three. Both designs still receive three events, process them one at a time, and produce three outputs.
The number of events remains three, while fixed preparation falls from nine operations to three in this example.
This comparison assumes the fixed conditions do not change and the working memory can be reused safely in sequence. Its contents are still updated for the current event each time. If multiple operations run concurrently, use separate regions for each operation or a pool that manages access so they do not overwrite the same memory.
Extend the same example to 1,000 events. Preparing three kinds of items for every event takes 3,000 preparation operations; completing the shared preparation once takes three. Both designs receive 1,000 events, process them one at a time, and produce 1,000 outputs. Keep the preparation count separate from the number of events being processed.
What decreases is repeated fixed preparation. Validation, decisions, signing, and other work remain, so the ratio of these counts is not an application-wide speedup.
Define the conditions under which reuse remains valid. If an input to the fixed-address derivation changes, the address must be recalculated. Prices, quantities, balances, referenced account state, risk limits, and blockhashes must be valid when the decision uses them. If the application maintains continuously updated local state, check its version, freshness, and validity. This does not necessarily require fetching everything again over RPC for every decision.
Solana's getLatestBlockhash returns a blockhash and its lastValidBlockHeight. Distinguish block height from slot when checking expiry.[7] Finalize the message before signing it. If the message is changed after signing, create signatures for the updated content.[19]
Choose one repeated parse, derivation, or allocation in your code and write down which changes require it to be redone. Define the period in which reuse is valid, move the work earlier, and compare preparation time after receipt and the resulting outputs. Also vary the inputs to verify that an obsolete preparation result is not reused by mistake.
5. Do not keep making decisions after missing required updates
Consider two markets for the same asset, with the application calculating the price difference B−A. While disconnected, market A changes from 100 to 105, and the application misses that update. If it receives only B's price of 104 after reconnecting, it calculates 104−100, or +4. Using the updated value for A gives 104−105, or -1. Even the sign changes.
The same calculation changes depending on whether it uses A's old value of 100 or the updated value of 105.
This model shows only a price difference. It excludes fees, execution conditions, and other factors, and does not represent trading profit. The point is that restoring the connection does not necessarily restore all updates needed for a decision.
In this example, pause new trading decisions that use the prices of A and B, then replace A's old value of 100 with the recovered value of 105. Next, verify that the updates needed for the decision have been applied to A and B and that the required ordering and freshness conditions are satisfied. Resume once the necessary checks are complete, and remain paused if they cannot be completed.
Separate updating the values from verifying that those values can be used for decisions.
A common recovery mechanism is a snapshot: a collection of state at a particular point. When joining it to a continuous update stream, establish which updates are already included in the snapshot and which subsequent updates should be applied. This avoids applying an included delta twice or losing an update at the boundary. The specific method must follow the guarantees of the chosen API for subscription start, identification, refetching, and replay.
Yellowstone messages include fields such as slot and write_version.[16] Their presence alone should not be taken as a guarantee of a sequence usable across providers or of complete gap detection. Do not convert a slot difference directly into a count of missing updates or seconds of latency. Verify that state has been reconnected according to the guarantees of the selected provider.
Also account for calculations that started before recovery. An operation that began with old state but finishes after recovery could overwrite the new state with its result. One approach is to assign state a generation number across recovery and reject results from an older generation. If using processed state, include rollbacks (where that state is no longer adopted) as a condition for reviewing the state.[6]
Start by checking whether the reconnection handler resumes trading decisions simply by setting a connected flag. Replay an input with one missing update and verify that decisions stay paused between connection recovery and completion of state recovery. Then include duplicate updates, reordered updates, and operations that were already running before recovery to establish what can be detected and when resumption is allowed.
Choosing Rust, TypeScript, Node.js, and Deno
Implementing these five designs requires detailed decisions about who updates data, where memory is allocated, what gets copied, and which operations wait. When those controls need to be refined along a critical processing path, Rust is a strong candidate.
Rust checks ownership rules at compile time. Its ordinary memory management does not require a tracing garbage collector that follows live objects during execution and reclaims those that are no longer needed.[8] Designing who owns data and when it is finished with, then refining allocation, reuse, and concurrency costs, connects directly to the improvements in this article.
Rust still incurs allocation, deallocation, copying, locking, and operating-system waits. Test whether it meets the required latency under the actual inputs and load. A language change can follow the identification of waits and repeated work, based on how much control is required.
TypeScript is a language; Node.js and Deno are environments that execute JavaScript. TypeScript's type annotations are erased at runtime, so runtime validation of external data and the cost of CPU-intensive work must be considered separately. Deno also runs JavaScript in V8 after removing TypeScript's types.[9][10]
| Option | Work to assign and points to check |
|---|---|
| Rust | A candidate for decoding, state updates, decisions, and other paths requiring fine control over memory and concurrency. Measure actual copying, allocation, and synchronization costs. |
| TypeScript | A language for implementing Web UIs and applications that run on Node.js or Deno. Distinguish its help with type-based design from runtime performance and input validation. |
| Node.js / Deno | Can handle API integration, configuration, monitoring, and stream processing that meets the required performance. Examine work that occupies the event loop for too long and the cost of handing work elsewhere. |
| Go | A candidate for concurrent services and data processing. Most GC work proceeds concurrently, but measure the CPU, memory, and latency costs of allocation and collection.[13] |
| Python | A candidate for research, analysis, validation, and work using existing libraries. Check the actual CPython configuration and which parts are handled by native implementations in languages such as C or Rust.[14] |
| C / C++ / Zig | Candidates for low-level control over memory and execution. Consider generated code and libraries, implementation safety, team expertise, and maintenance costs. |
Node.js worker_threads and Deno Web Workers are options for moving CPU work to a different execution context. The Node.js documentation recommends a worker pool rather than creating a worker for each task. Compare not only the computation in the destination, but also conversion, copying, and the wait to submit work.[11][12]
For Python, evaluate the configuration you actually use, including whether it is a free-threaded build.[14] An existing application can start by improving one part identified through measurement. If moving work to Rust or a native implementation, include conversion and copying at the boundary and check whether the application as a whole benefits.
Test one change against the same input
Start with one problem observed in your own application. If unprocessed data accumulates, examine arrivals and processing capacity. If work waits for saves, examine the receiving loop. If one market's update waits for another, examine the shared lock. There is no need to introduce all five patterns at once.
Compare before and after using the same inputs, subscription conditions, load, and output requirements. For the time from receipt to decision completion, examine the median, p50, along with p95 and p99. The p99 is a threshold within which 99% of measured events finish. It helps reveal the slower side of the distribution as well as typical processing.
Adding the p99 of each stage does not produce the end-to-end p99. Measure the full duration from receipt to decision completion for each event directly, alongside queue waits, CPU and memory use, missing or discarded updates, and agreement between decision results.
When measuring elapsed time within a single host, use a monotonic clock that does not move backward when wall-clock time is corrected. If an SDK invokes a callback only after decoding, processing has also occurred before the callback starts. State exactly where each measurement begins and ends so that delivery latency and application latency can be considered separately.
Check what happens after submission as well. A successful sendTransaction response does not guarantee processing or confirmation by the cluster.[15] Correlating receipt, decision, submission acceptance, and the observed on-chain result helps identify the next place to improve.
Instructions for applying this to your application
Give the following instructions to an AI agent that can read your project's code. They cover examining the implementation, making one change, and validating it.
text
Examine this application's receipt → state update → decision → submission path and improve latency and processing efficiency while preserving correctness.
First read the README, development instructions, dependencies, and actual code. Identify the language, runtime, SDK, data sources, commitment, and deployment. Map synchronous I/O, CPU work, copying, allocation, shared state, queues, and waits on external communication to their locations in the code.
Choose one of the following five patterns whose effect can be tested:
1. Limits on queue items and bytes, concurrency, and waiting time
2. Separation of the decision-critical path from work that can happen later
3. Explicit state-update ownership, lock scope, and application order
4. Precomputation with expiry and invalidation conditions
5. Joining initial state to an update stream, detecting gaps, and resynchronizing
Explain why you selected it, the expected benefit and additional costs, and what you will measure. Before changing the code, save reproducible input and baseline measurements. If target latency or load is unknown, state your assumptions. Then implement the smallest change under the existing permissions and development process. Do not assume that a full migration to Rust or adoption of all five patterns is required. Distinguish TypeScript as a language from Node.js/Deno as runtimes.
Compare before and after using the same input. As needed, check receipt-to-decision p50/p95/p99, throughput, queue waiting time, CPU and memory, missing or discarded updates, and output agreement. Include conversion, copying, and waiting when handing work to a worker or native implementation. Mark values that cannot be measured as unmeasured.
Preserve required updates, ordering, numeric precision, risk checks, and signature validity. Do not assume replay or snapshot guarantees. While state is invalid, pause new trading decisions that depend on it and define recovery conditions. Do not output private keys, credentials, or customer data. Do not infer new permission to change production, enter paid contracts, or conduct live trades from these instructions alone.
Finally, report the files changed, causes established, before-and-after results, correctness validation, remaining limitations, and one next experiment.Examine this application's receipt → state update → decision → submission path and improve latency and processing efficiency while preserving correctness.
First read the README, development instructions, dependencies, and actual code. Identify the language, runtime, SDK, data sources, commitment, and deployment. Map synchronous I/O, CPU work, copying, allocation, shared state, queues, and waits on external communication to their locations in the code.
Choose one of the following five patterns whose effect can be tested:
1. Limits on queue items and bytes, concurrency, and waiting time
2. Separation of the decision-critical path from work that can happen later
3. Explicit state-update ownership, lock scope, and application order
4. Precomputation with expiry and invalidation conditions
5. Joining initial state to an update stream, detecting gaps, and resynchronizing
Explain why you selected it, the expected benefit and additional costs, and what you will measure. Before changing the code, save reproducible input and baseline measurements. If target latency or load is unknown, state your assumptions. Then implement the smallest change under the existing permissions and development process. Do not assume that a full migration to Rust or adoption of all five patterns is required. Distinguish TypeScript as a language from Node.js/Deno as runtimes.
Compare before and after using the same input. As needed, check receipt-to-decision p50/p95/p99, throughput, queue waiting time, CPU and memory, missing or discarded updates, and output agreement. Include conversion, copying, and waiting when handing work to a worker or native implementation. Mark values that cannot be measured as unmeasured.
Preserve required updates, ordering, numeric precision, risk checks, and signature validity. Do not assume replay or snapshot guarantees. While state is invalid, pause new trading decisions that depend on it and define recovery conditions. Do not output private keys, credentials, or customer data. Do not infer new permission to change production, enter paid contracts, or conduct live trades from these instructions alone.
Finally, report the files changed, causes established, before-and-after results, correctness validation, remaining limitations, and one next experiment.Turn fast delivery into timely decisions
Fast delivery and an application that completes the required decisions in time both matter. ERPC continues to improve its delivery infrastructure and develop information that helps improve the software running on it.
First validate application changes in the same environment. Then, where needed, compare the same code across different placements or resources to distinguish their effects. When using ERPC's hourly billing, define the hypothesis, comparison conditions, and usage duration in advance, and check the current Dashboard for pricing and availability.
References and related links
- [1] Tokio / CPU-bound tasks and blocking
- [2] Node.js / Don't Block the Event Loop
- [3] gRPC / Flow Control
- [4] Yellowstone gRPC / Messages and subscription specifications
- [5] LMAX Disruptor / Design and usage
- [6] Solana / Commitment
- [7] Solana / getLatestBlockhash
- [8] Rust / Ownership
- [9] TypeScript / Runtime Behavior and Erased Types
- [10] Deno / TypeScript
- [11] Node.js / Worker threads
- [12] Deno / Web Workers
- [13] Go / Garbage Collector
- [14] Python / Free threading
- [15] Solana / sendTransaction
- [16] Yellowstone gRPC / Message definitions
- [17] Rust / std::sync::Mutex
- [18] Tokio / Shared state and mutex sharding
- [19] Solana / Transaction Structure and Signatures
- ERPC
- ERPC Web Dashboard















