When should I use OWIN Katana?
I am new to OWIN and Katana. I really don't get why I should use OWIN, while I can use IIS
. To simplify, my question is: What do I lose if I skip learning OWIN and use IIS for my websites?
I googled but there is not a simple explanation. There is some information here, but they use some jargon phrases so I cannot understand it.
Solution 1:
In asp.net WebApi v2, the OWIN pipeline becomes the default. It is eventually going to be the standard pipeline under any asp.net project.
I cannot put it better than what is written here : http://www.asp.net/aspnet/overview/owin-and-katana/an-overview-of-project-katana
The section "The Open Web Interface for .NET (OWIN)" explains perfectly the goals of OWIN.
Without OWIN, the asp.net bits are coupled to the way IIS communicates with the application. OWIN abstracts web servers and framework components. That means that your application code will now be aware of the OWIN interface, but not of the webserver that is serving the request.
In return, applications can be more easily ported between hosts and potentially entire platforms/operating systems. For example, the ability to host an application in a console or any process allows Mono to host it without efforts... (Raspberry Pi anyone)
The second aspect is that it works as a pipeline.
You can plug any middlewares (and as many as you want) between the webserver and your application.
This allows for more modular solutions. You can develop redistributable middlewares that can impact the request/response coming to/from your application, but keep these modules separated from the application code.
To persuade yourself of the benefits of this modular approach, take a look at the nuget packages available for OWIN : http://www.nuget.org/packages?q=owin
A lot of these packages were previously core asp.net functionality, and have been extracted as middleware.
For example, adding support to login using various OAuth providers becomes an infrastructure concern (a middleware) and does not need to be part of your application code anymore :
- http://www.nuget.org/packages/Microsoft.Owin.Security.Google/
- http://www.nuget.org/packages/Microsoft.Owin.Security.Facebook/
-
http://www.nuget.org/packages/Microsoft.Owin.Security.ActiveDirectory/
...
Or if you want to automatically replace all the images from your website by cute cat images, you can do that transparently as well :
https://github.com/serbrech/Owin.Catify
EDIT : It is now available as a nuget package : Owin.Catify!
Solution 2:
public interface OWIN
{
void ListenHttpCallAndServeWebPage();
}
namespace Microsoft.OWIN
{
public class Katana : OWIN
{
public void ListenHttpCallAndServeWebPage()
{
// listen to a port for HTTP call and serve web page
}
}
}
Yes, thats right. OWIN is an interface and Katana is an implementation of OWIN interface by Microsoft. Therefore we hear these 2 words (OWIN / KATANA) together and manytimes we get confused between the difference between these 2 terms. So, Katana is Microsoft's implementation of OWIN interface. Say there is another company named BIG-BOSS who wanted to create their own implementation of OWIN, they can do that and name their implementation as 'BATANA' and advertise phrases like OWIN / BATANA.
So, why OWIN !!!
Think about a country where the only vehicle available for movement is a truck. Nothing else. If you want to buy a vehicle, you would buy truck. Well, that used to serve good but people started to realize that, they don't need truck all the time, especially when they want to go to watch a movie or buy milk, driving a heavy truck not only costs high fuel, but also add stress on driving. But yes, if they want to carry lots of heavy stuff, truck serves the purpose very well.
Then, the Government of that country came up with a specification for vehicle makers. The specification is as follows:
- A vehicle needs to have 4 wheels
- A vehicle must have a steering.
- A vehicle must have headlight and signal lights.
So, based on these specifications, anyone can make vehicle according to different needs and they can name their vehicle accordingly. Therefore, Sedan, Pickup Truck, SUV, VAN, ..etc.. all kind of vehicle showed up in the market. If someone does not need to carry heavy stuff all the time, rather needs a vehicle just for going to workplace, he/she can buy a little Sedan. Someone can buy SUV if he needs little more power.
Based on the above example, we can say that our ASP.NET Web application uses System.Web Assembly which is heavily loaded (like a truck) and if we want to make a little Web Application where our purpose is just to serve some files based on a little set of requests, we are bound to use that heavy System.Web assembly (truck). Now, OWIN shows up. OWIN is a set of specification (we can call it interface) that defines a Server. Based on that specification, someone (like a vehicle maker) can make various kind of servers based on specific problem domains / application needs. Microsoft created their own Implementation for OWIN named Katana in the same way which can serve Web API. As WebAPI is a light weight technology, which does not need full blown System.Web things, a light weight Server implementation (like Katana) can boost the performance heavily when you use Web Api hosted on Katana.
Now, if you ask, 'Do I need it' ? Answer is, 'It depends on your need of performance'. If you don't mind driving your truck even for going to watch a movie, then, perhaps you do not need OWIN. But if you feel that, a light weight Sedan car is all you need to drive within a city, small distance, watch movie..etc.. yes, You may check what implementations of OWIN available in the market. Katana is one of the implementations of OWIN, therefore you can check what Katana offers. Not only Katana, if any other company implements OWIN according to specific Domain (for example, a server for Medical Devices which will download latest medicine information) and if you are a doctor, perhaps, you can check that implementation of OWIN. Moreover, you yourself can create your own implementation of OWIN targeting any specific niche.
In terms of web applications, if you are a simple Web developer, developing custom Websites for your clients, perhaps, you do not need to worry about custom implementation of OWINs, because IIS will serve you in a balanced way. If you build a Web API project, you will get Katana based template ready made from Visual Studio -> New Project, so you won't have to worry about anything other than learning Katana specific techniques. At this moment, Katana is not mature enough to completely replace the need for IIS for ASP.NET MVC, but perhaps, in the future it will.
Then When I may need to write my own OWIN Implementation ?
Answer: Well, say for example, you have developed a Windows application which should run as a server in the background and listen to a port number XXXX. Your server will respond to only some set of Requests like this:
- GET Inventory
- DELETE Inventory ID=4
- PUT Inventory ID=5
That's all. And nothing else. So, why would you need a full IIS web server for this little task? You can create your own OWIN implementation in that case. (Perhaps, you will use Katana for that)
Ok, so I understood that, if I want to make a ASP.NET MVC website, I don't have the option to replace IIS, then why should I need to know about Katana at this moment ?
Answer: Even though Katana is not mature enough to replace the need of IIS so that you can host your ASP.NET MVC website directly on Katana, but Katana implemented many cool interfaces of OWIN so that you can take the advantage of using those features side by side. For example, allowing your users to login using Facebook, Google, Twitter etc was not very easy before. Katana gives you many hooks (as a middle-ware) so that you can let Katana take care of external Social Media based Authentication easily without writing plumbing code. There are many other benefits to using Katana that you may find out when you start using this technology.
Solution 3:
A simpler version of that answer is that Katana is gong to fully replace System.Web assembly and the old ASP.NET pipeline, which gives you both better flexibility (use it in more scenarios and use only the parts you like) and performance.
So everyone should watch its evolution now and be ready to switch when it is finally completed.
Below is a diagram I drew to fill in the details Microsoft fails to include in this article.
OWIN is such a standard that it let application frameworks run upon it and forget about everything beneath it. On the other hand, OWIN itself utilizes various host adapters to make sure it can talk to the underlying web servers (IIS and many others).
I am now working with the Jexus web server author to investigate how we can write a host adapter to bridge OWIN/Katana and Jexus. We are really happy to learn that OWIN is flexible and highly customizable.
Reference: http://blog.lextudio.com/2014/06/why-owin-matters-a-lot-for-asp-net-developers/
Solution 4:
Why I should use OWIN, while I can use IIS?
OWIN is designed to decouple web servers from the frameworks you work under. It can make the applications lightweight and portable for the mixing frameworks and servers.
And Katana is Microsoft’s implementation of OWIN components.
Since last few years Microsoft is making web tools more agile and responsive as the their plan is progressing. For an example, the development of ASP.Net MVC and ASP.Net Web API. They do not depend on System.Web dll which is a huge burden they feel now I think. Advantage is both developments fixes can be provided on a timely manner and the cycle is faster than ever. Also now developers can deploy these applications on custom OWIN hosts or Katana, which is a reference of OWIN implementation.
What's the point after all?
Microsoft has released a project which is a lightweight OWIN based web host on top of IIS, called `Helios. The goal is to avoid ASP.NET/IIS relationship by providing some independent small components that can be used, installed and manage independently running on a web-host that implements the OWIN specifications.
One of the core reasons is the performance-factor. Helios will be able to achieve 2x-3x more throughput than standard ASP.Net application. In terms of memory consumption, Helios is much better than System.Web dll. In a taken benchmark Helios architecture allowed a sample application to achieve 50000 concurrent requests with approximately 1GB less overhead compare to a standard ASP.Net application.