Ep 121: Current Events
► Play EpisodeEach week, we discuss a different topic about Clojure and functional programming.
If you have a question or topic you'd like us to discuss, tweet @clojuredesign, send an email to feedback@clojuredesign.club, or join the #clojuredesign-podcast channel on the Clojurians Slack.
This week, the topic is: "making sense of the outside world". We take snapshots of the outside world, but it won’t sit still.
Our discussion includes:
- More pure data models
- Tracking the state of the outside world
- Ingested model vs a state tracking model
- Polling artifacts
- Using event sourcing for consistency
- Designing a system to have its state monitored
- Real-world testing
- The language of the application
- What matters to the application
Selected quotes
Pure data models are the heart and soul of your Clojure program. They have the essential representation for what really matters. We like pure data models because they're easy to test, easy to use and understand, and easy to visualize.
Our software interacts with the world. The world is stateful. State is everywhere.
The state tracking model is for when there's some computing happening outside your application and you need to know about it.
You sense the change, you figure out what's different, and then you update whatever local state you have.
Your application probably isn't interested in the entire external state, but whatever it is interested in, it needs to be able to tell if that changed externally so that it can update it internally.
The goal is to assemble a cohesive view from pieces. You have to build into your model the idea of being able to handle inconsistencies, not only between different sides of the communication, but also the data and itself, temporally.
Event sourcing is going to be more consistent than polling because if you get all the events, then you can be assured that you know everything that happened in the external system.
It's very useful for us to track an external state of something and and react to it in some way or visualize it in some way. That's the whole point of this.
We're making an ingested model so we understand what information matters from that external system. We may not want to track all of it. We may not want to track it in general. We want to track what matters to the application.
We're representing the whole thing as a pure model, and because it's a pure model, you can thoroughly test and handle all the scenarios for all the different events and what their resulting state should be. You can test that extensively.
You can write actual event logs, that come from the real thing, down on the disk, and you can play them back again through your pure model. You can even do regression testing that way. You have a powerful approach to tracking external information, external state.
All the different kinds of functions that go into data model, because they're all defined in that central data model, have a coherent language among them. It's the language of your application.
The point of this series is we want to be able to understand systems we go back into, so if you are going back into a system, go look at the data model.
The pure model, and the unit tests around it, explain what matters to the application about the outside world. That helps you frame your ideas of what is important and what information matters to this application as a whole.
When I think of state, I tend to not think pure, at least until Clojure, right? Wait, what's the point of state if you can't change anything? Immutable representations of changing state! Got it.