Hacker News new | ask | show | jobs
by F-W-M 112 days ago
How do you structure your program to do this?

I had huge success writing a trading system where everything went through the same `on_event(Inputs) -> Outputs` function of the core and a thin shell was translating everything to inputs and the outputs to actions. I actually had a handful of these components communicating via message passing.

This worked rather well as most of the input is async messages anyway, but building anything else this way feels very tiresome.

2 comments

I also worked on trading systems.

Usually two methods `onMessage(long timeNow, byte[] buf)` and `onTimer(long timeNow, int timerId)`.

All output sinks and a scheduler need to be passed in on construction of the application.

Then you can record all inputs to a file. Outputs don’t need to be recorded because the inputs can be replayed but it is useful for easier analysis when bugs happen.

I have even worked on systems where there were tools that you could paste recorded input and outputs to and they code generated the source code for a unit test. Super useful for reproducing issues quickly.

But you are spot on in that there is an overhead. For example, if you want to open a TCP socket and then read and write to it, you need to create a separate service and serialise all the inputs and outputs in a way that can be recorded and replayed.

Thanks alot.

How easy one can debug such a systems easily outweighs the costs, if you have a low number of separate services.

OP is basically describing functional programming