Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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.

share|improve this answer
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 Jun 23 '11 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 Jun 23 '11 at 15:18
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.