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?

2 Answers 2


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.

  • 1
    The effort of updating the libraries can be partially mitigated if you have a good automatic build process. It probably is best if each application pulls in the libraries it needs, rather than trying to maintain a list of where to push new builds.
    – Michael K
    Commented Jun 23, 2011 at 14:34
  • 1
    I should mention that any services would be run on multiple servers, similar to the webapps, to avoid a single point of failure.
    – Royal
    Commented Jun 23, 2011 at 15:18

Library Advantages:

Service Advantages:

  • Everyone gets upgrades immediately and transparently (unless versioned API offerred)
  • Consumers cannot decompile the code
  • Can scale service hardware separately
  • Technology agnostic. With a shared library, consumers must utilize a compatible technology.

  • More secure. The UI tier can call the service which sits behind a firewall instead of directly accessing the DB.

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.