GitHub - mauroservienti/all-our-aggregates-are-wrong-demos: A microservices powered e-commerce shopping cart sample - based on SOA principles. Demos and sample for my "All our Aggregates are Wrong" talk (original) (raw)

A microservices-powered e-commerce shopping cart sample based on SOA principles. These are the demos for my All our Aggregates are Wrong talk.

The demo showcases a shopping cart and its associated behaviors. Add items to the cart and observe the log messages printed in the various service terminal windows as events are processed. Leave the cart inactive for a few seconds and observe the stale cart policy kick in: after 30 seconds of inactivity a ShoppingCartGotStale event is published, and after 60 seconds the cart is deleted and a ShoppingCartGotInactive event is published.

Solution overview

The solution is organized into four business domains, each owning its own data and communicating asynchronously via NServiceBus over RabbitMQ.

Marketing

Manages the product catalog. The Marketing.Api exposes product data (names, descriptions) used to compose product listing and shopping cart views. Marketing.Data provides the EF Core data access layer backed by a dedicated PostgreSQL database.

Sales

Manages the shopping cart lifecycle. Sales.Api exposes endpoints to retrieve cart contents. Sales.Service is a background NServiceBus endpoint that handles ProductAddedToCart commands and runs the ShoppingCartLifecyclePolicy saga, which publishes ShoppingCartGotStale (after 30 seconds of inactivity) and ShoppingCartGotInactive (after 60 seconds of inactivity, also deleting the cart). Sales.Data provides the EF Core data access layer backed by a dedicated PostgreSQL database.

Shipping

Handles shipping concerns when items are added to a cart. Shipping.Api exposes shipping-related cart data. Shipping.Service is a background NServiceBus endpoint that reacts to cart events. Shipping.Data provides the EF Core data access layer backed by a dedicated PostgreSQL database.

Warehouse

Manages inventory. Warehouse.Api exposes stock availability data. Warehouse.Service is a background NServiceBus endpoint that reacts to cart events to track product reservations. Warehouse.Data provides the EF Core data access layer backed by a dedicated PostgreSQL database.

WebApp

An ASP.NET Core web application that serves as the user interface. It composes views by coordinating responses from all service APIs using the ServiceComposer pattern (via ITOps.ViewModelComposition). It hosts a product catalog page and a shopping cart page.

Shared and infrastructure projects

Requirements

The following requirements must be met to run the demos successfully:

How to configure Visual Studio Code to run the demos

Wait for Visual Studio Code Dev containers extension to:

Note: no changes will be made to your Visual Studio Code installation; all changes will be applied to the VS Code instance running in the remote container

The repository devcontainer configuration will create:

Once the configuration is completed, VS Code will show a new Ports tab in the bottom-docked terminal area. The Ports tab will list all the ports the remote containers expose.

Containers connection information

The default RabbitMQ credentials are:

The default PostgreSQL credentials are:

How to run the demos

To execute the demo, open the repository root folder in VS Code, press F1, and search for Reopen in container. Wait for the Dev Container to complete the setup process.

Once the demo content has been reopened in the dev container, go to the Run and Debug VS Code section and select one of the available launch configurations:

Each configuration launches all services simultaneously in integrated terminal windows:

Disclaimer

This demo is built using NServiceBus Sagas; I work for Particular Software, the makers of NServiceBus.