Note that there are some explanatory texts on larger screens.

plurals
  1. POHigh load RESTful API in Ruby (sync/async implementation)
    text
    copied!<p>I'm struggling with implementing a RESTful API that should return JSON response and should sustain very high load. The highest load will be generated by 'read' part of the API and very little load will be generated by 'write' part of the API. My first attempt was to write whole API using nodejs. I almost did it but faced very high duplication of models and logic between javascript and ruby, because the API is a part of a bigger system. I tried moving all logic into backend (mySql), but that idea turned out even more uglier. My second attempt is to write the API in Ruby ecosystem in order to share models/logic and tests between all parts of the system.</p> <p>I tried using Cramp and Goliath alone, but all that async stuff really complicated API implementation. I only need to have 2 read urls async because they generate the highest load and by going async all the way I was forced to implement the rest of API in async fashion, which didn't add any value.</p> <p>My current attempt is to go hybrid: use Thin/Sinatra/Cramp cocktail. I'm instantiating Thin rack handle right in Ruby code and using rack builder I'm splitting API between Sinatra, which is taking sync implementation, and Cramp, which is implementing 2 urls in async way.</p> <p>Is this is a good way to go? Or having Sinatra and Cramp in one web server (Thin) will get me even in more trouble by some reason?</p> <p><strong>update:</strong> I'm trying solution with sole Sinatra mixed with rack/fiber_pool and em_mysql2. Seems I'm killing two goals - making API async with sync implementation. But I'm suffering from <a href="https://github.com/brianmario/mysql2/pull/168" rel="nofollow">a bug</a> which I think will be fixed quite soon. </p> <p>Were will be any gotchas going this way?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload