Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

High-performance REST API - Which language/stack? [closed]

I am developing a site using Ruby on Rails. I would like to develop the REST API (JSON) separately to maximize performance, the Rails stack just takes away too much.

Are there any performance benchmarks out there? What do you think would yield the best performance? I am currently thinking about the following, because that's what I have experience with. Is there anything else I should consider? It should be lightweight.

  • node.js
  • Scala Spray (http://spray.io/)
  • Ruby Sinatra

Thanks!

like image 262
Denny Avatar asked Nov 30 '12 18:11

Denny


People also ask

Which language is best for REST API?

XML: JSON and XML are the two de facto standards for sending and receiving data in REST APIs. Web programming languages such as Python, JavaScript, Ruby on Rails, and Java all have tools for parsing and working with XML and JSON.

How do I improve my REST API performance?

Caching is one of the best ways to improve API performance. If you have requests that frequently produce the same response, a cached version of the response avoids excessive database queries. The easiest way to cache responses is to periodically expire it, or force it to expire when certain data updates happen.

Which API is the fastest?

Fiber is one of the fastest frameworks for building APIs.


1 Answers

Summary: Maximize your performance as a developer. Use stack you know best. First make it work, then make it fast.

Are there any performance benchmarks out there?

There are all kinds of benchmarks out there. Let's say, node.js can handle 100k HPS (helloworlds per second) and Sinatra can only do 80k. What does it tell you? Nothing.

Also, sometimes higher performance comes at a great cost. Take ruby C extensions, for example. Sure, C runs faster than Ruby, but it prevents other threads from running on other cores (because of GIL).

So, don't choose tech only by benchmark figures from the internet. There are so many factors to consider besides raw HPS number.

LINK: If you think Rails is too heavy, you should try rails-api. It's basically a stripped down version of Rails (you don't need things like cookie authentication or MSIE rendering helpers in an api server).


Personal story

I run an API server that handles some load. First version was written with Rails. Then I thought "Hey, Rails Is Bloated (c), let's rewrite everything with Sinatra". And then I had waves of frustration coming one after another. It turned out that Rails does a lot of small but helpful things which I didn't appreciate. I gave up, rewrote it with Rails again (applying lessons learned) and lived happily ever since.

like image 62
Sergio Tulentsev Avatar answered Oct 11 '22 13:10

Sergio Tulentsev