API – Choosing Between Web API and DLL Reference

apicdllnetweb

I am confused between choosing Web API or DLL reference for a project I am working on and want to understand recommendations for both the approach.

We are having a Web API which exposes an interface for the business logic(BL). We are using HTTP based service and the code is C#. We also have a Web Application which internally uses the BL. When I compile I get separate DLL for BL which can also be referenced and reused.

Now, I want to create a C# console app which will be run through task scheduler at a specific time of the day. I will be requiring to use the same BL to proceed with my logic. It's a background service and performance is not a major concern. What will be a better approach here, using compiled DLL or calling Web API? What things to consider when you have to decide between the two approach?

One more thing I would like to mention is that my organization is moving towards microservice architecture. Anything in this context will be highly appreciated.

Best Answer

There are a few considerations to make:

  • Updates: changes to the BL will always be reflected in the API but you would need to install a new version of the DLL - Point for API
  • Connection: A DLL will work offline, provided nothing that it does requires online functionality - Point for DLL
  • Portability: An API can be accessed from just about anything and should just work while the DLL, or shared library, you would have to build for each potential platform - Point for API
  • Speed: Usually a DLL will run faster as it is not usually waiting for responses from a server - Point for DLL
  • Client Loading: If the BL is doing a lot of work this is done on the Server when accessed by the API not on the client - Usually point for API unless your server gets heavily loaded.
  • Data Storage/Currency: The API will use the latest data at the server whereas the DLL will need to download/update it first, it might be very large, or risk using out of date data - Point for API
  • Potential to use Micro-services: Most micro-services are run under Linux so you would need a shared library (.so) rather than a DLL for the BL and then you would need to consider how to communicate with an API based approach you are largely there already - Point for API
  • An API can easily be made self documenting while a DLL will have to maintain & ship documentation separately - Point for API.

Based on comments

  • A DLL is usually easier for an inexperienced developer to produce - point for DLL (thanks to @yawar-murtaza) but it must be remembered that it will only be made for and tested on the system(s) that they have available
  • In the case of long operations an API call can time out (thanks to @myroman) but a DLL can give the appearance of the machine locking up Im calling that a draw
Related Topic