18 Reactive and onion architectures

 
Image

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.

Image

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.

Image

Onion architecture

Coupling of causes and effects of changes

What is reactive architecture?

Tradeoffs of the reactive architecture

Cells are first-class state

We can make ValueCells reactive

We can update shipping icons when the cell changes

FormulaCells calculate derived values

Mutable state in functional programming

How reactive architecture reconfigures systems

Decouples effects from their causes

Decoupling manages a center of cause and effect

Treat series of steps as pipelines

Flexibility in your timeline

Summary

sitemap