1. 🌍 What are Microservices?
Microservices architecture is an approach to building applications as a collection of independent, loosely coupled services that communicate over lightweight protocols (like HTTP or gRPC).
Key benefits
Independent development & deployment.
Technology flexibility (polyglot services).
Scalability per service.
Fault isolation.
Asp.Net Core is widely used for building microservices because of its performance, cross-platform support, container-friendliness (Docker), and modern API capabilities.

2. 🧩 Core Components of ASP.NET Core Microservices
API Gateway
A single entry point for clients.
Handles routing, load balancing, authentication, and aggregation.
Microservices (independent APIs)
Each service owns its data and logic.
Examples: Order Service, Product Service, Payment Service.
Database per Service
Each service should have its own persistence.
Communication
RESTful APIs, gRPC, or messaging (RabbitMQ, Kafka, Azure Service Bus).
Observability
Logging, monitoring, and distributed tracing (OpenTelemetry).
3. ⚡ ASP.NET Core Microservice Example
Let’s create a ProductService and an OrderService.
(a) Product Microservice
// Program.cs - Minimal API (ASP.NET Core 10)
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
var products = new List<Product>
{
new Product { Id = 1, Name = "Laptop", Price = 1200 },
new Product { Id = 2, Name = "Headphones", Price = 150 }
};
app.MapGet("/products", () => products);
app.MapGet("/products/{id}", (int id) =>
products.FirstOrDefault(p => p.Id == id) is Product product
? Results.Ok(product)
: Results.NotFound());
app.Run();
record Product(int Id, string Name, decimal Price);
👉 This microservice exposes REST APIs for products.
(b) Order Microservice (consumes ProductService)
// Program.cs
using System.Net.Http.Json;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
List<Order> orders = new();
app.MapPost("/orders", async (OrderRequest request) =>
{
using var client = new HttpClient();
var product = await client.GetFromJsonAsync<Product>(
$"http://localhost:5000/products/{request.ProductId}");
if (product is null)
return Results.NotFound("Product not found");
var order = new Order(Guid.NewGuid(), product.Id, product.Price, DateTime.UtcNow);
orders.Add(order);
return Results.Ok(order);
});
app.MapGet("/orders", () => orders);
app.Run();
record Order(Guid Id, int ProductId, decimal Amount, DateTime CreatedAt);
record Product(int Id, string Name, decimal Price);
record OrderRequest(int ProductId);

Join the conversation! Your thoughts help the community grow.