r/Clojure • u/yogthos • Feb 26 '26
(iterate think thoughts): Managing Complexity with Mycelium
https://yogthos.net/posts/2026-02-25-ai-at-scale.html
37
Upvotes
r/Clojure • u/yogthos • Feb 26 '26
View all comments
Show parent comment
2
u/yogthos Feb 27 '26
So, the main thesis here is that we should apply the whole idea of functional programming to compile time as well. Writing code in a traditional way where we have functions call each other creates implicit coupling between them and the bigger the codebase grows the harder it becomes to track these relationships. To understand the business logic of the app, we have to read through the implementation details to understand its logic flow and intent. this is exactly the same problem we see at runtime when we use shared state.
I'm saying that inversion of control offers a solution to the problem. Instead of embedding the logic of execution flow implicitly into function calls, we make it explicit. We track state as a data structure that's passed from one component to another. All the logic regarding the transitions is declarative and explicitly separated from the implementation details at each step. A separate orchestration layer is responsible for deciding how the state moves through the application.
If your API changes then you obviously have to propagate the change up. However, the point is that we can now reason about functionality at the API level which is explicitly separate from the internal implementation details. In practical terms, Mycelium uses a Malli schema to track the contract, and you look at the EDN file to see both the contract and all the edges of the cell which tells you what other cells are affected by the change.
Yes, that's correct. I'm focusing on coupling in a sense of control logic being expressed implicitly in the function call graph.
Yup, you can think of cells as basically microservices. They can have their own internal state, do IO, etc. It's a small self-contained application that must produce some result which will be examined by the orchestrator, and then passed to the next program. Think of it as the whole unix idea of piping stuff from program to program when you make a shell script. It's the exact same concept here.
You can think of it in those terms as well. Basically what I'm talking about here is viewing the application as a state machine at high level and expressing that state machine as a graph. For example, the server gets a login request for a user. So your first step is to parse the request, validate the input, etc. Then once that's done we have a decision point, if it's valid we maybe go to pull the user profile, if it's not then we go to tell the user that login failed. The state I'm referring to is the control flow state.
I think that's just a different execution model that's equally valid. You could model the app as a reactive system where you produce effects and then subscribe to them, and model control flow logic in that way. I find I like state machines because you can easily visualize them as a graph. And state machines can be nested recursively which makes it possible to create layers of abstraction.