سؤال

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

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى softwareengineering.stackexchange
scroll top