# Server-side

## Web API (when choosing SPA & Web API)



If you chose to go with a single page application (SPA) framework, then the next step is to choose a server-side technology. The standard means of communications are HTTP requests, so the server will provide an HTTP API. This means the server-side and client-side are decoupled. You can also consider using a [RESTful API](https://searchapparchitecture.techtarget.com/definition/RESTful-API) pattern.

There’s an abundance in great server side technologies. This is both a blessing and a curse. There are so many good choices that it becomes difficult to choose. Here are some of the more popular technologies:

* [Node.js](https://nodejs.org/) – JavaScript
* [ASP.NET Web API](https://dotnet.microsoft.com/apps/aspnet) – C#
* Java – [Spring](https://spring.io/), [Jersey](https://jersey.java.net/), [Apache CXF](https://cxf.apache.org/), [Restlet](https://restlet.com/)
* Python – [Flask](https://palletsprojects.com/p/flask/), [Django REST framework](https://www.django-rest-framework.org/)
* [Go](https://hackernoon.com/how-to-create-a-web-server-in-go-a064277287c9)
* Ruby – [Sinatra](http://sinatrarb.com/), [Ruby on Rails](https://scotch.io/tutorials/build-a-restful-json-api-with-rails-5-part-one) – Rails is mostly MVC, but _Rails core_ 5 supports API-only applications.

All of these frameworks are free and most are open source.

This is not an exhaustive list, but those are the most popular technologies. Choosing a popular framework is important. It probably got popular for a reason. A popular framework will have better support, better documentation, and more documented issues. Perhaps most importantly, you’ll find more developers that are familiar with that framework.

Checking market popularity with Google Trends and surveys in this particular category was a bit difficult. Instead, we can see popularity by looking at Tags in [StackOverflow](https://stackoverflow.com/tags). We can see overall usage according to the total number of questions asked. And we can see the trends according to the number of questions asked in the last month. This is not a perfect indicator of popularity, but I think it’s pretty good. Here are the results:

![Backend frameworks trends](https://michaelscodingspot.com/wp-content/uploads/2019/09/so_tags_serverRest.jpg)

**Node.js, for example, has 291K questions, 161K watchers and 5K questions asked this month**

The big 4 winners are **Node.js, ASP.NET, Spring**, and **Ruby on Rails**. Flask, Django REST and GO are much less popular. However, this is not a fair comparison. **Spring, ASP.NET**, and **Ruby on Rails** are primarily MVC and not API-only, so they really have a much lower value. **Go** is a programming language, so it’s overvalued as well. On the other hand, **Django-rest**, and **Flask** are server-side API technology only, so their value is "real". **Node.js** is also not an MVC framework, rather a technology to run JavaScript natively. But, it’s _mostly_ used for Web API with something like [Express.js](https://expressjs.com/) framework.

Keep in mind that even though Node.js is clearly the _most_ popular, the other ones are still extremely popular technologies.

**Java Jersey, Apache CXF and Ruby Sinatra usage was so much lower in comparison that I didn’t even include them in the chart. There are probably hundreds of other lesser known frameworks that don’t appear as well.**

Besides popularity, here are some more considerations when choosing:

* For web applications that provide big-data analysis, consider going with a Python backend.
* Do you want to work with a [strongly-typed programming language](https://stackoverflow.com/a/2696369/1229063) like C#, Java, and Go? Or weakly typed languages like JavaScript, Ruby, and Python? This is a big consideration. Make sure your development team is comfortable with the language.
* With Node.js, you work in the same language in client-side and server-side. I claim that’s way too much JavaScript, but the world seems to think it’s a good idea.
* Which development technologies are more popular in your area of the world? Prefer those.
* If you love C#, but afraid to be stuck with a Microsoft proprietary tech that’s tightly coupled to Windows, then fear no more. The latest versions of ASP.NET (.NET Core) are open-source, work on Linux and have great performance on top.
* If you have a team that’s already experienced with a framework or language, go with their known technology. This consideration trumps all others.

### MVC (when choosing MVC) <a href="#mvc" id="mvc"></a>

Like with Web API, there’s a big selection of server-side technologies that use the MVC pattern. Up to a few years ago, the MVC pattern was by far the most popular way to build web applications. The most notable frameworks are:

* C# – [ASP.NET MVC](https://dotnet.microsoft.com/apps/aspnet)
* Java – [Spring MVC](https://spring.io/), [Apache Struts](https://struts.apache.org/), [Play Framework](https://en.wikipedia.org/wiki/Play_Framework)
* Groovy – [Grails Framework](https://en.wikipedia.org/wiki/Grails_\(framework\))
* Python – [Django](https://www.djangoproject.com/)
* Ruby – [Ruby on Rails](https://rubyonrails.org/)
* PHP – [Laravel](https://laravel.com/)

And here’s the popularity contest results according to Stack Overflow Tags:

![Backend MVC frameworks trends](https://michaelscodingspot.com/wp-content/uploads/2019/09/so_tags_serverMVC.jpg)

**This is a normalized chart. ASP.NET MVC, for example, has 183K questions, 63K watchers and 856 questions asked this month.**

These results were interesting and quite surprising for me. I expected **Ruby on Rails**, **Spring** and **ASP.NET MVC** to be on top. Instead, I found that **Django, Ruby on Rails** and **Laravel** were the most popular frameworks. **Ruby on Rails** has the most questions in all times. **Django** and **Laravel** seem to be rising in popularity with the most questions asked in the last 30 days.

Besides popularity, the additional considerations when choosing a framework are similar to the ones for Web Api server side:

* For web applications that provide big-data and statistics, consider going with Python Django.
* The [strongly typed vs weakly typed language](https://michaelscodingspot.com/web-application-development/\(https://stackoverflow.com/a/2696369/1229063\)) is still a consideration.
* If you have a team that already knows and loves a framework or a language, go with the already-known known technology.

On a personal note, I’m dumbfounded that PHP is gaining popularity.

#### Performance Benchmarks – for Both Web API and MVC

If you’re building a small business web application, performance might not matter as much. But for big applications that should serve many requests, response times are crucial. The most notable performance benchmarks comparison site is [https://www.techempower.com/benchmarks/](https://www.techempower.com/benchmarks/). Here, you can find a huge list of frameworks and various server configurations. Those are all benchmarked and compared into something like this:

![server-side performance framework benchmarks](https://michaelscodingspot.com/wp-content/uploads/2019/09/framework-benchmarks.png)

The candidates in the above test include a server with a web framework, a database, and an ORM. In the benchmark, the framework’s ORM is used to fetch all rows from a database table containing an unknown number of messages.

If we go by language, the fastest is Rust, followed by C, Go, Java, C++, PHP, C#, and Kotlin. If we go back to our "popular" frameworks and look for them, we’ll find this:

1. ASP.NET Core Web API (42.8% of best result)
2. Node.js variation (17.9% of best result)
3. ASP.NET Core MVC (17.2%)
4. Spring (4.4%)
5. Laravel variation (2.9%)
6. Django (1.9%)
7. Ruby on Rails (1.3%)

By the way, the #1 performance winner [Actix](https://actix.rs/) is a Rust language framework that I didn’t include due to its very low popularity.
