Node vs Python

Thu, 31 Jan 2019


Over the course of the next few sections, we will explore some important elements that will help us better understand the differences between Python and Node.

Part 1: Learning Curve

Before we begin let’s first clarify; Python is a programming language while Node.js is a framework that is based on the language Javascript.

What does that mean for Node? It means we can use Javascript both on the frontend (React.js framework) and backend of our application. The benefits of this include:

  • Most developers have at least some experience in Javascript, so working in Node.js would be familiar
  • In the case of an emergency fire, more developer could hop on to support
  • Code can be re-used on both sides of the application, or in the very least demonstrated and understood by both parties.

However, although Node is easy to learn, it is very hard to master. From understanding asynchronous behavior to complex error handling there are many concepts that, without good understanding, can result in application slowing consequences.

Python, on the other hand, is the most popular introduction language in the United States, and for good reason. It’s clean easy to read syntax lets developers get the job done with fewer lines of code, and it’s strong community provides many introductory resources.

Part 2: Project Size & Coding Standards

As a project scales up in size (of the codebase) more developers will touch the codebase and cycle through. As a result, having a coding standard is essential to ensure new developers can understand and contribute quickly to a growing project.

Node does not have clean coding standards. In node, we can do the same thing in many different ways. As a result, to build out a larger project in Node, it would require a more expert team, that can collaborate in a disciplined manner. Furthermore, javascript is developing at an exponential rate, with over 500 new “and improved” libraries coming out each day, and constant depreciation. This rapid growth has resulted in poor documentation, and consequently poor quality Node code. Developers must make a conscious decision when selecting which of these many simple, single-purpose libraries and micro-frameworks to use. Also, with Javascript being a frontend language initially, many solutions available may be inadequate for backend use.

Python, on the other hand, is much safer for a large project, with well-defined standards and established conventions (based on single implementation; CPython), It is a much older language with much slower (sometimes too slow) changes. The benefit of this is much more stable releases, accompanied by much better documentation. There backward support it also much strong (i.e. ee still have support for python 2.7 features). The concise and expressive syntax makes it easier for others to maintain and enhance a python based application. Furthermore, the rich standard/native library for server-side development is one of the main strengths as functionality comes inbuilt (as well as providing an extensive ecosystem of modules to choose from if needed).

For small scale projects (i.e. micro-services) and functionality does not require a large amount of scripting, this will not be a concern. Furthermore, a lack of coding standard also equates to greater flexibility. Many available Node packages are simple, single-purpose libraries and micro-frameworks; this forces developers to make more conscious decisions what to use and when.

Part 3: Debugging

Debugging in Node is much more difficult, and take much more time than in python. Errors are passed around in promises making them more difficult to catch. Furthermore, the language itself does not flag errors when run. For example, if we call a function with missing params (they get the value undefined) whereas python would throw an error.

Part 4: Speed and Performance

Python is an object-oriented, high level, dynamic and multipurpose programming language. Python’s syntax and dynamic typing with interpreted nature. It supports multiple programming patterns, including object-oriented programming, functional programming, or procedural styles. Moreover, it an interpreted language which means it cannot convert to computer-readable code before it runs at runtime.

Node is an open-source, cross-platform, powerful run-time environment that’s built on the V8 engine. It is single-threaded with an event-based architecture and non-blocking I/O that helps it to maximize the usage of CPU and computer memory. This event-driven architecture is based on asynchronous calls that allow the Node.js servers to process more concurrent requests as compared to the multi-threaded servers. As it’s non-blocking I/O do not block program execution under I/O-heavy workloads, thereby improving the Node application runtime performance. In addition, there is no buffering in Node as applications output the data in pieces. These factors, in turn, make Node servers faster and productive and also provide the fastest server-side solutions. This great performance is largely due to Node being based on Chrome’s V8, which is a very fast and powerful engine.

Node is much less performant when it comes to CPU-intensive operations are concerned (such as generating graphics or resizing images). A possible workaround would be creating a task queue to manage CPU intensive requests exists, but it requires spawning additional workers and introducing new layers to our Node application. Python is more suited for such applications. However, Python is high unsuited for memory intensive processes, as it is interpreted, whereas Node is much stronger.

In the case of speed and performance, Node wins hand down. However!!! We must understand what we value when building out this application; CPU time or developer time. The biggest con of a micro-service is its performance, but the greatest pro is it’s time-to-market. By taking on this micro-service model we are choosing to build teams around smaller projects and codebases to iterate and innovate at a much faster pace. As a result, we must ask ourself if we want to choose a language that reflects a similar value set.

Part 5: Scalability

When we look at scalability, we are trying to understand how effective the language is in handling large user traffic and how they can be handled using the minimum server.

Even though Node.js is a single-threaded solution, its standard library provides modules that support high scalability. Node clusters and workers are abstractions that can spawn additional Node.js processes depending on the workload of your web application. Limited only by the number of CPUs, you can easily scale your Node applications to fully functional enterprise solutions.

On the downside, complex apps with a lot of concurrent processes need in-depth knowledge, attention and careful research, when we seek to scale. Python, which does not support asynchronous programming by default, does this more naturally and makes code complex projects easier.

Part 6: Applications

Python has a very broad set of applications. It is the leading language for machine learning and big data solutions, and is great for developing scientific applications, government projects (Due to the stability), scripting, desktop apps (i.e. dropbox), web applications, integration with back-end applications, network programming… it goes on!

Node on the other hand is designed primarily for web development. In particular, it is the ideal solution for developing Data Intensive Real-time Applications (DIRT), I/O bound Applications, JSON APIs based Applications. It is also useful for developing heavy-load applications and e-commerce sites that depend on the speed of processing.

Stephanie Mills

Stephanie Mills

Living to learn. Designing to disrupt. Coding to create

  • Learning. Laughing. Coding. Creating.