title: AKKA.NET in ASP.NET or in console app?
body: <p>I'm trying to integrate AKKA in a IoT application built using ASP.NET Core on framework net46. I'm trying to find the best approach and would appreciate any comments on this question, although it is a bit long. Both comments based on experience with AKKA in Java and AKKA.NET will be relevant. </p>
  
  <p>In short, I need AKKA.NET to receive IoT-messages from remote devices and perform fairly complex processing logic. </p>
  
  <p>For the IoT-communication we use the Azure IoT-hub. The IoT-messages are consumed by a multithreaded console-application following the guidelines from Microsoft here: </p>
  
  <p><a href="https://azure.microsoft.com/da-dk/documentation/articles/iot-hub-csharp-csharp-process-d2c/" rel="noreferrer">https://azure.microsoft.com/da-dk/documentation/articles/iot-hub-csharp-csharp-process-d2c/</a></p>
  
  <p>At the same time we are running a standard ASP.NET Core (framework net46) application using dependency injection and all the latest best practices.</p>
  
  <p>I need AKKA.NET to take over part of the processing going on inside the IOT consumer application and also part of the processing going on inside the ASP.NET application.</p>
  
  <p>I see the following three solutions and I'm curious which would be recommended by more experienced AKKA-developers. My own guts feeling is that solution 1 is the preferred, see below for my own arguments: </p>
  
  <ul>
  <li><p>Solution 1: Create a new Console application based on AKKA.NET and use AKKA.Remoting to communicate with the ASP.NET application and the IoT consumer application. This means that all the actor logic will be encapsulated within an isolated console application. Of course AKKA.NET will also be referenced and utilized within the ASP.NET application and the IoT consumer application, but only for sending remote messages.</p></li>
  <li><p>Solution 2: Use AKKA.NET directly within the ASP.NET application and use AKKA.Remoting to communicate with the Iot consumer application. This means that the ASP.NET application will be extended with Actor logic side-by-side with existing traditional ASP.NET logic based on controllers, await/asynch etc. </p></li>
  <li><p>Solution 3: The opposite of solution 2, that is, use AKKA.NET directly within the IoT consumer application and use AKKA.Remoting to communicate with the ASP.NET application. </p></li>
  </ul>
  
  <p>There might be more variations such as integrating AKKA.NET logic inside both the ASP.NET and the IoT consumer application but I don't like the idea of having actors running in different applications, at least not in this early phase where I'm trying to establish a clean new actor-based implementation. </p>
  
  <p>Here are my arguments for solution 1: </p>
  
  <ul>
  <li><p>I have been told that AKKA.NET is able to utilize all cores in the best possible manner without context switches if configured correctly. To be able to analyze and optimize the configuration, I prefer to have the simplest possible runtime environment for the AKKA.NET application logic. Having the AKKA.NET running inside a web-container or inside a console application already utilizing threads and locks, doesn't seem very simple as compared to a raw console application running nothing else than my AKKA.NET actors.</p></li>
  <li><p>As the actor based logic in C# is fundamentally differently (and slightly more convoluted) than ordinary procedural/functional programming, I like to encapsulate it in a seperate project using existing application projects as dependencies. In this way I hope the code will be easier to understand later on. </p></li>
  <li><p>I plan to run scheduled actors to take over cron-based processing. Doing this inside my ASP.NET application seems fragile as the application might be taken to sleep by the infrastructure. </p></li>
  <li><p>If at some point I want to scale up the actor-based processing it seems easier and more transparent to scale up using a pure console application that only runs actors than scaling up either ASP.NET application nodes or scaling up my IoT consumer application (which might not even be possible without introducing subtle errors).  </p></li>
  </ul>