I'm developing a complex environment which involves a web application, a mobile app and a real time middleware system which accesses the DB for on-site tag readings. Currently, the web application exposes some services over a REST API, which are accessed by the mobile app to let it perform its business work (in this case, time delay is not critical). However, for my middleware system, I access the DB directly (through a ORM), in order to provide faster responses.

Am I doing it right or should I take advantage from the REST API to access the information to be processed in the middleware system too? Actually, this system, the web application and the DB belong to the same physical server.

Any recommendation about that will be welcomed!

  • You could test an api for the middleware system and see how much of a performance hit you'll take. Then you can see if having an api that is only used by one other system is worth the time, energy and effort.
    – JeffO
    Sep 18, 2014 at 13:31

1 Answer 1


From personal experience I suspect you are approaching it in a sensible way - there would be a performance hit by using the RESTful API for 'internal' access.

However, what you might consider is building an internal linking library that takes internal requests to access the DB and convert it into a form that is essentially what the RESTful API uses internally once it has accepted/authenticated and translated the request messages.

This is a model that splits the RESTful API into two layers - the message transport and control layer facing the Internet or network, and the internal message handlers. By having a 'local' linking library that bypasses the top layer but then goes through a common layer of handlers, you keep the advantages of one code base, one monitoring and maintenance/audit system etc.

  • Hi @David, thanks for your comment. So you mean I should access the REST API layer but with other kind of protocol rather than HTTP? I use Spring web services right now, so the complete API is exposed over a java interface and then the framework does the conversion to handle HTTP protocol. Having this API written in Java, you mean taking advantage of it to access it in other way?
    – Aritz
    Sep 19, 2014 at 10:37
  • Yes. On a recent project I had copies of the API message handler libraries on each server and if other systems on a server needed to 'access' the RESTful API (but internally obviously) it went through a simple 'linking' library that then called the underlying handler libs. Clearly there are some architectural considerations here, but it cut out the HTTP transport part (and authentication as internal connections I chose to trust). I hope this makes sense. I guess the eventual 'rule' was to use a single code library for all business logic execution. Sep 19, 2014 at 11:32
  • It makes sense. Then I'll manage the same entities and same methods either in REST API clients and internal clients.
    – Aritz
    Sep 19, 2014 at 11:36

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.