I’m thinking about writing my first Elixir backend server, and I’ve been wondering if I should use Phoenix or a simple cowboy server for it.
What I’m going to do is have a simple api server which queries a db and most probably would send rest requests to another server when needed (this part of the architecture wasn’t decided yet)
This backend server would have to auth and in the future probably authorize users but it won’t handle the user session.
I wonder if Phoenix would be an overkill for such a simple backend server, as from my experience rails is.
Would appreciate any input.
Phoenix is primarily a set of plugs (and optionally a nice websocket handler) on top of cowboy, it can be as slim as you want it to be, and as such you should use it, just remove what you don’t need from your endpoint if you so wish, and you can grow it later if you need.
Thanks for the super fast reply.
It’s just when using ruby I found out that Sinatra was the best fit for this kind of servers, Rails just requires way too much fuss to make such simple severs.
Guess I’m still thinking ruby.
Yeah, Phoenix is not at all heavy, it is rather very lightweight, especially as you can pretty trivially pick and choose what of it you want to use. The default generated endpoint is showing off a lot of common features (not even all) and those you do not need to leave in if you don’t need them. Like if you don’t need static file hosting then remove that plug call, or if you don’t need a router then remove that call (finish up with a final single plug or so). Etc… etc… You can pick and choose and mix and match what you want.
I’ll take your word and go through it before starting the work on the server, hopefully I won’t have to start with ruby and Sinatra and do a move later, time frame is going to be really short for this project.
Well this is going to be my first experience with Elixir but I’m not afraid to try new stuff.
Already did a move from Perl to Ruby without previous experience with Ruby on a production server.
The main decision maker would be how much time I’ll have for this server, Ruby + Sinatra would require a day or so Elixir most probably a week or so.
First iteration of this server wouldn’t need to be prefect it would just need to work and be secure. In the future it would need to be fast, but that’s a problem for the future;)
So the decision would be time, I do know and expect that in the second stage of this project it would need to be lighting fast Elixir is the perfect fit, and I want to have my first experience with Elixir when I can make mistakes and don’t have to worried about benchmarks.
Go for it it is actually aimed at programmers so you are the target market (It’s just that personally I am the sort of person who likes to read or learn as much about something as I can before jumping in )
As ODL commented, it will be fast from the get go - Phoenix response times are in microseconds
Well that’s why I bought programming elixir, programming Phoenix and functional web development and been browsing the in the last month.
But the sad truth is until you write something you don’t know the language and the first few times you use it, you duck only after a few months of using a language you start to be mediocre (in my case) when using it
Well, I think that I owe you an update here…
The project is now on the first stage unfortunately it started 2 weeks ago or maybe 3 and needs to be up and running in less than 2 weeks.
So I decided to stay with ruby and Sinatra, the good news is that 90% of this project is based on what I learned here and I think of it as the Elixir way(as I see it)
Basically what I’m doing is creating a Json based web services project that uses lots of threads that can always crash and send their state to another server if and when it happens.
I even have a gen server that is responsible of checking loads start and stop every other server, and of course is chosen with each restart.
So I basically wanted to say thanks, this community enriched me more than I could ever imagine, and I’m doing my best to use what I learned here, hopefully stage 2 would be Elixir but if not Elixir then my time here as a silent observer would be my inspiration.
I should have said that my gen server is not going to be even 10% as smart as elixir more in the lines of removing computers from LB and adding them when they are up. (but the idea came directly fro it)
It would also be responsible of running test to make sure that every node is working as it should and every bot is doing what it is suppose to do.
The nodes themselves would be responsible of re-sending failed attempts to the Load Balance and letting the gen server know that they are down when it happens, which would initiate a replacement (shutting down the failed node or deciding the error was acceptable or not)
Well, I would give you one more update now and 2 more one when finished and another when I will finally move to Elixir.
From last week we are up, managed to do it within our 1 month time frame.
So what I have for now 12 computers each can do all the tasks I need.
State is decided by a transferable json, and when a request is failed it is retried and on second fail goes back to lb, second fail sends an error to queue and returns a success to my genserver.
Next stage I would fix 3 things:
Better genserver decision process for now first server started is genserver
Auto version update
Seamless move when genserver fails.
And of course make each node start as a service - yeah I know … but this one was less important considering I needed to get the whole system working.
Next update would hopefully be after everything is working, and in less than 3 weeks, nothing is critical and I do have so many other important things I should do.
Last update would be a move to elixir but that would probably be later than I want
Forgot to say everything is threaded:)