How to use an event driven architecture in Julia?

Hello everyone! I’m an equities and options trader with a basic understanding of Python and JavaScript. The little I’ve seen of Julia so far has been amazing and I’m hoping to explore working with financial data in Julia.

I’m now learning about event driven architecture and I’d like to know if it’s possible to use this approach in Julia?
If so, I’d really appreciate some ideas on how to do so.
Thank you.

3 Likes

Could you provide a link that explains the concept? Maybe it’s a standing term in some circles, but I’ve never heard of it and the name seems generic enough as to potentially lead to confusion!

1 Like

Probably this could be of interest to you GitHub - JuliaActors/Actors.jl: Concurrent computing in Julia based on the Actor Model

2 Likes

Yes, of course. Here’s a link https://gameprogrammingpatterns.com/event-queue.html

Based on several sources I’ve learned from, it seems that this architecture is widely used in game programming. In the examples I’ve seen, there is an event queue which stores all events passed on from the classes which handle specific tasks. This is all kept inside of an event loop.

1 Like

If working in a notebook is an option for you:

is reactive, i.e. all dependent cells are automatically updated if an input variable changes.
Planned enhancements include an (automatic) API so that the notebook and its reactivity can also be used by external programs (see Connor’s talk at Hello!).

2 Likes

Looks amazing! I’d seen the Pluto name come up while searching for other things but now that I had a chance to read about it, it’s certainly something I see myself using. Thanks for letting me know about this reactive notebook.

1 Like

See also Rocket.jl , it’s quite comprehensive. Also Transducers.jl

5 Likes

Hi,

Normally EDA / EDD is a design strategy for reactive (multi process or application) systems e.g. a loosely - coupled microservice design to support 1 - many data processing requirements.

However, from your description on pushing and pulling from an event queue, you may want to review Channels.jl - which will allow you to push from many producers to many consumers asynchronously and will help you model and reason about your system. Extending to a distributed system is then possible via RemoteChannels etc.

Actors and Rocket are both fantastic packages, but if you are just starting you may want to first relate EDA to your problem in Julia.

As an aside, if you have experience in Java: AKKA or C#: Orleans could help your design strategy.

Regards

2 Likes

An event is a computation of something that has been composed earlier. For example if you have a macro:

macro event(expr)
    esc(:(()->($expr)))
end

it gives you back a closure that has captured your expression expr: any function and arguments wrapped in it, which you can put in a queue and execute when it is due, for example:

julia> myqueue = [];

julia> ev = @event begin    # compose an event
           # do something
           1+1
       end
#13 (generic function with 1 method)

julia> push!(myqueue, ev);  # push it around

Then later (or somewhere else in your program) you can do

julia> pop!(myqueue)()      # execute it later
2

And there maybe other events in your system composed after that one but with higher priority or different time stamp … that you or your scheduler decides to execute before.

There are many ways to do that, since functions in Julia are first class objects which you can pass around with or without arguments as

You can send your events over a Channel to another Task, even residing on another thread, worker or node. But be aware, that if you do that, you may encounter a synchronization problem, since those foreign threads or workers have another time and don’t know about the function you are referring to in your event (a world age problem).

Julia gives you all those possibilities and it is an exciting field to explore.

3 Likes