Skip to content

Server-Sent Events in .NET 10 - Pedro Constantino

Whether you’re tracking order status, pushing instant notifications, or streaming live data, keeping clients synchronized with your server is essential for modern applications. Here’s the good news. .NET 10 brings native Server-Sent Even...

00:00 / --:--

Read by your browser's built-in voice.

Whether you’re tracking order status, pushing instant notifications, or streaming live data, keeping clients synchronized with your server is essential for modern applications.

Here’s the good news.

.NET 10 brings native Server-Sent Events (SSE) support to ASP.NET Core. No third-party libraries, no complex setup.

SSE gives you a simple, HTTP-based way to push updates to clients, and it’s built right into Minimal APIs and controllers.

Today, I want to show you how to implement production-ready real-time features with SSE.

What Are Server-Sent Events?

Server-Sent Events (SSE) is an HTTP-based technology that allows servers to push automatic updates to clients through a single, long-lived connection. The key difference from WebSockets? SSE is unidirectional, server to client only.

This makes SSE perfect for scenarios where clients just need to listen. Live dashboards, real-time notifications, streaming metrics, activity feeds. Any case where the server pushes data and the client consumes it.

When a client connects to an SSE endpoint, the server responds with the text/event-stream content type and keeps the connection open.

As events occur, the server writes them to the stream in a text-based format:

event: orderShipped
id: 123
data: {"orderId": "1234", "status": "shipped"}
			

The browser’s EventSource API handles everything automatically. Parsing events, triggering callbacks, even reconnecting if the connection drops.

.NET 10 introduces native SSE support with the TypedResults.ServerSentEvents method. You can now implement SSE endpoints directly in Minimal APIs or controllers without any third-party libraries.

The method signature is elegant:

C#

TypedResults.ServerSentEvents<T>(IAsyncEnumerable<SseItem<T>> items)

Implementing SSE in a Minimal API with .NET 10

Here’s how you implement a Server-Sent Events endpoint in .NET 10. It’s remarkably simple.

C#

app.MapGet("/api/orders", (OrderService service, CancellationToken ct) =>
{
    return TypedResults.ServerSentEvents(
        service.GenerateOrders(ct),
        eventType: "order"
    );
})
.WithName("GetOrders")
.WithOpenApi();
			

That’s it. No configuration, no middleware, no additional packages.

When a client connects to this endpoint, ASP.NET Core automatically detects that you’re returning ServerSentEvents and does something clever.

It adds an endpoint filter that intercepts the response. Instead of closing the connection after sending data, it keeps it alive. As your IAsyncEnumerable yields items from GenerateOrders, ASP.NET streams each one to the client in the SSE format.

The connection stays open until the enumerable completes or the client disconnects.

The async enumerable pattern means you can stream data from anywhere, Entity Framework queries, message queue consumers, SignalR hubs, external APIs. If it can be enumerated asynchronously, it can be streamed to clients via SSE.

SSE vs Other Real-Time Technologies

You have several options when building real-time features. Let’s break down when to use each one.

Technology

Direction

Protocol

Reconnection

Complexity

Infrastructure

Use When

Server-Sent Events

Unidirectional (Server → Client)

HTTP/1.1, HTTP/2

Automatic (built-in browser)

Low

Standard HTTP servers, works with proxies

Push notifications, live feeds, streaming updates, progress tracking

WebSockets

Bidirectional (Server ↔ Client)

TCP with HTTP upgrade

Manual implementation

Medium-High

Requires WebSocket support, some proxies block it

Chat applications, multiplayer games, collaborative tools

Long Polling

Unidirectional (Server → Client)

HTTP

Manual (client retries)

Medium

Standard HTTP, high server overhead

Legacy browser compatibility only

SignalR

Bidirectional (Server ↔ Client)

Abstraction (WebSockets/SSE/Long Polling)

Automatic with fallback

High

Additional library, more memory

Complex scenarios needing automatic transport selection

SSE handles 70% of real-time scenarios with 10% of the complexity.

Now, we don’t need to add WebSocket complexity unless you actually need clients talking back to the server constantly.

Conclusion

Server-Sent Events in .NET 10 makes real-time features straightforward. No complex setup, no third-party libraries, just native HTTP-based streaming that works everywhere.

The beauty of SSE is its simplicity.

Start simple. Build your real-time features with SSE. Add complexity only when you actually need it.

Thank you for reading.

See you next time!

Sponsors

- Check out this powerful framework on ABP Framework for .NET. A game-changing platform for building robust, modular, and maintainable applications faster than ever

Source: Pedro Constantino

Original article: Server-Sent Events in .NET 10 - Pedro Constantino

Original author: Pedro Constantino

Rate this article

Rate this article out of 5

No ratings yet
Be the first to rate this article.

Selecting a star will ask you to sign in.
HV
Huy Vũ
Contributor at Selectgo

Shares practical engineering notes on this blog.