11

I am a .NET developer. I see ASP.NET MVC framework now started providing a self-hosting feature. It makes a lot of sense (to me). A self-hosted application feels complete with no external dependency.

The question I have in my mind is now why would anyone NOT want to self-host ? I mean, Are there any advantages that IIS will give me over self-hosting. I am sure there are some advantages because otherwise, Microsoft would not have bothered creating IIS integration with asp.net core.

I don't want my question to be specific to .NET. So, I am gonna go with- why go with why use IIS or apache tomcat instead of self-hosting ?

Laiv
  • 14,283
  • 1
  • 31
  • 69
bilal fazlani
  • 228
  • 2
  • 7
  • 4
    At a high level, major web servers come with a lot of functionality you need to totally rebuild, that you can otherwise *configure* or *simply ignore*, if you "self-host." Simple things, like serving up static files, and configuring `Expires` and `ETag` headers. And then more complicated things, like separating traffic by `host`, keeping applications away from each other's memory, SSL, and managing thousands of concurrent requests ... – svidgen Sep 21 '16 at 17:10
  • You could just write your own HTTP service using C++ sockets. – Matthew Whited Sep 21 '16 at 17:28
  • 1
    http://www.dotnetfunda.com/interviews/exclusive/show/755/what-are-the-advantages-of-hosting-wcf-services-in-iis-as-compared-to – Matthew Whited Sep 21 '16 at 17:33
  • 1
    Many .net applications call themselves "self hosted" while they still use http.sys, which is rather misleading IMO. – CodesInChaos Sep 21 '16 at 18:23
  • In my view, it's merely a historical consequence of the evolution of the use cases for the TCP/HTTP protocols and services stack. E.g., in the case of HTTP, the daemon or service used to be sitting on top of the OS as a sort of central hub of anything-web content, to which other local or remote applications would delegate the consumption or offering of hypertext/hypermedia content. – YSharp Sep 29 '16 at 23:12
  • ... Later on, people realized that most of their functionality could as well be encapsulated in component librairies making less assumptions wrt. availability, scalability, content types, caching, etc -- hence how (more or less) monolithic HTTP implementations got broken down into smaller reusable components aka "core", for direct, finer-grained use by, and from within applications. I agree "self-hosting" is a misnomer, though, as they rely on bits of a codebase that is still subject to the IIS or Apache or etc's design &/or implementation bias that predated them. – YSharp Sep 29 '16 at 23:12

1 Answers1

13

IIS provides a number of common capabilities that are not available by default in self-hosted web services. Supervisor: it monitors the health of the web application and will kill/respawn the application if it starts looking unhealthy (using too much memory, CPU, etc. -- configurable). Resource limits like CPU usage, connection limits, etc. Run as a certain user for least privilege security. Manage certificates/SSL. Host/manage many applications through one port/interface. Reverse proxy to console applications. A lot of other things I didn't mention like request logging.

I'm unfamiliar with Tomcat, but I assume it's the same story. You get extra hosting features that self-hosting does not give you by default and may be quite difficult to implement yourself.

Often products that do expose a self-hosted web service will still recommend putting them behind a reverse proxy or other supervisor in production. This may be to ensure it will survive crashes or be graceful during network interruptions. I'm thinking of NGINX for Docker services, for instance. In the .NET space, I believe Kestrel is reverse proxied through IIS as standard practice (or maybe NGINX on Linux/Mac).

Traditionally, ASP.NET apps have been windows-only hosted on Internet Information Server (IIS). The recommended way to run ASP.NET Core applications on Windows is still using IIS, but as a reverse-proxy server. The ASP.NET Core Module in IIS manages and proxies requests to the Kestrel HTTP server hosted out-of-process.

Kasey Speakman
  • 4,341
  • 19
  • 26