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

BeginnerIntermediateAdvancedProfessional

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.

Code
Result

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

  1. Create Product.Api with Product entity (Id, Name, Price, Description).
  2. Seed five products in migration or POST loop.
  3. Test list and get-by-id in Swagger.
  4. Change a string or number in the example and run again — predict the output first.
  5. 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.

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Mid PDF Detailed
Isolate Business Logic: Test only the core business logic, ensuring no external?
Short answer: dependencies like databases, APIs, or other services are involved. Real-world example (ShopNest) After payment succeeds, ShopNest publishes OrderPaid . Inventory and Notification services react independentl…
Mid PDF Detailed
URI Versioning: Include the version in the URL, such as /api/v1/users.?
Short answer: Example: GET /api/v1/orders/{id} vs. GET /api/v2/orders/{id} GET /api/v1/orders/{id} vs. GET /api/v2/orders/{id} Example code GET /api/v1/orders/{id} vs. GET /api/v2/orders/{id} GET /api/v1/orders/{id} vs.…
Mid PDF Detailed
Tight Coupling: Services become tightly coupled, violating the core microservice?
Short answer: principle of independence. Real-world example (ShopNest) ShopNest splits Catalog, Cart, Order, and Payment into services so teams can deploy catalog changes without redeploying payments. Say this in the int…
Mid PDF Detailed
Test Full User Journeys: Simulate real user workflows that span multiple?
Short answer: Test Full User Journeys: Simulate real user workflows that span multiple? is a common interview topic in Microservices. Give a clear definition, then one concrete example. Real-world example (ShopNest) Shop…
Senior PDF Detailed
Distributed Transactions: Using Two-Phase Commit (2PC) or Sagas to ensure?
Short answer: that a transaction either commits or rolls back across multiple services. Real-world example (ShopNest) After payment succeeds, ShopNest publishes OrderPaid . Inventory and Notification services react indep…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

Microservices with .NET
Course syllabus

Microservices with .NET Tutorial

Module 1: Foundations and Fundamentals
Module 2: Building User Microservice
Module 3: ShopNest Services and Integration
Module 4: RabbitMQ and Messaging
Module 5: Saga and Distributed Transactions
Module 6: API Gateway
Module 7: gRPC, CQRS, and GraphQL
Module 8: Resiliency and Fault Tolerance
Module 9: DevOps and Cloud-Native
Module 10: Git and GitHub
Module 11: CI/CD Pipelines
Module 12: Observability and Testing
Module 13: Advanced Topics
Module 14: Real-World Enterprise Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details