4

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.

5
  • With Web API when you make "internal" change in business logic you need update only one place - Web API, but with dll you need update Web API and dll
    – Fabio
    Mar 7, 2017 at 5:59
  • Will the console app become part of the Web Application system, maintained by the same team, with coupled releases and versioning? Or will the console app be completely independent, having a different life cycle and versioning and maintainer than the Web Application?
    – Doc Brown
    Mar 7, 2017 at 6:46
  • @DocBrown the console app will be managed separately
    – nak
    Mar 7, 2017 at 13:51
  • Sorry, I meant the console app and the BL, not the Web Application. My point is: is the DLL of the BL the "official" API of the BL, and is it exposed to other applications intentionally? If yes, you can use it, if no, better use the Web API.
    – Doc Brown
    Mar 7, 2017 at 14:28
  • Sorry, I don't exactly understand what "official" here represents but let me give an example. Consider a recommendation service, it is currently embedded in the web app, so my UI layer composes object of BL and uses it accordingly to show the output. We also have created a web API to expose this functionality to some other 3rd party apps, not within our control. Since it is a layered architecture, we get the DLL of each layer too. Now I want to use recommendation in our new internal jobs, let's say to send emails to client. What should be done in this case
    – nak
    Mar 8, 2017 at 4:42

1 Answer 1

5

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
5
  • DLL is quick and easier to built - Point for DLL. It doenst require any extra operations over head like setting up a new web application and maintaining it - Point for DLL. Sep 27, 2018 at 9:00
  • I think it was mentioned in the post, but to make it more clear, For cases when BL is doing some long running operation, http call to an API can fail because of timeout - Point for DLL.
    – myroman
    Sep 23, 2019 at 22:00
  • @YawarMurtaza - good point I have added and entry based on it to the answer. Sep 24, 2019 at 5:32
  • @myroman - good point I have added and entry based on it to the answer. Sep 24, 2019 at 5:33
  • This is a very nice comparison.
    – robotron
    Dec 18, 2020 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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