用于创建 RESTful Web 服务的 Node 与 Python [英] Node vs python for creating RESTful webservices

查看:41
本文介绍了用于创建 RESTful Web 服务的 Node 与 Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为移动应用创建 REST API 后端.我很难在 python 中的 Twisted matrixExpress 框架在 Nodejs 中.

我参考了几个参考资料:

  1. Python REST 框架建议
  2. 网络+移动应用的技术栈
  3. REST API 的最佳语言/框架

和街区里的其他孩子一样,我也有同样的要求:

  1. 易于维护.
  2. 可扩展到大流量.
  3. 应支持 MongoDB/NoSQLs
  4. 应该是安全的并且易于验证.
  5. 网络服务的其他标准要求.

我了解事实:

  1. 它是可扩展的解决方案,而不是技术."
  2. 任何技术的良好解决方案都会成功.
  3. 大多数技术堆栈都有一些值得夸耀的成功案例.

如果我必须选择一种技术堆栈而不是另一种技术堆栈,那应该是什么?一方面,Nodejs 提供原生异步和非阻塞 I/O 特性.但是twistedmatrix 有一些严肃的它的kitty 成功案例.在 python 和其他语言中还有其他框架也是可能的.也欢迎其他建议.

我的具体问题是:我计划在 python 中使用 Twisted Matrix 来构建 RESTful API.因为我之前有 python 和 django 的经验,代码非常简洁.我应该使用 Node 或其他技术堆栈有什么致命的理由吗?

请不要进行冗长的讨论.

ps1:为了提供有关移动应用程序的一些想法,它包含基于地理位置的大规模消息传递.REST API 将不得不处理空间计算.

ps2:我已准备好接受信仰的飞跃.

解决方案

考虑到您在问题中陈述的所有内容,您愿意接受信仰之跃.我想我有答案:

  • 我自己是一名 python-django 开发人员,首先我不会因为您正在处理的问题而更喜欢 python.

  • 在将成为大型系统一部分的地理应用程序中,当您最终实现应用程序的第一阶段时,您将遇到并发和优化问题.

  • 我认为你应该毫无疑问地选择 node.js [实施它可能需要时间,但将是最好的解决方案],原因如下:

    • JavaScript 的设计本质上解决了您将面临的大部分性能问题.
    • 您不需要像 nginx 这样的代理服务器来为它提供服务,它会再次为您节省开销.
    • 它与 mongo db 一起工作得非常好,再次作为一个很棒的缓存后端.

    • 您可以使用 node.js 中的 10 行 Web-Server 获得与 nginx 相当的性能.

简而言之,Python 按设计同步工作,tornadoTwisted 允许它通过棘手的线程处理async - 为什么不选择一种天生就可以解决您所针对的问题的技术?

考虑到开发人员的工作效率,我确实不喜欢将 node.js 预先用于网站开发.但我想说我们应该在 node.js 真正解决问题的地方使用它,即作为解决方案出现,然后是技术(正如您在问题中引用的那样).

当您拥有像 postgres 这样出色的关系数据库时,为什么要使用 nosqldb ?你知道你不能用 postgres 做的事情的答案,你可以用 nosqldb 做的事情,如 mongo,反之亦然.

因此,您的问题区域是 node.js 原生的,因此似乎没有必要尝试使用 python 重新发明轮子.

注意事项:

  • 您将面临 node.js 的初步摩擦,因为它对您来说是一项新技术.
  • javascript 最初对于 Python 开发人员来说可能更难维护.
  • 信仰的飞跃是必须的,因为您的目标是长期目标,而不是在久经考验的技术上节省时间的短期利益.

例如:

  • Facebook 在其所有网页中使用 php,但在聊天中使用固有的并发 erlang.
  • 考虑 erlang 会比考虑 Python 模拟更合乎逻辑.

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.

解决方案

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.

这篇关于用于创建 RESTful Web 服务的 Node 与 Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆