5 ms·
How does one actually architect a functional service, regardless of language? Is it a traditional 3 tier approach with controller, service persistence or someth
by luftbbb 5y ago
How does one actually architect a functional service, regardless of language? Is it a traditional 3 tier approach with controller, service persistence or something more... Functional?
- flylikeabanana 5y agoAt least in my corner of FP (Scala) my preferred functional architectures are vertically-sliced modules further decomposed into data types and algebras/interpreters. I might have an `EdgeAlgebra` and a `PersistenceAlgebra` for said module, but not always.
- luftbbb 5y agoThis sounds interesting, though I'm not quite grokking the vertically sliced modules aspect. Maybe you could explain it a bit more in detail, or link to some diagram or code repo, would be awesome.
- fancyants 5y agocould you perhaps expand on vertically sliced modules, what does that mean? do you have any diagram or code we can reference to get a clear idea of the concept behind the words. thanks!
- bontaq 5y agoWe've come around to something like the "imperative shell, functional core" pattern. All the business logic is purely functional (so no database calls or side effects), and any data needs are done as close to the edge of the system as possible. You can do it in any language, FP languages can help enforce the distinction. For going even more functional, in FP languages that support it, free monads and effect systems allow you to define interpreters for effects and you can write code more or less like you would non-functionally, but the interpretation can be pure (say hardcoded results for a query) for tests, and impure for actually running. Basically fancy dependency injection, but for everything.
- luftbbb 5y agoWhen you say imperitave shell, am I correct in interpreting this shell to be the external interfaces to other systems - both incoming and outgoing eg api and dB layers? At this juncture you'd then take the data and process it in the domain core functionally? It seems like a plausible solution but it is not purely functional which leaves my question open.. How does one do it purely functional? By going "more functional" with the free monad and effect system approach, do you mean the Result design pattern as seen in rust and F#? If you have any working example I can dig in to that would be welcome
- ledauphin 5y agoagreed on IS/FC. and though I've not yet had the opportunity to use "proper" effects, I've ended up writing some micro effect systems that apply to specific systems we interact with a lot. it makes testing and reasoning about the system so much saner.
- xupybd 5y agoYou might be interested in reading Domain Driven Design Made Functional and Clean Architecture. After reading these two books I realized good application architecture shouldn't change much between functional and OO languages. I could be wrong but I think an onion or clean architecture solves any issues you would have.