Search code examples
web-servicessoapnugetlibrariessoa

Libraries rather than Web Services


I am interested in the pros/cons of refactoring a large application (industrial monitoring software) into a bunch of Libraries / NuGet Packages, rather than as stand-alone Services. The perception is that they're almost identical, i.e. a service can be built as either a Library hosted within the application, or it can be built as a Web Service and hosed externally to the application. The only difference is integration (code level vs. network SOAP or REST traffic). I'm not sure it's that straightforward, looking for pros/cons of each.


Solution

  • The perception is that they're almost identical...

    If you squint your eyes hard enough I think they might look identical. But only up to a point.

    You implement some functionality in a web service, you can implement it in a library too. The web service provides an API to call, the library provides an API to call too. You invoke the web service, you can invoke the library too.

    But there is stuff you can't do by replacing a web service with a library.

    Your libraries are in .dll files? How is a PHP application going to use them? Or a Java application? SOAP/REST are client agnostic. Your web service can use any technology stack, your client can use any technology stack. With libraries you are stuck to the same technology you used to write the library in.

    Web services are individually deployable components. Fix bugs for the web service, deploy, and your 10 clients get the fix on the next call. Now fix some bugs for the library then update all 10 clients to use the new versions of the libraries.

    How about security? A web service can have a database for example. You don't get access to the database directly, you do so with the API the web service provides you. You have a library that uses a database? Guess where the connection string, username and password are found.

    How about scalability? If you have a web service you can scale it horizontally and your clients immediately benefit from the improvement. If the library is in the client how are you going to scale it? By scaling the clients?

    You can find similar responses elsewhere (e.g. Web Service vs. Shared Library), but the point to take home is that it depends on what you are building and for whom. One is not a general replacement for the other, and vice-versa.

    If you are building a single monolithic application that makes use of all of these components then maybe it does not matter for you if the components are microservices or hosted libs. With libs it might actually be easier to build. But if your plan is to actually provide services to other clients, then hosted libs won't work all the way.