Node vs python for creating RESTful webservices [

2019-03-08 02:02发布

I am creating REST APIs backend for mobile apps. I have difficulty deciding between Twisted matrix in python and Express Framework in Nodejs.

I have gone through several references:

  1. Python REST framework recommendations
  2. Tech stack for Web+mobile apps
  3. Best language/framework for REST APIs

Like every other kid on the block, I too have same requirements:

  1. Easy to maintain.
  2. Scalable to large traffic.
  3. Should support MongoDB / NoSQLs
  4. Should be secure and easily authenticated.
  5. Other standard requirements for webservices.

I understand the facts:

  1. "Its the solution that scale, not the technology."
  2. A good solution on any technology will be successful.
  3. Most technology stacks have some big success stories to boast.

Still if I have to choose one technology stack over the other, what should it be? On one side, Nodejs offers native async and non-blocking I/O features. But twistedmatrix has some seriously large success stories in its kitty. There are other frameworks also possible in python and other languages. Other suggestions are welcomed as well.

My specific question is: I plan to use Twisted Matrix in python for building RESTful API. As I have prior experience in python and django, and the code is very neat. Is there any killer reason that I should go with Node or other tech stack?

Please do not involve extended discussions.

ps1: To give some idea about the mobile app, its into large scale messaging based on geo locations. The REST APIs will have to deal with spatial calculations.

ps2: I am ready to take leap of faith.

3条回答
等我变得足够好
2楼-- · 2019-03-08 02:08

Considering all that you have stated in your question, and you are willing to take the leap of faith. I think I have the answer :

  • Myself being a python-django developer, I won't prefer python in the first place because of the problem that you are dealing with.

  • In a geo application that will be a part of a very big system, you will have concurrency and optimization issues the moment you end up implementing the first phase of your application.

  • I think you should go for node.js with no doubts in mind [It might take time to implement it but will be the best solution], here is why :

    • It inherently due to design of javascript solves most of the performance issues that you will face.
    • You will not need any proxy server like nginx to serve it, it will again save you the overhead.
    • It works really well with mongo db that again serves as a great cache backend.

    • You can achieve performance equivalent to nginx with a 10 line Web-Server in node.js.

In a nutshell, Python works synchronously by design, and tornado and Twisted allows it to go async with tricky threading - Why not choose a technology which inherently comes with solution to the very problem that you are targeting ?

Its true that I won't prefer node.js upfront for a website development considering the developer's productivity. But I would say we should use node.js where it really solves a problem i.e. come as a solution then a technology (as you quote in your question).

Its a question like why use a nosqldb when you have a great relational database like postgres ? You know the answer you can-not do stuff with postgres that you can do with nosqldb like mongo and vice versa.

So, your problem area is native to node.js so there seems no point of trying to re-invent the wheel with python.

Considerations :

  • You will face initial friction with node.js since its a new technology to you.
  • javascript can be harder to maintain for a python developer initially.
  • Leap of faith is a must since you target long-term goals with this, rather then short term benefit of saving time on tried and tested technology.

As an Example :

  • Facebook uses php for all its webpages, but it uses the inherently concurrent erlang for its chat.
  • Considering erlang would have been more logical then considering python emulations.
查看更多
萌系小妹纸
3楼-- · 2019-03-08 02:22

Your question largely hinges on sub-questions that aren't purely technical, since in purely technical terms there's very unlikely to be any real performance difference between your two proposed solutions. The questions you need to be asking are along the following lines:

1) Which language do I have the most experience with?

2) Which language am I more comfortable writing in?

3) If I were to bring more people onto the project, how would they answer the previous two questions?

4) Which language has better/more comprehensive libraries for handling the common tasks that will arise in my project?

5) Which language/environment is more likely to be found/easier to set up in most hosting environments that I'd consider for my project in the early stages.

Don't even think of asking yourself "which technology stack would be best if my project became the next Facebook?". IF you're ever lucky enough to reach that point, you won't be using the same tech stack you started out with. Do not try to optimize prematurely.

查看更多
不美不萌又怎样
4楼-- · 2019-03-08 02:31

You should also consider the fact that if you go with Node, you'll be able to use the same language in both server side and client (if needed) which can be a huge plus. When you gain experience in JavaScript, in this case, both sides of your project will benefit.

查看更多
登录 后发表回答