Services or Shared Libraries

librariessoaweb services

I work in an environment where we have several different web applications, where each of them have different features but still need to do similar things: authentication, read from common data sources, store common data, etc.

Is it better to build the shared functionality into a set of services, to be called by the web apps, or is it better to make a shared library, which the webapps include?

The services or libraries would need to access various databases, and it seems like keeping that access in a single place (service) is a good idea. It would also reduce the number of database connections needed. A service would also keep the logic in a single place, but then it could be argued that a shared library can do the same thing. Are there other benefits to be gained from using services over shared libraries?

Best Answer

If you go the service route, all your applications will fail if the single service fails. Of course, it means if you need to modify the code that handles the common functionality, you only have to do it in one place (the service).

If you go the library route, your applications are more independent (in fact, they could be deployed on to different servers that do not even communicate) and don't all rely on a single service. Of course, if you need to modify the code that handles the common functionality, you will probably have to rebuild and redeploy all the applications with the new libraries. This could also be an advantage if you want Application A to use version 3 of Some Library and you want Application B to use version 4.2 of the same library. It's not a common case, but I have seen it happen once or twice in very specific situations.

Testing efforts for both should be the same because even if only one service "application" is modified, all the user applications should still be retested as if the service was internal to them.

Related Topic