# How to use an event driven architecture in Julia?

**URL:** <https://discourse.julialang.org/t/how-to-use-an-event-driven-architecture-in-julia/56748>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [March 8, 2021, 5:00pm UTC](https://discourse.julialang.org/t/how-to-use-an-event-driven-architecture-in-julia/56748 "2021-03-08T17:00:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![BryanB](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bryanb/32/22687_2.png) [@BryanB](https://discourse.julialang.org/u/BryanB)\
**Post date:** [March 8, 2021, 5:00pm UTC](https://discourse.julialang.org/t/how-to-use-an-event-driven-architecture-in-julia/56748/1 "2021-03-08T17:00:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 8, 2021, 5:04pm UTC](https://discourse.julialang.org/t/how-to-use-an-event-driven-architecture-in-julia/56748/2 "2021-03-08T17:04:43Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)\
**Post date:** [March 8, 2021, 5:10pm UTC](https://discourse.julialang.org/t/how-to-use-an-event-driven-architecture-in-julia/56748/3 "2021-03-08T17:10:26Z")

</div>

Probably this could be of interest to you [GitHub - JuliaActors/Actors.jl: Concurrent computing in Julia based on the Actor Model](https://github.com/JuliaActors/Actors.jl)

---

<div class="post-metadata">

**Author:** ![BryanB](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bryanb/32/22687_2.png) [@BryanB](https://discourse.julialang.org/u/BryanB)\
**Post date:** [March 8, 2021, 5:42pm UTC](https://discourse.julialang.org/t/how-to-use-an-event-driven-architecture-in-julia/56748/4 "2021-03-08T17:42:52Z")

</div>

Yes, of course. Here’s a link [https://gameprogrammingpatterns.com/event-queue.html](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.

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [March 8, 2021, 5:56pm UTC](https://discourse.julialang.org/t/how-to-use-an-event-driven-architecture-in-julia/56748/5 "2021-03-08T17:56:31Z")

</div>

If working in a notebook is an option for you:

> **[GitHub - fonsp/Pluto.jl: 🎈 Simple reactive notebooks for Julia](https://github.com/fonsp/Pluto.jl)**
>
> 🎈 Simple reactive notebooks for Julia. Contribute to fonsp/Pluto.jl development by creating an account on GitHub.

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!](https://plutojl.org/plutocon2021)).

---

<div class="post-metadata">

**Author:** ![BryanB](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bryanb/32/22687_2.png) [@BryanB](https://discourse.julialang.org/u/BryanB)\
**Post date:** [March 8, 2021, 6:12pm UTC](https://discourse.julialang.org/t/how-to-use-an-event-driven-architecture-in-julia/56748/7 "2021-03-08T18:12:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Roger\_Powell](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger_powell/32/21586_2.png) [@Roger\_Powell](https://discourse.julialang.org/u/Roger_Powell)\
**Post date:** [March 8, 2021, 7:37pm UTC](https://discourse.julialang.org/t/how-to-use-an-event-driven-architecture-in-julia/56748/8 "2021-03-08T19:37:58Z")

</div>

See also [Rocket.jl](https://github.com/biaslab/Rocket.jl) , it’s quite comprehensive. Also [Transducers.jl](https://juliafolds.github.io/Transducers.jl/dev/)

---

<div class="post-metadata">

**Author:** ![djholiver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djholiver/32/50470_2.png) [@djholiver](https://discourse.julialang.org/u/djholiver)\
**Post date:** [March 8, 2021, 10:03pm UTC](https://discourse.julialang.org/t/how-to-use-an-event-driven-architecture-in-julia/56748/9 "2021-03-08T22:03:34Z")

</div>

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](https://docs.julialang.org/en/v1/base/parallel/#Channels) - 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](https://akka.io/) or C#: [Orleans](https://dotnet.github.io/orleans/) could help your design strategy.

Regards

---

<div class="post-metadata">

**Author:** ![pbayer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbayer/32/11675_2.png) [@pbayer](https://discourse.julialang.org/u/pbayer)\
**Post date:** [March 9, 2021, 8:01am UTC](https://discourse.julialang.org/t/how-to-use-an-event-driven-architecture-in-julia/56748/10 "2021-03-09T08:01:00Z")

</div>

> [@BryanB](#):
>
> learning about event driven architecture and I’d like to know if it’s possible to use this approach in Julia?

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

```julia
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
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
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

- [closures](https://docs.julialang.org/en/v1.6-dev/devdocs/functions/#Closures) as mentioned,
- [function objects](https://en.wikipedia.org/wiki/Function_object#In_Julia) (functors),
- a `struct` containing a [function, its arguments and keyword arguments](https://pbayer.github.io/DiscreteEvents.jl/stable/events/#DiscreteEvents.fun)
- or a combination of the above.

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](https://discourse.julialang.org/t/world-age-problem-explanation/9714)).

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