Tutorials Microservices with .NET
User Microservice with ASP.NET Core Web API — Complete Guide
User Microservice with ASP.NET Core Web API — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of Microservices with .NET on Toolliyo Academy.
On this page
Microservices with .NET · Lesson 12 of 120
Product Microservice
Beginner → Intermediate → Advanced → Professional
Beginner · 1 — Foundations · ~6 min · Module 2: Building Microservices
What is this?
Product Microservice owns the catalog — product name, price, description, stock display fields. Shoppers browse products through this API.
Why should you care?
Catalog changes constantly (sales, new SKUs). Isolating Product lets merchandising deploy without regression-testing Payment.
See it live — copy this example
Create a Web API project (dotnet new webapi), paste the code, then run dotnet run.
app.MapGet("/products", async (ProductDbContext db) =>
Results.Ok(await db.Products.AsNoTracking().ToListAsync()));
app.MapGet("/products/{id:int}", async (int id, ProductDbContext db) =>
{
var p = await db.Products.FindAsync(id);
return p is null ? Results.NotFound() : Results.Ok(p);
});
Run Example »
Edit the code and click Run — like W3Schools Try it Yourself.
What happened?
- AsNoTracking on list queries is faster for read-heavy catalog.
- Order service will store productId and price snapshot when order is placed.
Try it yourself
- Create Product.Api with Product entity (Id, Name, Price, Description).
- Seed five products in migration or POST loop.
- Test list and get-by-id in Swagger.
- Change a string or number in the example and run again — predict the output first.
- Break the code on purpose (remove a semicolon), read the compiler error, then fix it.
Remember
Product service = catalog CRUD. Read-heavy — optimize reads later with Redis (lesson 68). Order stores snapshot of price at purchase time.
Real-world: Big Billion Day pricing
Prices flash every hour. Product service deploys price rules; CDN caches GET /products with short TTL.
Outcome: Checkout reads price from order line snapshot — not live catalog — so totals do not change after click.