I just finished reading Paul Dixโs book, Service Oriented Design with RoR, and I would like to build a Rails 3 web application based on what I just learned.
I think I got the basic architecture correctly, but a simple question like blocking me: how should I host multiple REST services on the same server?
Here's how I see things at the moment:
- Create * Utility applications (UserService, XYZFeatureService, ...) based on Sinatra (I think) that provide REST endpoints for accessing resources
- Have a front-end Rails application with controllers / views / ... that consume data from different services. End users could access it through
http://www.myapp.com , for example. - And finally, have a standalone "API" application for handling calls
https://api.myapp.com/* or https://www.myapp.com/api/* for publishing an external API that will use the same services with possible authentication, throttling, etc. on top of it.
Does this sound like a good start for you?
As for the implementation, from what I read in the book, I plan to create gems to handle the connection between the rails application and the services (I can throw in RabbitMQ, but that's another story).
However, since I only have one physical server, I wonder how I am going to combine all these applications / services? My first guess is to run each service application on localhost: xxxx, where xxxx is the other unprivileged port for each service. I can configure each client stone in my rails application to use these ports.
Along with this, I would probably run Apache 2 + Passenger to serve my rails and API services, using something like Rack :: URLMap (or virtual hosts when using a subdomain) to direct requests to the right of the application. Should I use Passenger to run my services in a production environment?
Is this the right way ?! It feels in accordance with what I read and found out, and, if necessary, easily crashed into several physical servers, but I would like to be sure that I will not miss anything. Do you build things differently?
Thanks so much for your input!
Update
The main questions I want to answer are:
- Is the architecture described suitable for building a web application with external API endpoints?
- Can I use services on the same server on different ports?
Thanks!