Introduction
.NET Architecture Weekly is a journal about learning software architecture on .NET and not just limited* to .NET only.
PS: Why? Because software architecture designs normally can use in any languages or frameworks :).
Week #2
1) .NET Microservices Architecture
Today we will try to learn microservices on .NET via eShopOnContainers. eShopOnContainers is a cross-platform .NET sample microservices that runs on Linux and/or Windows containers. Below is the main overall architecture for the eShopOnContainers for docker or local development environment using mermaid.js.
---
title: eShopOnContainers Architecture
---
graph LR
subgraph CA[Client apps]
APP[Mobile apps]
SPA[Web SPA]
MVC[Web MVC]
end
subgraph DH[Docker Host]
MVC --> COREMVC[ASP.NET Core MVC]
subgraph GW[API Gateway]
GW1[Mobile-Shopping]
GW2[Web-Shopping]
end
APP --> GW
SPA --> GW
COREMVC --> GW
APP --> ID[Identity Service]
SPA --> ID
COREMVC --> ID
Admin --> GW
GW -->|REST call| A[Catalog Service]
GW -->|REST call| B[Ordering Service]
GW -->|REST call| C[Basket Service]
ID --> |DB call| D[SQL Server]
A -->|DB call| E[SQL Server]
B -->|DB call| F[SQL Server]
C -->|DB call| G[Redis]
D -->|Pub/Sub| EB
E -->|Pub/Sub| EB
F -->|Pub/Sub| EB
G -->|Pub/Sub| EB
subgraph EBGrp[Event Bus]
EB[RabbitMQ]
end
subgraph Admin[Admin Services]
A1[Web Status]
A2[Seq Logging]
A3[Webhooks API]
end
end
style CA fill:#f0f0f0,stroke:#333,stroke-width:2px
style DH fill:#e0e0e0,stroke:#333,stroke-width:2px
style GW fill:#d0d0d0,stroke:#333,stroke-width:2px
style EBGrp fill:#c0c0c0,stroke:#333,stroke-width:2px
style Admin fill:#b0b0b0,stroke:#333,stroke-width:2px
style APP fill:#ffcccc,stroke:#cc0000,stroke-width:4px
style SPA fill:#ccffcc,stroke:#00cc00,stroke-width:4px
style MVC fill:#ccccff,stroke:#0000cc,stroke-width:4px
style COREMVC fill:#ffffcc,stroke:#cccc00,stroke-width:4px
style ID fill:#ffccff,stroke:#cc00cc,stroke-width:4px
style A fill:#ccffff,stroke:#00cccc,stroke-width:4px
style B fill:#ff99cc,stroke:#cc3399,stroke-width:4px
style C fill:#99ffcc,stroke:#33cc99,stroke-width:4px
style D fill:#99ccff,stroke:#3399cc,stroke-width:4px
style E fill:#ffff99,stroke:#cccc33,stroke-width:4px
style F fill:#ff99ff,stroke:#cc33cc,stroke-width:4px
style G fill:#99ffff,stroke:#33cccc,stroke-width:4px
style EB fill:#9999ff,stroke:#3333cc,stroke-width:4px
style A1 fill:#ff9999,stroke:#cc3333,stroke-width:4px
style A2 fill:#99ff99,stroke:#33cc33,stroke-width:4px
style A3 fill:#9999ff,stroke:#3333cc,stroke-width:4px
As you might feel, the architecture is similar to the API Gateway pattern that we used for the Todo app.
---
title: API Gateway Pattern
---
graph LR
UI[Browser] -->|HTTP request| GW[API Gateway]
UI --> S3[SPA on Nginx]
subgraph Backend
GW -->|REST call| A[User Service]
GW -->|REST call| B[Task Service]
GW -->|REST call| C[Notification Service]
A -->|DB call| D[DB A]
B -->|DB call| E[DB B]
C -->|DB call| F[DB C]
end
style UI fill:#f9d0c4
style GW fill:#f0b37e
style A fill:#a9dc76
style B fill:#a9dc76
style C fill:#a9dc76
style D fill:#78dce8
style E fill:#78dce8
style F fill:#78dce8
One thing worth noting is for this .NET microservices, the Identity Service does not go through API Gateway but can be accessed directly from the browser.
Another pattern that can be found on the eShopOnContainer architecture is the Event-Driven pattern. It is an Event Bus that has Publishers/Producers and Subscribers/Consumers. The message broker for eShopOnContainers is RabbitMQ.
---
title: Event-Driven Pattern
---
graph LR
subgraph MS[Message Sender]
Origin[Microservice Origin]
end
subgraph Broker[Message Broker]
Origin -->|publish| A[Queue A]
Origin -->|publish| B[Queue B]
end
subgraph MR[Message Receivers]
A -->|subscribe| MA[Microservice A]
B -->|subscribe| MB[Microservice B]
end
style MS fill:#f0f0f0,stroke:#333,stroke-width:2px
style Broker fill:#e0e0e0,stroke:#333,stroke-width:2px
style MR fill:#d0d0d0,stroke:#333,stroke-width:2px
style Origin fill:#ffcccc,stroke:#cc0000,stroke-width:4px
style A fill:#ccffcc,stroke:#00cc00,stroke-width:4px
style B fill:#ccccff,stroke:#0000cc,stroke-width:4px
style MA fill:#ffffcc,stroke:#cccc00,stroke-width:4px
style MB fill:#ffccff,stroke:#cc00cc,stroke-width:4px
That all for today .NET Microservices Architecture with eShopOnContainers, hope in future will learn other things from the sample. If you wish to know more than, remember it has an ebook, you can download via the link below:
.NET Microservices: Architecture for Containerized .NET Applications
2) The Full-stack Software Design & Architecture map
This post is suitable for developers who want to transform to become a solution architect. It discussed from low-level to high-level of software design and architecture. The author has split it into nine stages that we can follow as below:
1. Learn how to write clean code
2. Understand the differences between each mainstream paradigm and who OOP is the most beneficial for architecture
3. Re-learn OOP programming but this time with model-driven design in mind
4. Learn the OOP design principles for keeping code flexible and testable
5. Learn the patterns that are solutions to commonly solved problems and how to apply them at the class-level
6. Learn how to manage relationships between components, express high-level policy, and identify architectural boundaries
7. Learn the different approaches to organizing our code into high-level modules and defining the relationships between them
8. Learn the architectural patterns that implement one or more architectural styles to solve a problem
9. Learn the enterprise patterns that be suit your choose architectural pattern.