18 Reactive and onion architectures
In this chapter
- Learn how to build pipelines from actions using reactive architecture.
- Create a common mutable state primitive.
- Construct the onion architecture to interface your domain with the world.
- See how the onion architecture applies at many levels.
- Learn how the onion architecture compares to the traditional layered architecture.
We’ve learned quite a lot of applications of first-class functions and higher-order functions throughout part 2. Now it’s time to take a step back and cap off those chapters with some talk about design and architecture. In this chapter, we look at two separate, common patterns. Reactive architecture flips the way actions are sequenced. And the onion architecture is a high-level perspective on the structure of functional programs that have to operate in the world. Let’s get to it!
Two separate architectural patterns
In this chapter, we’re going to learn two different patterns, reactive and onion. Each architecture works at a different level. Reactive architecture is used at the level of individual sequences of actions. Onion architecture operates at the level of an entire service. The two patterns complement each other, but neither requires the other.
Reactive architecture
The reactive architecture flips the way we express the order of actions in our code. As we’ll see, it helps decouple cause from effect, which can untangle some confusing parts of our code.
Onion architecture