Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing application server for API backend

With so many choices for the application server (Passenger, Thin, Unicorn, Mongrel, Puma and Rainbows!), I'm wondering what would be appropriate for the following scenario:

Rails is used purely for API backend (all assets are served with Nginx). Some of the API calls rely on other API services, so sometimes they take a while to finish.

The responsive app is used with mobile, tablet and desktop clients, so there's no guarantees about the client's connection.

What application server do you think is appropriate in this case? What things should be considered when choosing?

like image 466
randomguy Avatar asked Feb 14 '13 12:02

randomguy


People also ask

What is backend API server?

What is a back-end API? A back-end API is a programming interface that helps developers to interact with back-end services for example server. When choosing a backend API, there are a multitude of options available. There are certain things that you need to keep in mind that will lead you to your goals.

What is Application Server backend?

A backend server is generally an application server that software on the web server can call on behalf of the end user to perform business logic. ... A backend server is any remote server managing data. A webserver is a specific type of backend server used for “internet” traffic.

What can I use for backend API?

REST and GraphQL are both standard ways to develop backend APIs. But over the past decade REST APIs have dominated as a choice for developing backend API's. And many companies and developers use it actively in their projects. But REST has some limitations, and there's another alternative available – GraphQL.

Are APIs on the backend?

Often, an API is considered a backend "component". And, for instance, a database can also be treated as another backend component. The APIs you are likely referring to here are web APIs, so could be considered as backend components.


1 Answers

If your application makes API calls to other services then Unicorn is a bad choice. Unicorn is a single-threaded multi-process application server, explicitly designed for fast, short-running CPU-bound workloads. Making HTTP API calls counts as long-running blocking I/O requests. This is not a limitation, but an explicit design choice of Unicorn. This is confirmed by the Unicorn website, section "Just Worse in Some Cases".

In theory Thin can handle such high-concurrency workloads because it uses evented I/O. However this requires explicit framework and application support in the form of evented code. Few frameworks and applications do this. Rails and Sinatra do not.

So this leaves only multithreading-capable application servers. The three contenders are Puma, Rainbows and Phusion Passenger 4 Enterprise.

  • Puma is relatively new. Rainbows is slightly older but the author gives no guarantees about whether it works well. Phusion Passenger is mature, has existed for years, and is currently being used by over 150000 websites including large ones such as Pixar, New York Times, AirBnB, etc.
  • Puma's and Rainbows's usage models are similar to Unicorn and Thin in that you start a bunch of processes and hook them into Nginx through a reverse proxy configuration. Phusion Passenger on the other hand is designed to integrate into Nginx directly, so it requires a lot less configuration, process management and other administration overhead.
  • Phusion Passenger 4 Enterprise is not a strictly multithreaded server, but a hybrid multi-process/multithreaded one. This means it can run multiple processes (for increased stability and the ability to use multiple CPU cores), each one with multiple threads (for high I/O concurrency).
  • Phusion Passenger 4 Enterprise bring many advantages over has more features than Puma and Rainbows: for example it has out of band garbage collection, can dynamically adjust the number of processes based on traffic, completely automates rolling restarts so you don't need scripting, etc.

You may also be interested in this writeup for more information.

like image 124
Hongli Avatar answered Sep 21 '22 02:09

Hongli