LESSON 1 OF 20

1. Project Vision and Microservice Architecture Fundamentals

Define the sample project’s business domains and candidate services, compare monolithic and microservice approaches, and create the initial .NET 10 and Aspire solution structure.

50 dk 30

Introduction

Before building a distributed application, the most important decision is not how many APIs to create. It is deciding which business responsibilities the system should contain and where their boundaries should be. Microservice architecture does not simply mean splitting one application into many small projects. Each service should own a meaningful business capability, perform its responsibilities independently, and communicate through explicit contracts.

Throughout this course, we will build a sample online ordering platform called ShopFlow. Customers will browse products, add items to a basket, create orders, and track order status. In this first lesson, we will not yet implement databases, queues, or caching in detail. Instead, we will establish the project vision, identify business domains, and create an initial solution structure using .NET 10 and Aspire.

Aspire provides an application model in which distributed application resources and their relationships are declared in code. The AppHost describes projects, containers, and dependencies. During local development, this allows us to run and observe the application topology from one place instead of starting and configuring every service independently.

1. The sample project scenario

The business problem

Assume that ShopFlow must support the following core flows:

  • A customer views the product catalog.
  • A customer adds products to or removes products from a basket.
  • A customer creates an order with delivery information.
  • The system checks product availability.
  • Payment and notification processes begin when an order is created.
  • The customer tracks the order status.

These flows should not immediately be translated into technical layers. First, identify the business capabilities. “Controllers,” “repositories,” and “database” are not business domains. They are implementation details. A business domain is a responsibility that has meaning for users and the organization, such as catalog, basket, ordering, or payment.

Discovering business domains

Our first draft may contain the following areas:

Business areaPrimary responsibilityInitial service candidate
CatalogProvide products, categories, and pricesCatalog API
BasketManage a customer’s temporary shopping basketBasket API
OrderingCreate orders and manage their lifecycleOrdering API
InventoryManage quantities and reservationsInventory API
NotificationsSend email or other notificationsNotification Worker

This list is not yet a final architecture. Service boundaries may change as we examine workflows, ownership, and data dependencies. In microservice design, being able to explain why a service exists is more important than choosing names early.

2. Comparing monoliths and microservices

The monolithic approach

In a monolithic application, the user interface, API endpoints, business rules, and data access commonly exist within one deployable unit. This approach is often highly productive at the beginning. Creating one project, running one process, and using one database are straightforward. For small teams and early-stage products, a monolith can prevent unnecessary operational complexity.

Over time, however, modules may begin reading each other’s tables directly, depending on shared classes, and following the same release cycle. A change in one area can then require redeploying the entire application. The codebase may become a tightly connected dependency network even if the original structure looked modular.

The microservice approach

In a microservice architecture, the application is composed of independently executable services organized around business capabilities. Each service owns its code, API contract, and preferably its own data. Services communicate through explicit protocols such as HTTP or messaging.

This approach can provide independent deployment, team autonomy, and service-specific scaling. It also introduces network latency, transient failures, consistency concerns, observability requirements, security considerations, and more complicated local development. Therefore, “more services” does not automatically mean “better architecture.”

ConcernMonolithMicroservices
DeploymentOne unitMultiple independent units
CommunicationUsually in-process callsNetwork APIs or messages
DataA shared database is commonData ownership per service is preferred
OperationsSimpler initiallyMonitoring and failure handling are more important
ScalingThe whole application is scaledServices can be scaled independently

3. Defining service boundaries

When defining a service boundary, examine business responsibility and reasons for change rather than the number of technical classes. Data that changes because of the same business rule is more likely to belong within the same boundary. For example, changing a product description in the catalog should not directly change how the basket service operates.

Ask the following questions for every candidate service:

  1. Which business decisions does this service own?
  2. Which data does it own?
  3. Which API or message contract does it expose?
  4. Why do other services need to interact with it?
  5. Can it be tested and deployed independently?

For example, Catalog API may own product browsing. If Ordering needs the product name or price, it should not connect directly to the catalog database. It should call the catalog API or use an event published by Catalog. This preserves data ownership and avoids coupling two services to the same storage schema.

A good service boundary does not only split code; it limits the impact of change.

4. The initial solution structure

We will not implement every service in detail during this lesson. We will create a structure that can grow throughout the course:

ShopFlow.sln
src/
  ShopFlow.AppHost/
  ShopFlow.ServiceDefaults/
  Catalog/Catalog.Api/
  Basket/Basket.Api/
  Ordering/Ordering.Api/
  Inventory/Inventory.Api/
  Notification/Notification.Worker/
tests/
  Catalog.Tests/
  Ordering.Tests/

AppHost declares application resources and dependencies. ServiceDefaults can centralize shared telemetry, health check, and service discovery configuration for the services. Each API project will own a business responsibility and, later, its own data access concerns.

Creating projects

After installing the .NET 10 SDK and the appropriate Aspire tooling, inspect the installed templates first because template names can vary by version:

dotnet --info
dotnet new list aspire

You can then create an Aspire starter application or add an AppHost to an existing solution. For example, the following commands illustrate the initial project layout:

dotnet new sln -n ShopFlow
dotnet new webapi -n Catalog.Api -o src/Catalog/Catalog.Api
dotnet new webapi -n Basket.Api -o src/Basket/Basket.Api
dotnet sln ShopFlow.sln add src/Catalog/Catalog.Api/Catalog.Api.csproj
dotnet sln ShopFlow.sln add src/Basket/Basket.Api/Basket.Api.csproj

These commands are only a starting example. For the most reliable AppHost creation experience, use the official Aspire template installed for your environment. If you encounter version conflicts, check the target framework values of both the AppHost and the service projects.

Declaring resources in the AppHost

The core idea of a C# AppHost is to add projects to the application model and declare their relationships explicitly:

var builder = DistributedApplication.CreateBuilder(args);

var catalog = builder.AddProject<Projects.Catalog_Api>("catalog");
var basket = builder.AddProject<Projects.Basket_Api>("basket")
    .WithReference(catalog);

builder.AddProject<Projects.ShopFlow_Web>("web")
    .WithReference(catalog)
    .WithReference(basket);

builder.Build().Run();

Service names are not meaningless labels. Logical names such as catalog and basket become the basis for service discovery addresses used later. The WithReference call declares that one project depends on another resource and enables the related connection configuration to be provided.

We do not need to add a database in this lesson. In later lessons, SQL Server, Redis, and RabbitMQ resources will be added to the same application model. The goal is to create a visible dependency graph in the AppHost instead of managing every resource through unrelated terminal commands.

5. Running and inspecting the application

When the AppHost runs, Aspire starts the application resources and provides a dashboard. The dashboard can show resource status, endpoint information, log streams, and, in later lessons, tracing data.

  1. Confirm that Docker or another supported container runtime is running.
  2. Open the solution and select the AppHost project.
  3. Run the AppHost from the IDE or with the appropriate Aspire command.
  4. Check the status of resources in the dashboard.
  5. Inspect Catalog and Basket logs separately.

If a service does not appear, check project references, target framework versions, and the resource name in the AppHost. If one service cannot discover another, common causes include a missing reference, an incorrect logical name, or a target service that failed to start.

Common mistakes

  • Creating a service for every table: Database tables are not automatically service boundaries.
  • Exposing one shared database to every service: This weakens data ownership and independence.
  • Splitting too early: Decomposition before understanding workflows can create a distributed monolith.
  • Hard-coding URLs: Prefer AppHost references and service discovery over addresses such as localhost:5001.
  • Underestimating operations: Multiple services require coordinated logging, metrics, tracing, deployment, and failure handling.
  • Treating the AppHost as only a startup script: The AppHost is the application model describing resources and relationships.

Short practice exercise

Complete the following exercise for ShopFlow:

  1. Write one responsibility statement for Catalog, Basket, Ordering, and Inventory.
  2. List at least three data items owned by each area.
  3. Identify which information Ordering needs from Catalog.
  4. Describe the difference between a direct method call in a monolith and an HTTP call in a microservice system.
  5. Add Catalog and Basket projects to the AppHost and make Basket reference Catalog.
  6. Run the application and verify that the resources appear in the dashboard.

At the end, you should be able to answer the question “Why does each service exist?” in two or three sentences. You do not need to implement every endpoint yet.

Conclusion

In this lesson, we established the ShopFlow business scenario, identified candidate business domains, compared monolithic and microservice approaches, and saw that service boundaries should be derived from business responsibilities rather than technical layers. We also introduced the .NET 10 solution structure and the role of the Aspire AppHost.

In upcoming lessons, we will turn this initial model into working Catalog and Basket APIs. We will then combine data ownership, HTTP communication, service discovery, SQL Server, Redis, RabbitMQ, resilience, and OpenTelemetry within the same application model. The decisions made here provide the foundation for those technical implementations.

Sources