A good framework is every developers dream. It helps automate the implementation of common solutions, while also cutting time of development to allow developers to focus more on working on application logic instead of routine and other unnecessary elements.
A good Python framework is no different. Depending on the size and complexity of the project, selecting the right web framework for python might just help eliminate most of the stress involved. If you are working on a large system that has a lot of requirements and features, then you might need to get a full stack web framework.
However, if you are working on a simpler and smaller project, then the use of a micro-framework is in order. Note that this does not mean that one web framework is better than the other, but they are unique by design and useful for different purposes.
There are many types of Python framework that can be used depending on the type of project. Some of them include: Django, Flask, Pyramid, Web2py, Bottle, CherryPy. In this article, we will focus more on two of these web frameworks: Flask and Bottle is a microframework to check if they are scalable for use.
Flask is a Python web framework which was inspired by the Sinatra ruby framework and is available under the BSD license, while Bottle is a microframework which helps implement everything in a single source file.
For web applications, scalability means two things:
- The ability of the application to respond to all requests even if it becomes very popular and the number of users and requests goes up exponentially (by a factor of 10^x)
- The ability of the web framework to accept more features (as many as possible) when you come up with new ones. If the code is affected by the addition of one feature, then it is not scalable.
Now that we understand what scalable means in this context, let us see how both frameworks act in response to these two meanings.
Scaling the app to handle more users/requests
It doesnt matter if it is flask or bottle, what you need to do in this case is not to reprogram your application to be able to deal with more users or requests, what you need to do is to reprogram other things around the application.
You can use FastCGI to help your application start up as many instances as possible or required, so that it can handle more requests.
Scaling the app to accept more features
Flask comes with some wonderful tools to help scale. There is a tool called Blueprints in Flask that helps you to modularize your code so that you can put them in largely independent chunks when your codebase grows and you have to add more lines of code. This tool also gives you the option of white-labeling and customizing your app for many customers.
Bottle also comes with a lot of tools that can help it scale to accept more features so that your existing code is not affected by the addition of these features.
Top comments (2)
Good job addressing feature scaling.
But what about request scaling? What does a flask/bottle app architecture look like when it is handling 100K requests per minute? Is one server with FastCGI all that is needed?
Flask can scale to larger size, some examples include Twillio and Pinterest. With 100K requests a minute you would want to setup a CDN and other config. The easy way is to host on a cloud like PythonAnywhere that takes care of everything for you