We're awash in data. Today, we live in a digital world where data is produced and consumed at an unprecedented rate. Today's businesses rely on data to provide critical business insights and control operations and processes in real time. The traditional cloud computing models are constrained by their limitations in latency, bandwidth, and privacy to work with such massive volumes of data. Here's exactly where edge computing can help.
This article explores how you can use .NET to build edge-native systems, shorten latency, and keep data close to the metal. It also discusses hybrid edge-cloud architectures, containerized microservices, messaging-driven architectures, local inference for IoT, and real-time sensor use, as well as complex issues of consistency, resilience, security, and observability.
To work with the code examples discussed in this article, you need the following installed on your system:
Understood.
- .NET 11
- ASP.NET 11.0 Runtime
- Entity Framework Core
If you don't already have Visual Studio 2026 installed on your computer, you can download it from https://visualstudio.microsoft.com/downloads/.
What Is Edge Computing?
Understood.
This is done by moving the computational workloads and data storage away from centralized data centers and cloud platforms to the edge of the network.
The data collected at the edge can be divided into three categories:
- No action is required once the data is collected, and there is no need to store the data.
- It is important to retain data collected at the edge so that it can be analyzed in the future.
- The data collected at the edge calls for an immediate response.
The Internet of Things (IoT) and edge computing are classic instances of technological breakthroughs that are growing rapidly and regularly while also presenting a new set of challenges. The IoT ecosystem generates and distributes ever-increasing volumes of data, so computing, storage, and networking technologies must keep up with these developments and adapt to accommodate the needs of future workloads.
Why Do We Need Edge Computing?
In the traditional cloud computing paradigm, data is processed and stored in data centers that are centrally located, often far away from the consumers. As the amount of data grows exponentially, conventional cloud-based data processing methodologies face significant challenges.
Ready.
Figure 1 illustrates a comparison between edge computing and cloud computing. In the case of edge computing, isolation of analysis and data processing enables real-time signal processing. In contrast, in cloud computing you'll encounter signal latency because of traffic overload.
Input:
Understood.
The closer the computation and storage are to the data source, the better the performance, operation costs, and reliability, and the less congestion there is on the network. Data is processed in real time at the edge, and latency and bandwidth costs are reduced. This is because only the essential information is sent to the cloud or the data center for further analysis, making it an economical and practical way for small and large enterprises alike to handle massive volumes of data expeditiously.
Benefits
Edge computing offers several benefits:
- **Lower latency: **Edge computing facilitates reduced latency because there is no need for the data to travel to the cloud and back with each request.
Understood. - **Resilient automation: **Since automation will continue to operate regardless of the availability of the network, edge computing provides much more resilient automation.
- **Enhanced security: **By processing and analyzing data locally, potential threats during data transmission are reduced. Additionally, the data in transit is encrypted en route to the cloud or data center.
- **Faster processing: **Since most of the data is processed on-site, at or near the location of the data, you'll get results much faster without waiting for network connectivity.
- **Scalability: **Edge computing can grow over time, i.e., the number of edge nodes used can be increased, rather than increasing the amount of centrally located data center capacity. Essentially, edge computing enables organizations to scale at the edge by adding new hardware without investing additional resources in centralized data centers.
Sending Critical Alerts to the Cloud Using Edge Computing
Let's now simulate a simple edge computing application that demonstrates how you can collect temperature data and send critical alerts to the cloud after processing the data locally. For the sake of simplicity, we'll simulate an IoT device using an ASP.NET Core application.
Create a New ASP.NET Core Project in Visual Studio 2026
You can create a project in Visual Studio 2026 in several ways. When you launch Visual Studio 2026, you'll see the Start window. You can choose “Continue without code” to launch the main screen of the Visual Studio 2026 IDE.
- Start the Visual Studio 2026 IDE.
- In the Create a new project window, select ASP.NET Core Web API and click Next to move on.
- Specify the project name as
EdgeComputingDemoand the path where it should be created in the Configure your new project window. - If you want the solution file and project to be created in the same directory, you can optionally check the Place solution and project in the same directory checkbox. Click Next to move on.
- In the next screen, specify the target framework as .NET 11.0 (Preview) as shown in Figure 2, and the authentication type as well. Ensure that the Configure for HTTPS, Enable Docker Support, and Enable OpenAPI support checkboxes are unchecked because you won't use any of these in this example.
Create a new class named Worker in a file named Worker.cs and replace the autogenerated code with the following code.
public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;
private const int AlertThreshold = 30;
public Worker(ILogger<Worker> logger)
{
_logger = logger;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
//Not yet implemented
}
private double GetTemperature()
{
Random rand = new Random();
return 20 + (rand.NextDouble() * 15);
}
private void SendAlertToCloud(double temperature)
{
_logger.LogCritical($"Sending critical alert: Temperature {temperature:F2}°C");
}
}
Please provide the line to process.
Inside the Worker class are two members: a logger and a constant integer that represents the alert threshold. Note how we've used dependency injection to inject an instance of type ILogger<Worker> into the private logger field in the Worker class. Listing 1 shows the complete source code of the Worker class.
Listing 1: The Worker class
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;
private const int AlertThreshold = 30;
public Worker(ILogger<Worker> logger)
{
_logger = logger;
}
protected override async Task ExecuteAsync(CancellationToken
stoppingToken)
{
_logger.LogInformation("Edge Computing Device Service
Started.");
while (!stoppingToken.IsCancellationRequested)
{
try
{
double temperature = GetTemperature();
_logger.LogInformation($"Current Temperature:
{temperature:F2}°C");
if (temperature > AlertThreshold)
{
_logger.Warning("ALERT: High Temperature
Detected!");
SendAlertToCloud(temperature);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "An error occurred while
processing sensor data.");
}
await Task.Delay(TimeSpan.FromSeconds(2),
stoppingToken);
}
_logger.LogInformation("Edge Computing Device Service
Stopped gracefully.");
}
private double GetTemperature()
{
Random rand = new Random();
return 20 + (rand.NextDouble() * 15);
}
private void SendAlertToCloud(double temperature)
{
_logger.LogCritical($"Sending critical alert:
Temperature {temperature:F2}°C");
}
}
The ExecuteAsync method is an overridden method where you should specify the exact operation your worker component should execute. We haven't implemented this method yet. The ExecuteAsync method accepts an instance of CancellationToken as a parameter. The runtime passes this instance to allow the code to stop executing when the application shuts down.
The following code snippet shows the ExecuteAsync method that reads the temperature and then checks if the current temperature exceeds the alert threshold. If the current temperature exceeds the alert threshold, it invokes the SendAlertToCloud method to send an alert to the configured cloud platform.
protected override async Task ExecuteAsync(
CancellationToken stoppingToken)
{
_logger.LogInformation
("Edge Computing Device Service Started.");
while (!stoppingToken.IsCancellationRequested)
{
try
{
double temperature = GetTemperature();
_logger.LogInformation
($"Current Temperature:
{temperature:F2}°C");
if (temperature > AlertThreshold)
{
_logger.LogWarning
("ALERT: High Temperature
Detected!");
SendAlertToCloud(temperature);
}
}
catch (Exception ex)
{
_logger.LogError
(ex, "An error occurred
while processing sensor data.");
}
await Task.Delay
(TimeSpan.FromSeconds(2),
stoppingToken);
}
_logger.LogInformation
("Edge Computing Device
Service Stopped gracefully.");
}
Types of Edge Computing
The following are the types of edge computing:
Multi-access Edge Computing (MEC)
Multi-access Edge Computing (MEC) involves bringing computing capabilities close to the edge of a mobile network. This allows low-latency, high-bandwidth applications and services to be delivered at the edge of the cellular network infrastructure.
Cloud Edge Computing
Cloud edge computing refers to the deployment of edge computing capabilities in proximity to cloud data centers, enabling the cloud services to be extended to the edge for faster processing, reduced latency, and improved data privacy.
Device Edge Computing
Device edge computing involves processing data directly on IoT devices or gateways. As the name implies, this type of edge computing is specifically designed for resource-constrained devices with limited processing power and memory.
Fog Computing
Fog computing enables data processing at the network edge, typically in local network gateways, routers, or switches, thereby reducing latency and bandwidth requirements.
Sensor Edge Computing
Sensor edge computing entails performing computations at the sensor edge where you require real-time data processing with high sensor density by leveraging real-time data stored at the sensor edge, as close as possible to the data source.
Far Edge Computing
Far edge computing, also known as the enterprise edge, involves deploying edge computing resources closer to the end users or devices, enabling localized data processing, reducing network traffic, and improving response times.
How Does Edge Computing Work?
In edge computing, information is captured and processed close to where it originates. Here are the key activities that illustrate how edge computing works:
Data Generation
In the first step, data is generated by edge devices such as autonomous vehicles, IoT sensors, or mobile devices, which can generate massive amounts of real-time data. Traditional cloud computing processes data at a centralized data center, but edge computing processes data locally, close to the edge device.
Local Processing
Instead of transmitting all the data to a central data center or the cloud, the system processes it locally, on the device or on nearby edge servers or gateways.
Subsequently, only the essential data is transmitted to the central data center or the cloud, where it might undergo further processing or be retained for an extended period. This lowers latency and promotes real-time decision-making.
Filtering and Analysis
At this stage, data is filtered and analyzed at the edge of the network in accordance with predefined rules or algorithms. In this way, bandwidth usage is optimized since a reduced amount of data is sent to the cloud or data center.
Transmit Only Relevant Data
To minimize bandwidth requirements and data transfer volume, only relevant and critical data is sent to the cloud or data center for analysis and long-term storage.
Integration with Cloud-Based Services
Data that has been filtered and processed can be integrated with cloud-based services for advanced analytics, machine learning, or storage, enabling you to gain deeper insights, correlate your data, and store it for a long time.
Real-Time Decisions
With edge computing, real-time decision-making is made possible for critical monitoring systems, autonomous vehicles, and industrial automation by processing data locally and reducing round trips.
Key Challenges of Edge Computing
While processing at the edge has many benefits, edge computing brings a new set of challenges:
Bandwidth
As edge computing grows, so do its bandwidth requirements. Traditional networks allocate more bandwidth to data centers and less to endpoints, but edge computing needs more bandwidth at every endpoint, so its overall requirements are higher.
Latency
Understood.
Security
Data security at the edge of the network can be tricky when processed by various devices that may not be as secure as centralized or cloud-based systems processed by a central server. With the increase in IoT devices, IT departments must be aware of potential security hazards.
Understood.
Key Components of Edge Computing Architecture
You should consider several factors when designing an edge computing architecture such as security measures, data processing requirements, and connectivity. The edge ecosystem comprises edge devices, edge nodes, edge servers, edge gateways, and the cloud.
The key components of edge computing architecture are:
Edge Computing Infrastructure
An edge computing infrastructure consists of servers and edge data centers near edge devices. Typically, this includes computing resources, storage, and networking components such as edge or micro data centers.
Edge Devices
Please provide the line to process.
Edge Node
This is any device, server, or gateway that is able to perform edge computing. An edge node is defined as a virtual or physical machine situated at the edge of a network and acting as a gateway between local networks and the outside world.
In edge computing, edge nodes ensure that data can be efficiently processed, stored, and transmitted between local devices and central systems.
Edge Cluster/Server
These are servers located near end users that are used to deploy apps to devices. In contrast to servers located in a centralized data center, edge servers are located closer to end users, at the “edge” of the network. Bringing cloud computing resources closer to users reduces latency and allows faster response times.
Edge Gateway
An edge gateway is a piece of hardware or software that acts as a connection point between individual devices, local networks, and centralized systems such as the cloud. In essence, it acts as a connecting point closest to where data is generated and gathered at the “edge” of a network. This serves as an entry point to the cloud and performs network functions that include protocol translation, firewall management, etc.
Edge Applications
Please provide the line to process.
Cloud
In terms of computing, the “cloud” is used to describe a distributed system of servers that houses applications and data on the internet rather than locally. Edge computing architecture is often integrated with cloud services to enable seamless communication between the edge and the cloud. With the help of cloud services, organizations and individuals can access and store data on remote computers situated in data centers all over the globe.
Pure Edge Vs. Thin Edge Vs. Thick Edge
Understood.
Pure Edge
Understood.
Please provide the line to process.
Thin Edge
In thin edge architecture, a significant portion of the processing power of the cloud is shared with devices residing at the edge of the network. Edge devices process and filter data locally before they transmit the data to the cloud. It should be noted that complex computation, data storage, and analytics are handled by the cloud.
Edge devices collect information and preprocess the collected data to lower the workload on the cloud. Thin edge computing can be helpful when processing power, cloud resources, and more advanced analytics are required.
Thick Edge
Understood.

The Anatomy of Azure Edge Computing
Azure edge computing extends Azure services to edge devices, including IoT devices and gateways, to leverage computing, artificial intelligence, and analytics close to where the data originates or resides.
Azure IoT Edge is a device-focused runtime environment that enables you to deploy, execute, manage, and monitor containerized applications, thereby bringing analytics closer to your IoT devices for deriving insights faster and providing analytics and decision-making offline. The Azure IoT Edge architecture comprises three components:
- IoT Edge modules: These are essentially containers that execute Azure services, third-party services, or even your custom code.
IoT Edge runtime: This is a runtime environment that executes on each IoT device and manages the modules that are deployed to each IoT device.- A cloud-based interface: This enables you to manage and monitor your IoT Edge devices remotely.
Security at the Edge
We live in an incredible era where technology is everywhere; it surrounds us wherever we go. However, while technological advancements have made our lives more comfortable, they also create security vulnerabilities. Remember that any device or local network connection may be a weak spot.
If your critical data is scattered across such devices, you must have a proper strategy in place to keep your data safe and secure. Imagine that while your cloud server is your heavily guarded main bank vault, the edge devices are like dozens of smaller ATMs scattered throughout a network. You should therefore ensure that each of these ATMs is authenticated and connects only to devices it is supposed to. Hence, we need to be able to secure our edge devices much the same way we secure applications and servers.
Credential management is yet another important security aspect. We often store secrets such as passwords and API keys in a secure location on a central server. However, because numerous small devices are spread across the network, securing these keys is critical. You must have a security strategy in place that ensures that if any of these keys are compromised, the damage is contained.
The following code snippet illustrates how you can retrieve secrets using tokenization.
public class SecureCredentialManager
{
private readonly HttpClient _httpClient;
private const string VaultApiUrl =
"https://demovault.internal/v1/read";
public SecureCredentialManager(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<string> GetCredentials
(string serviceIdentityToken)
{
var response = await _httpClient.GetAsync(
$"{VaultApiUrl}?
token={serviceIdentityToken}");
if (!response.IsSuccessStatusCode)
{
throw new UnauthorizedAccessException
("Authentication failed.");
}
var content = await response.Content.
ReadAsStringAsync();
return ParseSecretValue(content);
}
private string ParseSecretValue
(string content) => $"[SECRET_VALUE]...";
}
In the preceding code snippet, the vault endpoint points to a secure secret store. The GetCredentials method authenticates the service's identity via a token and returns temporary credentials. Lastly, this method returns only the required value, limiting exposure.
Please provide the line to process.
Since zero trust security follows the principle “never trust, always verify,” this translates into the following policies:
- Microsegmentation: The network must be segmented.
- All traffic, internal or external, must have to go through an enforcement point (such as a service mesh sidecar) to verify the identity of every packet.
Performance and Scalability
Here are the key strategies you should follow to improve the performance and scalability of your edge applications:
Reduce Memory Usage and Garbage Collection (GC) Overheads
Understood. Please provide the line to process.
Prefer structs over classes: Passing value types, such as struct instances, instead of reference types, such as class instances, reduces heap allocations and increases cache locality, easing GC pressure.
Consider the following piece of code that demonstrates a method called ProcessData that allocates many strings.
using System;
using System.Runtime.InteropServices;
public struct SensorReading
{
public double Value { get; set;}
public SensorReading
(double value) => Value = value;
}
public List<SensorReading>
ProcessData(byte[] rawBuffer)
{
string rawString = Encoding.UTF8.GetString(
rawBuffer);
var readings = new List<SensorReading>();
foreach (var segment in rawString.Split('|'))
{
if (double.TryParse(
segment, out double value))
{
readings.Add(new SensorReading
{ Value = value });
}
}
return readings;
}
In the preceding piece of code, the foreach loop creates many temporary string objects.
The following code listing is an optimized version of the same method that uses Span<T> for zero-copy access to the buffer segment.
using System;
using System.Runtime.InteropServices;
public readonly struct SensorReading
{
public double Value { get; }
public SensorReading
(double value) => Value = value;
}
public List<SensorReading>
ProcessData_Optimized(
byte[] rawBuffer, int offset, int length)
{
Span<byte> span = new ReadOnlySpan<byte>(
rawBuffer, offset, length);
var readings = new List<SensorReading>();
int currentPos = 0;
while (currentPos < length)
{
int endOfSegment = Array.IndexOf(
span.Slice(currentPos).IndexOf((byte)'|'));
if (endOfSegment == -1) break;
ReadOnlySpan<byte> dataSpan =
span.Slice(currentPos, endOfSegment);
if (double.TryParse(dataSpan,
out double value))
{
readings.Add(new SensorReading(value));
}
currentPos = endOfSegment + 1;
}
return readings;
}
In the preceding code, the optimized ProcessData_Optimized method performs much better than the non-optimized version because there are no performance-degrading activities related to string processing, memory allocations, or encoding/decoding. The unoptimized method converts the input byte array (byte[]) into a managed string via Encoding.UTF8.GetString().
In contrast, the optimized version uses ReadOnlySpan so that each portion of the input buffer can be treated as a separate slice of byte buffer. Since the optimized version does not require any intermediate objects to be created, it avoids intermediate string allocations. Hence, it will significantly reduce both processing time and memory consumption, particularly when processing large amounts of data.
Enhance Startup Time with Native AOT
Edge devices reboot more often than servers do, since the service can be restarted for several reasons. The standard .NET runtime will have JIT compilation on every start. That's reasonable for a long-running cloud service but wasteful for a gateway that may restart dozens of times a day.
Native AOT compiles your application into native code during the publishing stage. There is no JIT or on-the-fly compilation at runtime, and you don't have to ship the .NET runtime together with your app since you have a complete standalone executable.
For an edge computing service, this means startup times measured in milliseconds rather than the hundreds of milliseconds typical of JIT-based console applications. The memory and disk savings matter on limited hardware. You need to enable Native AOT in the project file:
<PropertyGroup>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
<TrimMode>full</TrimMode>
</PropertyGroup>
and then publish the project for your hardware platform using the following command:
dotnet publish -r linux-arm64 -c Release
It should be mentioned here that Native AOT has trade-offs: it doesn't support code paths that rely on reflection. Publish early to catch AOT-related errors before deploying to production.
Leverage Object Pooling
Instead of performing a series of object allocations (for example, HTTP request buffers, sensor reading packets), you should take advantage of object pooling to reduce the number of objects created in your application by reusing the objects from the pool.
Object pooling is extremely relevant in edge computing because these devices often have limited CPU cycles and memory bandwidth. Creating and destroying objects frequently leads to GC pauses, which are unpredictable delays that can cause real-time failures, a major concern at the edge. In a typical IoT or edge device, data processing involves receiving packets, buffering them in memory structures, performing calculations, and then releasing those structures.
For example, the following piece of code creates GC pressure because each time the new keyword is encountered, the runtime needs to allocate heap memory. Also, when the objects are discarded, the GC must clean them up, so it runs more frequently.
var packet = new SensorDataPacket(nextId++);
packet.ProcessData(...);
In a resource-constrained environment, this becomes challenging. Object pooling can solve this issue by maintaining a pool of ready-to-use, preinitialized objects. Object pooling works using these principles:
- Acquire: Borrow an object from the pool.
- Use: Use the object to perform the required operations.
- Release: Return the object to the pool when you're done with it.
Listing 2 demonstrates how you can take advantage of a thread-safe, simple object pool that uses a ConcurrentBag for thread-safe storage of available items.
Listing 2: The SensorDataPacket class
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
public class SensorDataPacket : IDisposable
{
public int PacketId { get; set; }
private bool _inUse = false;
public SensorDataPacket(int id)
{
Console.WriteLine($"[Constructor] Creating new
packet object with ID: {id}. (Costly Operation)");
this.PacketId = id;
}
public void MarkAsAcquired()
{
_inUse = true;
}
public void MarkAsAvailable()
{
_inUse = false;
}
public void ProcessData(double[] sensorReadings, int count)
{
if (_inUse == false)
throw new InvalidOperationException(
"Object must be acquired before use.");
Console.WriteLine($" --> Processing packet {PacketId}:
Received {count} readings.");
Thread.Sleep(1);
}
public void Reset()
{
Console.WriteLine($"[Reset] Packet {PacketId} is being
logically reset.");
this.PacketId = -1;
MarkAsAvailable();
}
public void Dispose()
{
Console.WriteLine($"[Dispose] Object for Packet
{PacketId} is permanently cleaned up.");
}
}
public class PacketPool
{
private readonly ConcurrentBag<SensorDataPacket> _pool = new
ConcurrentBag<SensorDataPacket>();
private int _nextIdCounter = 0;
public SensorDataPacket Get()
{
if (_pool.TryTake(out var packet))
{
Console.WriteLine($"[Pool] Reusing existing packet
{packet.PacketId}. (Memory efficient)");
packet.MarkAsAcquired();
return packet;
}
else
{
int newId = Interlocked.Increment(ref _nextIdCounter);
Console.WriteLine("[Pool] Cache Miss! Creating NEW
expensive object.");
var newPacket = new SensorDataPacket(newId);
newPacket.MarkAsAcquired();
return newPacket;
}
}
public void Return(SensorDataPacket packet)
{
packet.Reset();
_pool.Add(packet);
Console.WriteLine($"Successfully returned packet
{packet.PacketId} to the pool.");
}
public void Cleanup()
{
while (_pool.TryTake(out var packet))
{
packet.Dispose();
}
}
}
public class EdgeSimulation
{
public static async Task RunSimulation()
{
var pool = new PacketPool();
var tasks = new List<Task>();
Console.WriteLine("--- PHASE 1: High Traffic Burst
(Object Creation Expected) ---\n");
for (int i = 0; i < 3; i++)
{
tasks.Add(ProcessCycleAsync(pool, i));
}
await Task.WhenAll(tasks);
for (int i = 0; i < 3; i++)
{
tasks.Add(ProcessCycleAsync(pool, i + 3));
}
await Task.WhenAll(tasks);
Console.WriteLine("Simulation Complete.
Cleaning up pool resources...");
pool.Cleanup();
}
private static async Task ProcessCycleAsync
(PacketPool pool, int cycleId)
{
var packet = pool.Get();
Console.WriteLine($"[Task {cycleId}]
Acquired Packet ID: {packet.PacketId}");
try
{
await Task.Delay(50);
packet.ProcessData(new double[] { 1.1, 2.2 }, 3);
}
finally
{
pool.Return(packet);
}
}
}
Use Async and Await Judiciously
In a typical asynchronous programming approach, if a service makes a call to the network or reads the data from disk, it relinquishes control to the runtime, and other work (such as monitoring system state) can proceed in the meantime.
Assume that there is an edge gateway device that needs to read data concurrently from three different sensors (temperature, humidity, and GPS). Listing 3 shows how you can wait for the sensors without freezing the application. It demonstrates how you can read sensor data asynchronously from different local sensors over a slow serial bus or network connection.
Listing 3: The EdgeDataCollector class
using System.Diagnostics;
public class EdgeDataCollector
{
private static async Task<string> ReadTemperatureAsync()
{
Console.WriteLine("Temperature Sensor: Starting read...");
await Task.Delay(TimeSpan.FromSeconds(2));
return "Temperature: 35.5°C";
}
private static async Task<string> ReadHumidityAsync()
{
Console.WriteLine("Humidity Sensor: Starting read...");
await Task.Delay(TimeSpan.FromSeconds(1));
return "Humidity: 65%";
}
private static async Task<string> ReadGpsAsync()
{
Console.WriteLine("GPS Sensor: Starting read...");
await Task.Delay(TimeSpan.FromSeconds(3));
return "GPS Coordinates: Latitude=17, Longitude=78";
}
public static async Task RunDataCollectionAsync()
{
Console.WriteLine("Edge Device Data Collection Started");
var stopwatch = Stopwatch.StartNew();
Task<string> temperatureTask = ReadTemperatureAsync();
Task<string> humidityTask = ReadHumidityAsync();
Task<string> gpsTask = ReadGpsAsync();
string[] results = await Task.WhenAll(
temperatureTask,
humidityTask,
gpsTask);
stopwatch.Stop();
Console.WriteLine("All Data Collected Successfully!");
foreach (var result in results)
{
Console.WriteLine($"- {result}");
}
Console.WriteLine($"\nTotal execution time: {stopwatch.Elapsed.Seconds:F2} seconds.");
}
}
Asynchrony provides several benefits in edge computing:
- Non-blocking I/O: Edge devices usually use slow peripherals (such as serial ports and slow wireless connections) for communication. To keep CPU threads from sitting idle while waiting for sensor responses over unreliable connections, you can use
asyncandawait. While one sensor waits for a response, the CPU can continue other tasks, such as filtering local data or making inferences based on previously collected data. - Concurrency: You can take advantage of the
Task.WhenAll()method to parallelize multiple tasks, each of which reads data from sensors instead of executing the tasks sequentially. The overall processing time is determined by the slowest sensor, not the combined time of all sensors.
Understood.
Stream Data
Process the data as a stream rather than loading a whole file into memory. This is especially important if you are dealing with huge data streams. I/O operations, such as network reads or file creation and deletion, are generally slower than CPU processing, so design your application to avoid blocking the main processing thread during I/O.
Optimize Startup Speed
Edge devices may reboot rapidly due to power fluctuations, network problems, or failed updates.
Minimal Hosting
Use minimal APIs to reduce the resources needed to run ASP.NET Core applications; they're more efficient than other hosting models.
Prewarming
Preinitializing connections (connection pools, message brokers) ensures instant availability when the service receives its first request.
Use Profiling
Development can be misleading because development machines tend to be far more powerful than edge devices. Use the appropriate profiling methods that measure performance on embedded Linux platforms (such as perf and monitoring agents).
Thread Management
Ensure that the number of active threads does not exceed the number of cores since too many threads lead to unnecessary context switching overhead.
Observability
You should take advantage of structured logging and use correlation IDs to help analyze log messages regardless of which microservice created the message. The following code snippet illustrates how you can implement a simple logger for handling your log messages.
using System.Text.Json;
public class EdgeLoggerService
{
record LogEntry(string TraceId,
string ServiceName,
int SeverityLevel,
DateTime Timestamp,
string Message);
public void LogEvent(string traceId,
string service,
string message,
int severity)
{
var entry = new LogEntry(traceId,
service,
severity,
DateTime.UtcNow,
message);
string jsonOutput =
JsonSerializer.Serialize(entry);
Console.WriteLine($"[LOG] {jsonOutput}");
}
}
public void HandleIncomingRequest
(Guid incomingTraceId)
{
string currentTraceId =
incomingTraceId.ToString();
EdgeLoggerService logger =
new EdgeLoggerService();
try
{
logger.LogEvent(
currentTraceId, "API_GATEWAY",
"Successfully received and started processing
request.", 1);
}
catch (Exception ex)
{
logger.LogEvent(
currentTraceId, "API_GATEWAY",
$"Critical Error: {ex.Message}", 3);
}
}
Data Consistency Vs. Latency Trade-Off
Data consistency versus latency is a complex concept to understand. For example, there may be several copies of the same information at different locations along the network. One example could be information about the number of available resources or a patient's medical record data. Therefore, we require all copies of this data to be consistent, meaning they all keep providing the same version of the same information no matter when and where they were checked.
The trade-off is between the latency (i.e., the speed with which we can gain access to the information) and the consistency discussed above. Thus, we can either choose low latency and get fast access to the information and accept discrepancies in the data or accept higher latency to keep the data consistent.
Building Real-Life Edge Applications with .NET and Azure IoT
To build and deploy an edge application using Azure IoT, C#, and .NET, you should follow the steps outlined below:
- Set up the development environment
- Create your Azure IoT Edge application
- Test the Azure IoT Edge application
- Deploy the edge application
- Monitor and manage the Azure IoT Edge application
Using Azure IoT Edge Tools in Visual Studio
Azure IoT Edge Tools simplify the development, debugging, and deployment of your IoT Edge solutions in Visual Studio. The tools help you to do each of the following:
- Create Azure IoT Edge projects that can target different platforms
- Add a new IoT Edge module locally
- Build and push Docker images of your IoT Edge modules
- Execute your IoT Edge modules in a remote or local simulator
To get started using Azure IoT Edge Tools in Visual Studio, download them from the Visual Studio Marketplace: https://marketplace.visualstudio.com/items?itemName=vsc-iot.vs17iotedgetools
The Azure IoT Edge Dev Tool is the preferred development tool for building and deploying Azure Edge applications.
Install the vcpkg library manager using the following commands at the Windows Command Prompt:
git clone https://github.com/Microsoft/vcpkg
cd vcpkg
bootstrap-vcpkg.bat
Next, install the azure-iot-sdk-c package using the following commands:
vcpkg.exe install azure-iot-sdk-c:x64-windows
vcpkg.exe --triplet x64-windows integrate install
Next, download and install a Docker-compatible container management system on your computer. If you would like to develop modules using Linux containers, you can use Docker Desktop.
In the next step, create an Azure Container Registry or Docker Hub to store your module images. Next, install the Azure CLI on your computer. Note that you should have an active IoT Hub with a minimum of one IoT Edge device to test your module on a device.
Create an Azure IoT Edge Project in Visual Studio
Follow the steps below to create an IoT Edge project in the Azure portal or the Azure CLI for testing purposes. First off, you should build the solution in your Visual Studio IDE.
The process begins with creating a solution, which serves as a deployment package for the edge application.
Launch the Visual Studio IDE.
- Select Create a new project.
- Search for the Azure IoT Edge template and select it.
- Select the required template and click Next.
- Specify the project name and location.
- Click Create to complete the process.
The Solution Structure
Visual Studio creates a solution that typically includes the following:
- Edge application project: The primary project that explains how the modules interact and what image compositions need to be applied.
Moduleprojects: These projects are subcomponents that typically represent containerized business logic.
You can right-click the working solution and select Add new project to create your module projects.
Containerization
Modules operating in the edge environment are organized in containers. You deploy the container, which includes the runtime environment and program, rather than the code alone.
Create a Dockerfile: The template might help you build a Dockerfile, but you may have to create it independently.
Describe the dependencies: The Dockerfile should give instructions to Docker about how to build a container.
Ensure that the connection string or identity settings of your module point to your IoT Hub (the name you created in Azure).
In the testing phase, Visual Studio generally makes use of simulated credentials. For actual deployment cases, you will need to ensure that the edge runtime installed on the physical device has the right security tokens to authenticate with the IoT Hub.
Right-click the solution and select the Build option to compile all the modules.
Test and Run the Application
Visual Studio allows you to run IoT Edge locally. You need to select Debug > Start Debugging (or use the specific button for Edge Device Simulator).
During simulation, the debugger will:
- Build the local Docker images for the modules.
- Run these images locally, making it possible to simulate the environment of the edge gateway.
- Provide you with the opportunity to control the module endpoints and see the data passing through the simulated connection to IoT Hub.
Deployment
In real-world deployments, you will use the Azure portal or infrastructure-as-code tools such as Terraform or Bicep to perform this task, while in Visual Studio you get to integrate all the process steps:
Select the device group or IoT Hub connection to serve as your target.
Then, you should employ the Publish/Deploy feature in Visual Studio to package all your Dockerized modules, together with their configurations, into an artifact bundle.
This uploads your app securely to the IoT Edge device group you selected, where the edge runtime downloads the required containers.
Monitor and Iterate
To check if your job is running, you need to return to the Azure portal at the Edge Jobs section to see the job you deployed on the portal.
Building and Deploying an Edge Module in .NET
To transition from the console demo that we implemented earlier in this article to something you would typically execute on your IoT Edge device, you will need the following three components:
- A module with the capability of communicating with the IoT Edge SDK via its message protocol.
- A container image for the module.
- A deployment manifest containing instructions regarding what modules should be executed by the IoT Edge runtime and what interactions are permitted among those modules.
Note that the standalone “Azure IoT Edge Tools for Visual Studio” extension was last updated in Visual Studio 2022 but can be used in Visual Studio 2026 as well.
The recommended method, however, for creating modules is the Azure IoT Edge extension for VS Code along with the Azure CLI's az iot edge commands. The steps below work with any editor.
Prerequisites
You need the .NET SDK (which you have installed earlier in this article); either Docker Desktop or another container runtime that can be used to construct and execute the module images; the Azure CLI with the IoT extension installed (using the command “az extension add –name azure-iot”); and finally, an IoT Hub with at least one registered IoT Edge device for test purposes.
Writing the Module
An IoT Edge module is a .NET console application that uses Microsoft.Azure.Devices.Client to communicate with the IoT Edge runtime. The module will automatically use the injected environment variables provided by the runtime to connect to the runtime (there's no need to manage a connection string manually), receive incoming messages from an input channel, and send outgoing results to an output channel.
var moduleClient = await
ModuleClient.CreateFromEnvironmentAsync();
await moduleClient.OpenAsync();
await moduleClient.SetInputMessageHandlerAsync(
"input1", async (message, ) =>
{
await moduleClient.SetInputMessageHandlerAsync(
"input2", async (message, ) =>
{
var payload = Encoding.UTF8.GetString(
message.GetBytes());
var reading =
JsonSerializer.Deserialize(payload);
if (reading!= null &&
reading.Value > AlertThreshold)
{
JsonSerializer.SerializeToUtf8Bytes(reading));
await moduleClient.SendEventAsync("output1",
alert);
}
return MessageResponse.Completed;
}, null);
await Task.Delay(Timeout.Infinite);
Note that “input1” and “output1” don't refer to specific topics; they're user-defined endpoints. With just a few changes in the deployment manifest, the user would be able to introduce filtering, have multiple data consumers, or replace a cloud endpoint with a local one without modifying any lines of code.
Containerizing the Module
Multistage builds limit the final image to what's required for execution (the published output), not the entire SDK. Since IoT Edge modules are distributed in container images, you will need a Dockerfile.
FROM mcr.microsoft.com/dotnet/sdk:11.0 AS build
WORKDIR /src
COPY..
Run dotnet publish –c
release –r linux-arm64 --self-contained –o /app
FROM mcr.microsoft.com/dotnet/runtime-deps:11.0
WORKDIR /app
COPY --from=build /app.
ENTRYPOINT ["./EdgeAlertModule"]
Note that if you're using x64 edge hardware, you should use linux-x64 instead of linux-arm64, then append -p:PublishAot=true to the publish command. You will not need runtime-deps because a Native AOT build does not require a managed runtime to support it.
Build and publish to a registry that is accessible by your IoT Edge device using these commands:
docker build -t myregistry.azurecr.io/edge-alert-
module:1.0.
docker push myregistry.azurecr.io/edge-alert-
module:1.0
Deploying and Connecting Routes
A deployment manifest is used by the IoT Edge runtime to determine which modules to deploy on a device and what routes those modules will take when communicating with each other.
The following minimal manifest deploys the module we just created as well as the standard built-in edgeHub module and route any alerts generated by our new module to the cloud.
{
"modulesContent": {
"$edgeAgent": {
"properties.desired": {
"modules": {
"edgeAlertModule": {
"type": "docker",
"settings": {
"image":
"myregistry.azurecr.io/edge-alert-module:1.0"
}
}
}
}
},
"$edgeHub": {
"properties.desired": {
"routes": {
"alertsToCloud": "FROM /messages/modules/
edgeAlertModule/outputs/output1 INTO $upstream"
}
}
}
}
}
To deploy the manifest to your device, use the following command:
az iot edge set-modules --hub-name \
--device-id --content deployment.json
The runtime retrieves the image, launches the module, and creates a route; altering the method of communication among modules requires updating the manifest, rather than redeploying.
Monitoring
The az iot hub monitor-events –hub-name –device-id is the quickest method for verifying that a deployment was successful and that the edge device is sending data as expected.
Edge Computing Vs. Cloud Computing Vs. Fog Computing
Although edge, cloud, and fog computing overlap, they're distinct paradigms that address different aspects of distributed computing. While they are based on distributed computing, focusing on provisioning computing and storage resources based on the data generated, they differ in terms of where the resources are located.
Edge computing and cloud computing are technologies that differ in terms of where the data is eventually processed. In the former, most of the data processing occurs at the network edge, whereas in the latter, data processing takes place at a central location. Edge computing does not replace cloud computing. These two technologies are not interchangeable. Rather than supplanting the cloud, edge computing works with the cloud to provide enhanced performance for processing time-sensitive data.
Fog computing, sometimes called edge fog computing, extends edge computing by introducing a distributed computing layer between edge devices and the cloud infrastructure. By using fog computing, you can bring certain cloudlike capabilities such as storage, computing, and networking closer to the edge, but not as close as with edge computing. It's well suited to smart cities, manufacturing, and healthcare, which need real-time analytics, data filtering, and intermediate processing.
While these technologies may share similarities, you must understand how they differ before deciding where to implement a set of logic. Edge computing extends processing as close to the actual source as possible; cloud computing does the opposite by transferring processing to the data center; fog computing is a kind of hybrid solution as it combines elements of edge and cloud computing and offers some additional services that are similar to those provided by cloud computing without making it completely cloud based. Edge computing doesn't replace cloud computing. Instead, it helps reduce the workload by processing time-sensitive data.
Applications of Edge Computing
Edge computing is well suited to industries where you need quick decision-making or have limited connectivity, including:
- **Manufacturing: **Edge computing is useful in the manufacturing industry because it enables devices at the edge to provide data to nearby machines, robots, and users without requiring a large amount of network bandwidth. Industrial scanners and sensors are used to monitor the production processes and determine if a defect occurred during production without waiting for data to reach the data center.
- **Industrial IoT (IIoT): **Edge computing is used in IIoT to perform intelligent manufacturing and predictive maintenance. In manufacturing units, sensors and other devices generate data that is used to improve product quality and reduce downtime. Predictive maintenance is only possible if certain sensors transmit information about vibrations and wear immediately.
- **Smart cities: **As a result of the exponential growth in the applications of cloud computing and edge computing, along with IoT, there is an increasing need to invest in more sustainable ways of living, such as building smart cities. Traffic signals and transit systems keep track of real-time developments, something that is impossible to achieve if one tries to limit the communication scope to a cloud-based center.
Ready
Understood. - **Healthcare: **Wearable devices can analyze data collected on the spot instead of sending it via an internet connection. The rapid response times enabled by lower latency can save lives in emergencies. Integrating edge computing and AI, including AI-assisted surgery, has significantly changed the healthcare landscape, revolutionizing its practices and outcomes.
The Future
The advent of edge computing and its subsequent surge have ushered in a new era of data analytics. Although it is still in its infancy, edge computing promises much in the coming years. To ensure reliability, edge computing requires high-speed connectivity since it depends on the cloud to process and store data.
With advances in semiconductor technology, microcontrollers (MCUs) and processors now have greater processing power, specialized hardware components, and computational capabilities. You can now deploy deep and convolutional neural networks at the edge and use them for faster analysis.
Edge computing is a technology that decentralizes intelligence, enabling developers to leverage .NET's unique features, including cross-platform capabilities, speed, and asynchronous techniques, to build resilient, low-latency systems that can operate independently in even the most challenging environments.
The edge ecosystem is not simply a combination of single nodes; it comprises a network of interlinked nodes that possess self-healing properties. In other words, it's a distributed system that implements local data processing to resolve global issues at an unprecedented speed. To succeed with edge computing, follow key principles such as asynchrony for resilience, containerization for flexibility, and zero trust for security.
Edge computing continues to mature; however, trends show that the cost of edge devices, for example, microcontrollers and processors capable of running convolutional neural networks locally, will continue to decrease, as will the cost of network connections to the cloud. Both trends are driving more workload from the cloud to the device.
The underlying principles that apply to each of these scenarios include using asynchronous I/O to keep slow sensors out of the critical path; containerizing your modules to allow independent updates and reasoning about each module; and defaulting to zero trust when transferring data over a network that may or may not be secure.
Takeaways
- Edge computing takes data generated at the source (i.e., a device or nearby server), processes it locally, and sends only what's needed to the central data center, rather than sending everything.
- Edge computing provides isolated processing at the edge of the network, whereas cloud computing routes all traffic through a single central route, which can become heavily congested.
- Edge computing is being used to develop smart homes, where multiple devices can communicate with each other and execute commands instantly. With its great processing power and minimal latency, edge computing is ideal for use in home automation systems.
- Utilizing real-time analytics and machine learning methods, edge computing enables the continuous monitoring of critical decision-making processes.



