Is Python Really Scalable?

Bobby
Bobby
Mar 30, 2019 · 5 min read

Python is one of the most popular programming languages as of 2019. Python is a very powerful programming language. It is, however, not perfect. There are a lot of articles and discussions about the limitations of Python. One of the most discussed limitations is scalability. Is it true that Python is not scalable and is it a bad choice for developing enterprise applications which require high scalability? In this post, I will walk you through this question.


What is Scalability?

Scalability is the capability of the system, process, application or network to handle a growing amount of work, or system’s potential to expand itself in order to handle that growth.

Scalability is viewed from two different angles: (1) machines — how the system behaves when the system usage increases and (2) humans - how the system behaves when the development team grows.


Machine Scalability — Performance and Speed

In most cases, scalability is viewed as how much load system can bear at a time (machine scalability). In that sense, Python is less scalable in terms of performance and execution speed than other programming languages like Java and C++ because of several reasons discussed below.

Scripting Language — Slower

One reason for Python being slower is that it is a scripting language. Most scripting languages usually perform slower than programming languages. So does Python.

Unlike programming languages like C and C++, with which the source code is compiled directly into machine code, Python is simply plain text, which requires being interpreted at run time. With Python, each code line may require some hundreds of programming instructions to execute, in a dual stack, recursive descent parsing algorithm.

No Multithreading Support

Multi-threading in Python is not robust at all

As mentioned above, scalability means the system’s capability to handle a growing amount of work, in other words, an increasing number of requests. Now, one technique which is really useful to make applications scalable is multithreading. Multithreading is the technique in which we divide program or process into multiple threads which run concurrently, hence providing a significant amount of speed in the applications.

Programming languages like Java offer much more robust support for multithreading than Python. This is because Python uses GIL (Global Interpreter Lock) which prevents Python interpreter to perform multiple tasks concurrently (means doing multitasking) and enforces it to run only a single thread at a time. Python language has its own reasons to use GIL but it does impact on the performance of the application. This multithreading support is also the reason why Java is more popular in enterprise applications as compared to Python.


Human Scalability

Another side of the scalability is human, which is about the situation when the development team grows in size or when the number of code changes done by developers in a system. If we compare Java to Python, then Java’s static typing comes in handy while scaling the system in terms of adding more features (lines of code). As Java is a more verbose language with strict rules of coding and also consists of a type safety system which produces fewer errors at runtime, Java allows the system development to grow at high scale smoothly (in terms of lines of code).

Python, on the other hand, is a dynamically-typed language. This feature does not suit well when the team grows or the lines of code increase significantly, as developers find more runtime errors. The system, therefore, becomes complex and hard to maintain at a high scale.


How To Overcome Scalability Limitations in Python

After knowing all of the above scalability issues found in Python, you would be wondering why should you pick Python language for your project as it has several scalability issues, or why Python is still used by many large companies in large projects. It’s because there are several solutions to these limitation issues.

Using Python Implementations

Using Python with C-like performance is totally possible. This goal can be achieved with CPython, which is a superset of Python and also includes some features of C, in which Python code is written.

Another well-known Python implementation is Jython, which is designed to compile Python code to Java bytecode. Thanks to this implementation, we can take advantages of Java virtual machine and Java libraries. Thus, Python can have the same scalability and performance boost as Java.

Horizontal & Vertical Scaling

We can solve the problem of scalability in terms of handling the growing amount of work by performing horizontal and vertical scaling properly, which is done at the hardware level.

This particular process of scaling has two types: vertical scaling and horizontal scaling. Vertical scaling is the process of adding more memory, disk space, and CPUs to the single machine. Though vertical scaling will eventually hit its limits depending on the machine or server that how much it can support. In that case, we should apply horizontal scaling which is the process of adding entire machines or servers to the system in order for it to handle more throughput.

Better architecture

Essentially, scalability is not the problem within the language itself but it depends on (in some aspects) decisions taken at the design and architectural level in the development process. The architecture should be designed in such a way that it has the flexibility to grow or scale. Many optimizations can be done in the early phase of the projects. For example, Nginx for static and apache for dynamic content, using CDN for static content, Proper use of vertical and horizontal scaling, and Load balancers and auto-scaling features.

Does Scalability Only Thing That Matters?

Scalability is surely the main factor which should be considered when developing large applications. But, there are several important factors which should be taken into account like programming language productivity, ease of use, ecosystem, support, and tools.

Regarding productivity, Python is slower in terms of performance and speed but it provides much flexibility and requires very fewer lines of code for same tasks that require much more lines of code in other languages like Java. So, Python allows developers to develop applications more quickly.

Additionally, Python language is very easy to learn and use as compared to languages like Java which require a significant amount of time to learn in order to be used effectively in application development.


Final Thoughts

Python does have scalability limitations. However, it is still used in many famous projects, such as Youtube, Pinterest, Reddit, Dropbox, and Quora were built on it. As every programming language has its own advantages and disadvantages. It depends on us that which language we choose that overall suits our needs.

To cope with the scalability limitations of Python, there are several solutions:

  • Using Python implementations such as CPython or Jython to reach C-like performance and take advantages of Java;

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade