Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Service vs. Shared Library

Tags:

web-services

This question has been asked a few times on SO from what I found:

When should a web service not be used? Web Service or DLL?

The answers helped but they were both a little pointed to a particular scenario. I wanted to get a more general thought on this.

When should a Web Service be considered over a Shared Library (DLL) and vice versa?

like image 552
Kevin LaBranche Avatar asked Aug 21 '09 15:08

Kevin LaBranche


People also ask

What is the difference between a library and a service?

A library is accessed via function calls. In contrast, a service has its own infrastructure. This means it has its own machine, but also logging, monitoring, alerting, potentially an on-call team to fix issues. It gets deployed independently of the applications.

What is the difference between API and library?

The main difference is that the library refers to the code itself, while API refers to the interface. When a complete set of software development tools for a specific platform are brought together as one kit, this is what is referred to an SDK (Software Development Kit).

What is a shared library used for?

A shared library or shared object is a file that is intended to be shared by multiple programs. Symbols used by a program are loaded from shared libraries into memory at load time or runtime.


1 Answers

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...

like image 193
Kevin LaBranche Avatar answered Jan 04 '23 01:01

Kevin LaBranche