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.
Using NCache In-Memory Pub/Sub for Microservices
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: Pub/Sub as a messaging broker between microservices.
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:
NCache as an Event Bus in .NET 8 Microservices
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: NCache as an event bus in the eShopOnContainers application.
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.
Subscribing to an Event (Order Processing Example)
The Ordering.API microservice subscribes to the UserCheckoutAcceptedEvent and processes the order when a user completes checkout.
New NCache Features in 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!