Web Service vs. Shared Library

Library Advantages:

  • Native code = higher performance
  • Simplest thing that could possibly work
  • No risk of centralized service going down and impacting all consumers

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.

My thought on this:

A Web Service was designed for machine interop and to reach an audience easily by using HTTP as the means of transport.

A strong point is that by publishing the service you are also opening the use of the service to an audience that is potentially vast (over the web or at least throughout the entire company) and/or largely outside of your control / influence / communication channel and you don't mind or this is desired. The usage of the service is much easier as clients simply have to have an internet connection and consume the service. Unlike a library which may not be so easily done (but can be done). The usage of the service is largely open. You are making it available to whomever feels they could use it and however they feel to use it.

However, a web service is in general slower and is dependent on an internet connection.
It's in general harder to test than a code library.
It may be harder to maintain. Much of that depends on your maintainance and coding practices.

I would consider a web service if several of the above features are desired or at least one of them is considered paramount and the downsides were acceptable or a necessary evil.

What about a Shared Library?

What if you are far more in "control" of your environment or want to be? You know who will be using the code (interface isn't a problem to maintain), you don't have to worry about interop. You are in a situation where you can easily achieve sharing without a lot of work / hoops to jump through.

Examples in my mind of when to use:

You have many applications in your control all hosted on the same server or two that will use the library.

Not so good example, you have many applications but all hosted on a dozen or so servers. Web Service may be a better choice.

You are not sure who or how your code could be used but know it is of good value to many. Web Service.

You are writing something only used by a limited set of applications, perhaps some helper functions. Library.

You are writing something highly specialized and is not suited for consumption by many. Such as an API for your Line of Business Application that no one else will ever use. Library.

If all things being equal, it would be easier to start with a shared library and turn it into a web service but not so much vice versa.

There are many more but these are some of my thoughts on it...

Tags:

Web Services