How to choose a Web Framework?
It is very tempting to select a framework based on its popularity - "X language/framework is good. You know Facebook uses it". Understand that Facebook did use an X lang/framework but not for all of their projects, and might not even prefer the same after 5 years down the line. However, what is interesting to know is why Facebook choose that X? Thinking this way would help you choose a better language/framework for your use case.
100$ tip: There is no one size fit for all!
Do you know that some organizations do not even use frameworks but use the language itself to build their entire system and toolchain? I know, it's crazy.
There are multiple factors that derive the decision of choosing the right framework (or language) that starts with identifying the problem statement that your system (or project) is going to solve. In this article, we will look closely at all such factors, and understand how to weigh their pros and cons according to our constraints. For example, constraints could look like,
- I want a good framework for my side project
- I am looking for a language/framework to build a system in my organization that involves high network throughput
- We are an early age startup and need to speed up the development, what could be the right framework for us?
and so on.
⚡️ If you are someone who understands concepts better through a video, then watch the same content over my Youtube. And, it's more compact there.
👉🏻 Language or Framework?
Recommendation: Don't jump to any conclusion before reading all factors.
Framework is built on top of a language. Ex. Django and Flask are frameworks built using Python.
The objective of a framework is to provide the most common utilities and use cases by wrapping the language's native modules and community-supported modules so that developers don't have to do redundant work. Moreover, frameworks always tried to include the best standards and modules. It even establishes opinionated ways like including MVP in its structure. All this is done to increase the developer velocity. However, there is a downside to this - it takes away the flexibility from you, and sometimes performance too.
To get the performance and flexibility of language, one must be willing to put the time and effort to build the baseline structure and tooling. To ease this path, modern-day languages like Go has made sure that their native library and toolchain is so versatile that there is no need for a framework.
👉🏻 Problem Domain
The most crucial step is to identify your problem domain. As an example, let's take the following 2 domains (one more covered in the video).
To get the best results in the Data domain, one should either prefer Python or Go. Python has great community support and ever-growing libraries that are all you need. If something is not solved, the language provides you standard ways to build your own library. Additionally, Go is becoming a popular choice for the Data domain because of its impeccable performance results, however, the library support from the community is fairly less than Python.
If you are building a system that is going to be network intensive then you should pick a language that is light and provides a high network throughput. Statically typed languages are always going to have an uppercut here. Additionally, languages that make the best use of OS resources will give the best result here. So, Rust and Go are two popular choices in this domain. Although, Nodejs also shows great results to an extent.
There are more granular domains, and the thinking process should be to first identify the domain and not jump to a framework (or lang).
The higher the opinionated nature, the lower the flexibility of the framework. To an early stage organization and business, a framework is always preferable as it provides the basic utilities and structure increasing developer velocity. Often businesses can stake the flexibility in their early days as they want to ship fast.
If you are building a side project, either go for a raw language or for a framework that is flexible enough and allows you to play with native modules. Implement the community standards by yourself, learn every bit of it.
This factor makes more sense when you are building a system at scale. Considering the two classes - language and framework, language is always going to be more performant than its corresponding framework. If we go deeper into language, the statically typed language is then going to be more performant than dynamic languages. Additionally, it depends on how well a language uses the system's resources - cores, memory, etc.
Here is a list of more than 200 frameworks with their benchmarking results. You will be surprised to see that popular frameworks like Express, Sails, Rails, Django are far below in the chart, and languages like Go, Rust, JS, and their frameworks are topping the charts.
However, one should not go blindly towards performance and leave other factors aside. So, frameworks like Koa, Hapi, Fastify.js (in the middle order in the list) bring you the best of both worlds - performance and developer velocity.
👉🏻 Learning Curve
In today's agile working culture, no developer or organization wants to spend months learning a language. This is the reason why dynamic languages are gaining popularity. Python, Nodejs, etc are the languages that are easy to get onboarded to. As we go deeper into these languages the learning curve increases exponentially but that is something everyone is willing to abide by.
At the same time, one loses the performance of statically typed languages. And this is where Go jumped in. It is the only static language that has the smoothest learning curve and also provides great performance because of its concurrent design model.
👉🏻 Community and Tooling
I have used this throughout the article because this contributes to the highest. Without good community support, no language or framework can survive. Languages, their design, the libraries built using them are battle-tested by thousands of engineers. Community hustles to make the entire ecosystem of the language to be production-grade. The community makes sure that the language or framework is compatible with other platforms. Always pick a language or framework that is supported and actively maintained by the community.
👉🏻 Technical Expertise
This factor is to acknowledge your constraints. Engineering teams put a lot of effort into building internal libraries and tooling using a language/framework. The longer the teams work on a specific language, the greater the team's knowledge base becomes and no team wants to lose their hard-earned technical expertise. Switching to an altogether new language or framework might not be a feasible step. Usually, any team has a set of 2-3 languages that they prefer for their projects. You have to weigh the other factors under this restriction. None the less, you can always bring a new language to the engineering team if you can prove its pros being far better than the existing stack.
I hope all these factors makes sense to you. Feel free to start a discussion in comments section. If you are shy, my DM is open on Instagram.