sweeetland
Hi guys, I’m new to Elixir and my background has mainly been focused on JS & Node. I am not entirely happy with the Node ecosystem
and for my next side project I’m looking for a stack that is productive, but also performant. Hence my interest in Elixir and Phoenix.
I’m currently going through Dave Thomas’s course Elixir for Programmers and he recommends against using Phoenix as a full-blown kitchen sink web framework ( à la Ruby on Rails). He states “A pure web interface has no need of a database—all persistence work should be performed in services. I strongly suggest you fight the temptation to stick everything in the Phoenix app.”
And given his reasoning, I’m inclined to agree. I can see how building code into separate, well-defined applications would probably lead to better maintainability and scalability. But, how would this impact productivity? Is this approach likely to slow you down do you think?
I just wondered what other people’s opinions are on this matter. How are you using Phoenix? Thanks!
Trending in Discussions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hauleth
In my side project Phoenix is just simple and small part of the umbrella that is only responsible for HTTP requests. Even more - I have 2 separate Phoenix applications that are then joined together into single “endpoint” where one application is responsible for public HTTP API and second one is responsible for application UI (via LiveView). In that way the logic is in completely separate application and doesn’t “know” about the HTTP or any other transport protocol at all.
sweeetland
Oh cool that’s a really good idea. One thing I like about using SPAs (at work) is the separation of concerns between the client and server. This seems like you get that separation, without a lot of the added complexity that comes with SPAs.
What made you choose that approach? And have you experienced any disadvantages? Sounds like it would take a little bit more time to put together?
hauleth
Not really, it just required some knowledge how to write “custom” Plug handler to handle sockets. However in the end that was not that hard and in total is less than 300 lines while most of them are copied from the Phoenix Cowboy handler:
And then “root” endpoint:
Which also uses some custom plugs before it even reaches “main” handlers:
Server-Timingdimitarvp
And I am very inclined to disagree. Depending on if you are Google scale or not (and I strongly doubt you are) having a monolith where you have tight code control is the optimal solution. You can either use the Elixir umbrella project structure as @hauleth suggested or, as I do recently, just isolate the project’s different responsibilities in different coding directories –
lib/yourapp_webfor your Phoenix stuff andlib/yourappfor basically everything else. You can do it even more fine-grained and have something likelib/yourapp/domainfor business logic,lib/yourapp/dbfor DB-specific code etc.The sky is the limit.
Dave Thomas is an amazing teacher and I have deep respect for him. Amazing teachers shouldn’t be replacements for thinking for yourself though.
Coding monoliths are quite fine 90% of the time.
hauleth
Not only fine, but are the best solution. All big companies started with monolith that was later split into micro services. Starting with micro services is IMHO the worst thing possible, as you will never know the boundaries beforehand.
AstonJ
Welcome
There are some great discussions surrounding his thoughts, you can view them at the course’s tag: elixir-for-programmers-course
There are three common ways to use Phoenix imo:
How you use them depends on your specific needs for the app, whether you’re focusing on speed of development, how ambitious the project is, etc.
It’s awesome that Phoenix is the flexible
(I wonder if we should do a poll on this
)
sweeetland
Yeah, even google has a monolith. I don’t think Dave is advocating for a micro services approach per se, at least my interpretation was that he would still suggesting a monolith (all in one repo). But one separated into small elixir applications and using Phoenix to handle http traffic and displaying views etc…
I’m not sure what’s different about your approach compared to Dave’s? I think I’ve quoted Dave out of context and it may have caused some confusion.
I agree!
sweeetland
Thank you and I’ll be sure to check them out.
Yeah that is really cool.
Sounds good, how do we do that?
axelson
Another option to keep an eye on is GitHub - sasa1977/boundary: Manage and restrain cross-module dependencies in Elixir projects · GitHub it helps you enforce which modules in your application can call which other applications. It’s good because often separating your code into separate applications is too crude of a tool and you end up with inflexible boundaries.
cnck1387
I haven’t read the book so I don’t know what he’s talking about exactly or how up to date the book is.
But maybe he’s talking about keeping your business logic outside of the web related bits of a Phoenix app, which would be considered a good idea. But you can still have a single app project that happens to use Phoenix and your DB related code could live in contexts (which is like your public API for your business logic that your controllers can call).