API in Lumen/Laravel, should I port it (or just maintain)?

Earlier on, I have posted to get some directions here

At the end we chose Lumen/Laravel due to that time team’s background experiences on php. No one dared enough to take up the challenge to work on functional language. Our database is MySQL RDS, Nginx as web server and using AWS t2 medium to host it (yeah, we are not that big yet).

2 reasons to consider porting Lumen/Laravel

  1. the current codebase is really spaghetti code. Enhancing is like hacking the code to make it work. Plus the original developer is no longer with us. Painful experience but still work.
  2. have received feedbacks from our current customers (from our mobile app) that the app is slow. Okay this slow is very subjective as it could be the app, internet speed at that time, infrastructure hosting the API or API stack itself. Till now, I have struggled to gauge (or narrow down the cause of slowness). How do you all measure this? Any tips?

But I have some concerns…

  1. lumen (part of laravel) comes with really good pagination support out of the box. It’s like magic and can be easily built. I am not sure whether elixir/phoenix has such capabilities.
  2. lumen/laravel comes with JWT token out of the box too. Auth is plain simple, and with eloquent (laravel version of ActiveRecord) is powerful and easy to use. Not sure about pheonix/elixir.
  3. The challenge i may face is rejection when comes to speed and productivity. Well Golang is really fast … seen benchmarks (well benchmarks can be bias too, but quite a fair big of big companies using Golang to build high performance APIs) … productivity (coding in lumen and laravel — really easy)
  4. even the code is spaghetti, shouldn’t we revamp or rewrite the codebase in Laravel 5.4 (or lumen). After all, the team strength is still on PHP.
  5. How guarantee that the API written in elixir/phoenix can be a lot faster than our current Lumen/Laravel? How can I test between 2 and compare the speed? How do you normally measure such performances? Note, I have used AB (apache benchmark – doesn’t seem to be accurate, hmm…)
  6. As for the API, I am thinking of going to GraphQL than Rest (just planning). Can Phoenix/Elixir support Graphql?

Note:

  • I am thinking to code this port by myself first to compare the speed before pushing this to the team. The reason I am not going with golang route as I really dislike C pointers, couldn’t get that concept to my brain :stuck_out_tongue: and the lang is so boring to learn. Learned a bit on phoenix/elixir (3 days back in Nov), quite fun. But I don’t have ruby background, so watching some of the phoenix/elixir screencasts (which elixir community is really geared to move ruby guys to elixir … some of the ruby terminology is just too confusing for me to grasp)
  • how the market like for developer salary in Elixir/Phoenix? Not sure I read somewhere recently that Golang is the top 1 for highest paid salary developer. Which means there’s a lot of demands on Golang. It doesn’t apply to me, but I want to ensure there’s a good developer ecosystems on phoenix/elixir too.

Mind to share your thoughts on this.

Thanks.

I’ve not used Lumen/Laravel, but used to use PHP extensively due to a very old job (back in PHP3/4 days) so keep that in mind for my responses. :slight_smile:

First, there are a number of plugs in phoenix/elixir that let you put an old API, like yours, behind elixir, so that you can slowly replace it and/or add to it piecemeal over time, so that would be the easiest thing to do first of all.

Second, PHP is slow, Facebook’s php compiler helps, but is still slow. For network traffic anything on the EVM/BEAM should blow those away entirely, especially with the reliability you gain, so your code is likely to not just be a little faster, but a lot faster than what you have now, especially under load you will see anything on the EVM/BEAM blow past near anything else, especially if you tried to build in the same reliability and scaling, and just in leagues above PHP.

Third, the algorithms you use are probably the slowest part of it all, and rewriting in Elixir will help you to rewrite them better, especially due to the change in style (procedural to functional).

For measuring slowness, ask ‘what’ they are doing is slow, measure those paths in your systems via tsung or something testing, put profiling in your PHP code to test, etc… Profiling on the EVM/BEAM is significantly easier than almost any other language as well, can even add it to a running production system.

Also, pagination is not hard, at all, like not even remotely, and yes there are libraries in Elixir to do but I’ve never even thought about needing to look at them.

Phoenix/Elixir supports any auth you want either via libraries or to build it, however yes JWT is supported with ease, the Guardian library is the most popular for that.

Golang is designed for fast network processing, but it is not ‘safe’, it can crash, and it does indeed do so, and since it is imperative procedural code then speed issues in your code are easily hidden. Golang also cannot scale across nodes with near the ease that the EVM can.

PHP, even the latest versions from what I’ve seen, still encourage bad coding practices, so knowing it does not really help, that is why you have spaghetti code to begin with. Immutably functional languages help prevent entire class of design issues just like strong static typing help prevent entire classes of bugs (which Elixir most has via Dialyxer, highly recommended to use).

To test which is faster I’d say put Elixir in front of your laraval and run tests on one of your slow paths, then rewrite that path in Elixir and test it again, you will quite see the different.

And oh Elixir has glorious GraphQL support, I’m quite partial to the Absinthe library, it is also highly recommended! but there is another one too. :slight_smile:

No clue about salaries, I’m not one that is watching that (though others here are, look for existing threads), but I work in Elixir as my day job. :slight_smile:

Also, I did not come from the Ruby world, I came from the (old time PHP,), C++, Erlang, etc… world, Elixir was still dead-easy to pick up. :slight_smile:

But yeah, I’d start with setting up elixir, using the terraform library or whatever the popular library is to forward existing api requests to your laraval instance, then start rewriting them one by one as you learn Elixir. People are wonderfully helpful here so always feel free to ask questions. :slight_smile:

5 Likes

Just a couple of comments:

  1. have received feedbacks from our current customers (from our mobile app) that the app is slow. Okay this slow is very subjective as it could be the app, internet speed at that time, infrastructure hosting the API or API stack itself. Till now, I have struggled to gauge (or narrow down the cause of slowness). How do you all measure this? Any tips?

Are you using NewRelic? If not, why not? :grinning: Even the free version
is super useful for identifying performance problems.

You can also get timing information out of your VPC flow logs. In
fact, I’m working on an Elixir analyzer for that at $dayjob right now.

  1. even the code is spaghetti, shouldn’t we revamp or rewrite the codebase in Laravel 5.4 (or lumen). After all, the team strength is still on PHP.

Maybe you need a new team. Seriously, if all they know is PHP, and
the code is such a mess AND no one has stepped up to refactor it into
a reasonable state – that’s not a good sign. It certainly doesn’t reflect
much in the way of “strength”. And if no one on the team is interested
in learning anything new the company’s doomed anyway…

FWIW,

2 Likes

This is good advice. I’m not saying you need to fire your team, but what I like about this advice is that it takes a sensible look at the constraints you’re working under. If you don’t have a team that can learn Elixir, or a team that can execute well, trying to start from the ground up with a totally new paradigm could well land you in a place even worse than where you’re at.

There are plenty of technical considerations between PHP and Elixir, but it sounds like you have a pretty good grasp of the differences. The decision from here relies entirely upon good judgement given the overall human situation you’re in. It doesn’t matter if Elixir is better if you can’t make it work. At the same time if you’re already at rock bottom, maybe starting from scratch with new people and a new language make sense.

Only you can make this call.

2 Likes

Noted and thanks guys :slight_smile:

1 Like