Microservices promote modularity by breaking down applications into small, loosely coupled services, with each service responsible for a particular function. The transition from monolithic applications to microservices architecture has transformed the way we develop software. This shift has improved scalability, resilience, and high availability, as each service can be developed, deployed, and managed independently.
A message broker plays a vital role in enabling asynchronous communication between microservices. It guarantees event-driven, decoupled interactions, allowing services to communicate effectively, regardless of response times. One popular solution for these asynchronous microservices communications is the Publish/Subscribe (Pub/Sub) messaging model.
NCache, an in-memory distributed cache for .NET 8 and ASP.NET Core, offers improved Pub/Sub messaging features. It guarantees fault tolerance, message persistence, and scalability while facilitating high-performance and event-driven microservice interaction.
Key Takeaways
Sub-Millisecond Latency: By moving the messaging layer from disk to in-memory storage, NCache eliminates the I/O overhead typical of traditional databases, ensuring high-speed event distribution.
Decoupled Scalability: Utilizing NCache as an event bus allows microservices to communicate asynchronously, enabling individual services to scale independently without causing system-wide bottlenecks.
Linear Throughput Growth: The distributed architecture of the NCache Pub/Sub model ensures that message handling capacity increases linearly as new nodes are added to the cluster.
Reliable Event Distribution: Features such as durable subscriptions and message expiration ensure that even in high-traffic environments, event delivery remains consistent and manageable.
How to Scale .NET Microservices with NCache In-Memory Pub/Sub
NCache enables real-time messaging between microservices by defining topics for publishing and subscribing to events. A publisher microservice sends events to the NCache message broker, while subscriber microservices handle events asynchronously.

Figure 1: Decoupled microservices communication using NCache as an in-memory event bus.
The updated Pub/Sub messaging in NCache aligns with .NET 8 and ASP.NET Core microservices architecture, integrating seamlessly with the latest frameworks. Below is a logical representation of NCache as an event bus for microservices:
Implementing NCache as a High-Performance Event Bus in .NET 8
In .NET 8 and ASP.NET Core microservices, NCache acts as an event bus for sending messages to multiple subscribers. Developers can use the NCache Pub/Sub APIs for messaging that is fast and has low delays, avoiding the need for external message brokers such as RabbitMQ or Kafka.

Figure 2: Scalable backend communication between containerized microservices via an NCache in-memory broker.
Implementing Pub/Sub with NCache in .NET 8
The following example demonstrates how NCache enables Pub/Sub messaging in a real-world scenario, using the eShopOnContainers sample application.
Publishing an Event (Basket Checkout Example)
The following code snippet from the Basket.API microservice showcases publishing a user checkout event to the NCache Pub/Sub message broker.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[Route("checkout")] [HttpPost] public async Task CheckoutAsync([FromBody] BasketCheckout basketCheckout, [FromHeader(Name = "x-requestid")] string requestId) { var userId = GetUserIdentity(); basketCheckout.RequestId = GetRequestID(); var basket = await GetBasketAsync(userId); var userName = User.FindFirst(x => x.Type == "unique_name").Value; var eventMessage = new UserCheckoutAcceptedIntegrationEvent(userId, userName, basketCheckout.Address, basketCheckout.CardNumber, basketCheckout.RequestId, basket); // Publish message to NCache Pub/Sub store eventBus.Publish(eventMessage); } |
Subscribing to an Event (Order Processing Example)
The Ordering.API microservice subscribes to the UserCheckoutAcceptedEvent and processes the order when a user completes checkout.
|
1 2 |
var eventBus = app.ApplicationServices.GetRequiredService(); eventBus.Subscribe<UserCheckoutAcceptedEvent, IIntegrationEventHandler>(); |
Technical Comparison: Disk-Based Messaging vs. NCache In-Memory Pub/Sub
The following table summarizes the key performance and architectural differences between traditional disk-based messaging and NCache’s in-memory Pub/Sub model.
| Feature | Disk-Based Messaging (e.g., RabbitMQ, SQL) | NCache In-Memory Pub/Sub |
|---|---|---|
| Primary I/O Path | Disk-bound persistence (fsync) | Memory-bound (DRAM) |
| Latency Profile | Milliseconds (Variable due to Disk I/O) | Sub-millisecond (Predictable) |
| State Management | Durable (Messages survive a full reboot) | Volatile/Replicated (Speed-optimized) |
| Scaling Model | Vertical or Cluster-Partitioned | Linear Horizontal (Dynamic Membership) |
| Throughput Bottleneck | Disk contention and Transaction logs | Network Bandwidth / CPU |
| Message Ordering | Strict (often causes Head-of-Line blocking) | High-concurrency (Parallel distribution) |
What’s New in NCache Pub/Sub Messaging for .NET 8?
The following are some features NCache provides:
- Durable Subscriptions for Reliable Message Delivery
Microservices may join or leave dynamically, and network failures can disrupt message delivery. NCache ensures message durability with two subscription modes:
- Shared Durable Subscriptions: Multiple subscribers receive messages using a round-robin distribution, ensuring fault tolerance.
- Exclusive Durable Subscriptions: A single active subscriber processes the message while preventing duplicate handling.
- Improved Resilience with Connection Retries
NCache maintains a persistent connection between microservices and the message broker, even in the event of temporary network failures. It implements:
- Automatic reconnection mechanisms to restore connections.
- Keep-alive signals to prevent unexpected connection drops.
Why Choose NCache for Microservices Messaging?
As organizations make the shift, NCache provides a robust, distributed message broker optimized for .NET 8 and ASP.NET Core applications. Here’s why NCache is an ideal choice:
- High-Speed, In-Memory Messaging
Unlike traditional message brokers, NCache is entirely in-memory, offering sub-millisecond latency for Pub/Sub messaging. This ensures real-time event processing, even under high loads.
- Linearly Scalable Message Processing
NCache supports dynamic scaling. As more microservices are added, the Message Broker cluster expands dynamically to handle higher message volumes efficiently.
- Fault-tolerant and Highly Available
NCache provides the following reliability features:
- Peer-to-peer clustering removes single points of failure.
- Automatic replication ensures messages are persisted across nodes.
- Seamless server additions/removals without service disruption.
- Native .NET 8 and ASP.NET Core Support
NCache offers the following features to ensure seamless integration:
- Fully compatible with modern cloud-native architectures.
- Works with gRPC-based communication in microservices.
- Supports containerized environments (Docker, Kubernetes, Azure).
Conclusion
Effective inter-service communication is essential as microservices architectures keep changing. With NCache, Pub/Sub messaging is simplified, performance bottlenecks are eliminated, and a rugged, high-speed messaging foundation for .NET 8 and ASP.NET Core microservices is provided.
To explore more, check out our blog on Scaling Microservices Performance with Distributed Caching!
Frequently Asked Questions (FAQ)
Q: How does NCache ensure message delivery if a subscriber microservice disconnects?
A: NCache utilizes Durable Subscriptions to maintain message integrity during service interruptions. Unlike standard subscriptions, a durable subscription persists on the server side; if a microservice goes offline, NCache retains the messages for that specific subscription and delivers them once the service reconnects, provided the message has not expired.
Q: Can NCache Pub/Sub handle communication between different programming languages?
A: Yes. NCache supports cross-platform messaging, allowing microservices written in different languages (such as a mix of .NET and Java) to communicate over the same topic. By using JSON for message serialization, services can share data seamlessly across different runtime environments.
Q: What is the advantage of a shared durable subscription in a clustered environment?
A: A Shared Durable Subscription allows multiple instances of a microservice to share the load of a single subscription. NCache distributes the messages among these instances using a round-robin approach. This ensures that even if one instance fails, the other active instances continue processing the messages, providing built-in fault tolerance and load balancing.
Q: How does NCache prevent the message broker from becoming a scalability bottleneck?
A: NCache avoids bottlenecks through its distributed peer-to-peer architecture. Unlike centralized brokers that may have a single point of failure, NCache distributes the message topics and the processing load across all nodes in the cluster. As message volume increases, you can add more servers to the cluster to achieve linear increases in throughput and capacity.






