I'm building a service that will consist of mobile and desktop apps, which will require me to build my own RESTful web API to easily keep the data for the service in sync. I am also building a web app in Ruby on Rails. Initially I plan to host everything on one server due to cost.

I'm curious which is a better design:

  1. Have the Rails app access the database strictly via calls to the API to allow for the future ability to host them on separate servers.
  2. Host the API and Rails app on the same server always, and have each access the database directly.

I'm currently planning on the API to be private, with the possibility of opening up a small portion of it later.

Disclaimer: This would be my first time building my own API


1 Answer 1


It is better to go with the first option. Having your 3 clients - mobile, desktop and webapp - use the API in the same way is a better design since all of them use the API in a consistent manner, and any changes in the API will be reflected as-is in all the three clients.

This way it is easier to debug and simpler to extend new features. If your Rails app talks directly to the database you will have to modify the data access code (instead of the ReST client code) in your Rails app every time the API changes and the Rails app might end up modifying the data in a different way than the desktop and mobile app, leading to inconsistencies.

In a nutshell: Keeping consistent access mechanism will ensure better maintainability.

  • Thanks! This is kind of what I was thinking, but since I'm relatively new to API design I wanted to get others opinions. Dec 5, 2014 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.