Hacker News new | ask | show | jobs
by luftbbb 1806 days 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?
3 comments

We'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.

agreed 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.
At 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.
could 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!
This 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.
You 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.