I am creating a Rails application, which rather than using a database for the backend, will communicate with an external REST service.
This will work something like this:
Model.find(1) # GET /model/1
Model.delete(1) # DELETE /model/1
...
The business logic necessary to turn method calls into REST requests belongs in my model. However, there are several different servers that can be queried. Where do I put the connection logic so that:
- the queries are spread equally between servers?
- if a server becomes unavailable, the request is retried using a different server?
I am assuming this logic doesn’t belong in the model, but I’m not sure where.
Any advice much appreciated.
Have you considered using Active Resource? It is probably meant for almost exactly this use case, if I understand correctly.