Skip to content
LATEST

🚀 Welcome to Upgradix by Shrash Studio – Your destination for free technology learning and career growth.

Upgradix
Upgradix Code. Learn. Ship.

Capstone Project: Event-Driven Order & Notification Microservices

In this capstone, we connect three .NET microservices – an Order API, an Inventory Worker, and an Email Service – using RabbitMQ Topic Exchanges, Raft-replicated Quorum Queues, and automated DLX delayed retries. Orders stay fast and safe even when downstream services fail.

Capstone Project: Event-Driven Order & Notification Microservices

Quick Answer: In this capstone, we connect three .NET microservices – an Order API, an Inventory Worker, and an Email Service – using RabbitMQ Topic Exchanges, Raft-replicated Quorum Queues, and automated DLX delayed retries. Orders stay fast and safe even when downstream services fail.

Imagine Karthik runs an online electronics store in Hyderabad. During a festival sale, Meena clicks Buy Now on wireless headphones (order ORD-9021).

At peak traffic, 2,000 shoppers place orders every minute. If the email provider blinks for 5 seconds, or a server restarts, Karthik cannot lose Meena's order or double-deduct stock.

How do we combine everything from this series into one production-ready .NET microservices system?

1. Why Do We Need an Event-Driven Microservices Architecture?

The problem without RabbitMQ reliability patterns

In a basic setup, the Order API calls the Inventory database and the SMTP email server in one HTTP request.

Example 1: Fragile synchronous checkout in Order API

This works for 10 shoppers, but breaks during a festival sale.

public async Task<IActionResult> PlaceOrderAsync(OrderRequest req)
{
    await _db.SaveOrderAsync(req);
    await _inventoryHttp.ReserveStockAsync(req.Sku);  // Blocks if slow
    await _smtpClient.SendEmailAsync(req.Email);      // Fails if SMTP blinks
    return Ok();
}

What happens under load

Order ORD-9021 -> Stock reserved OK
Order ORD-9021 -> SMTP 503 Service Unavailable!
Result: Meena sees an error, retries checkout, and gets charged twice.

This setup works on a quiet Tuesday. However, it breaks when real traffic and network glitches arrive.

  1. A 5-second SMTP glitch fails Meena's entire checkout.
  2. If a classic RabbitMQ queue loses its broker node, unconfirmed orders vanish.
  3. Without a retry pipeline, failed emails are dropped forever.

The solution: Exchanges + Quorum Queues + DLX Retries

Quorum Queue = a replicated RabbitMQ queue that uses the Raft consensus algorithm to prevent data loss on node crashes.

Dead-Letter Exchange (DLX) = a fallback exchange that catches rejected or expired messages so we can retry them later.

In our capstone, Karthik's Order API publishes one order.created event to a Topic Exchange. RabbitMQ routes it to two Quorum Queues, and if the Email Service hits a glitch, the DLX automatically retries it after 5 seconds.

Live Capstone Flow: Order, Quorum Queues & Automated DLX Retry

Watch Meena's order succeed in Inventory while Email Service recovers automatically from a transient SMTP error.

Phase 1: Meena places order ORD-9021
Meena (Hyderabad)
POST /api/orders (ORD-9021)
Order API (.NET)
Publishes order.created
Publisher Confirm · ecommerce.events (Topic)
q.inventory (Quorum)
Raft-replicated · Durable
q.email (Quorum)
Bound to ecommerce.dlx
Inventory Worker (.NET)
Reserves stock → BasicAck
Email Service (.NET)
Sends receipt to Meena

Automated DLX Delayed Retry Pipeline

ecommerce.dlx
Catches Nacked email event
q.email.retry (5s TTL)
Waits 5s → Returns to q.email
Active Flow Processed / Acked Transient Error → DLX

Inventory reserves stock immediately. When Email Service hits a brief SMTP outage, it Nacks the message to ecommerce.dlx, waits 5 seconds in q.email.retry, and succeeds on retry.

2. Building the Capstone in .NET (C#)

To make queues safe across broker restarts, we set x-queue-type to quorum and attach our Dead-Letter Exchange.

Example 2: Declaring the Email Quorum Queue with DLX in C#

Run this topology setup when the Email Service starts.

await channel.ExchangeDeclareAsync("ecommerce.events", ExchangeType.Topic, durable: true);
await channel.ExchangeDeclareAsync("ecommerce.dlx", ExchangeType.Direct, durable: true);

var queueArgs = new Dictionary<string, object?>
{
    ["x-queue-type"] = "quorum",
    ["x-dead-letter-exchange"] = "ecommerce.dlx",
    ["x-dead-letter-routing-key"] = "email.retry"
};

await channel.QueueDeclareAsync("q.email", durable: true, exclusive: false, autoDelete: false, arguments: queueArgs);
await channel.QueueBindAsync("q.email", "ecommerce.events", "order.created");

Inside the Email Service BackgroundService, we use manual acknowledgments so failing messages route cleanly to the DLX.

Example 3: Handling transient failures with BasicNackAsync

Setting requeue: false sends the message to ecommerce.dlx instead of blocking the queue.

consumer.ReceivedAsync += async (_, ea) =>
{
    try
    {
        await _emailSender.SendReceiptAsync(ea.Body);
        await channel.BasicAckAsync(ea.DeliveryTag, multiple: false);
    }
    catch (SmtpException)
    {
        // Route to ecommerce.dlx -> q.email.retry (5s TTL)
        await channel.BasicNackAsync(ea.DeliveryTag, multiple: false, requeue: false);
    }
};

Expected console output across the three .NET services

[OrderAPI]        Published order.created for ORD-9021 (Confirmed)
[InventoryWorker] Reserved 1x Wireless Headphones -> BasicAck
[EmailService]    SMTP 503 error for ORD-9021 -> BasicNack (Sent to DLX)
[EmailService]    Retry #1 after 5s: Receipt sent to Meena -> BasicAck

Meena gets an instant checkout confirmation, stock is updated in milliseconds, and her email arrives 5 seconds later once SMTP recovers.

3. Synchronous Checkout vs. Event-Driven Capstone

Synchronous HTTP checkout vs. RabbitMQ Capstone Architecture
Synchronous HTTP calls Event-driven RabbitMQ capstone
Checkout fails if Email Service is down. Order API stays up; Email Service retries via DLX.
Hard to scale Inventory independently. Add more Inventory Worker pods anytime.
Broker crash risks losing in-flight orders. Quorum Queues replicate orders across nodes.

The important terms to remember

  • Quorum Queue = a durable, Raft-replicated queue built for high availability and zero data loss.
  • Dead-Letter Exchange (DLX) = an exchange that receives rejected or expired messages for safe retries.
  • Manual Ack = telling RabbitMQ to delete a message only after the .NET worker finishes safely.

Design tip: Always store processed MessageId values in MS SQL Server or Redis inside the Inventory Worker. That guarantees at-least-once delivery never deducts Meena's headphones twice.

4. Common Mistakes to Avoid

1. Calling BasicNack with requeue: true on errors

If SMTP is down, setting requeue: true puts the message right back at the front of q.email. Your worker will hammer SMTP 1,000 times per second.

Better approach: Use requeue: false so RabbitMQ routes the message to a DLX retry queue with a 5-second TTL.

2. Running Classic Queues for order data in production

Classic queues do not replicate safely across cluster nodes. A single server crash can wipe out paid orders.

Better approach: Always declare x-queue-type: quorum for critical business workflows like orders and payments.

5. Interview Questions & Practice

Question 1: Walk me through what happens if the Email Service is down for 10 minutes during a sale.

What the interviewer expects: Understanding of decoupling, queue durability, and graceful recovery.

Strong answer: "Karthik's Order API keeps accepting orders because it only publishes to the Topic Exchange. The Inventory Worker keeps reserving stock from q.inventory. Meanwhile, q.email safely buffers all email events on disk using Quorum replication, and as soon as the Email Service comes back online, it drains the backlog without losing a single receipt."

Practice: Bus ticket booking capstone

Adapt this capstone for a bus ticket app with a Booking API, Seat Allocation Worker, and WhatsApp Alert Service. Name your Topic Exchange, two Quorum Queues, and the DLX retry queue.

Expected result: Exchange bus.booking.events, Quorum Queues q.seat.allocation and q.whatsapp.alerts, plus bus.dlx routing to q.whatsapp.retry.

6. Next Steps

  • Previous Article: Leveling Up with MassTransit in C#
  • Series Complete: You have completed all 20 articles in the RabbitMQ & .NET Microservices series.

Discussion & Comments

1
Guest mode · Login / Register
Post directly as a guest or log in first.
S
S.Daniel Guest
Nov 23, 2026

<p>Such a useful resource to have,<br> everything is taught in a well mannered structure.</p>

This article is protected. Printing and saving as PDF are disabled.