Skip to content

Commit e2302b2

Browse files
author
Simon Brown
committed
Adds a page that talks about how to model microservices.
1 parent f6a33bc commit e2302b2

File tree

14 files changed

+109
-21
lines changed

14 files changed

+109
-21
lines changed

abstractions/06-components-vs-code.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: default
33
title: Components vs code?
44
parent: Abstractions
5-
nav_order: 5
5+
nav_order: 6
66
permalink: /abstractions/components-vs-code
77
---
88

abstractions/07-microservices.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
layout: default
3+
title: Microservices
4+
parent: Abstractions
5+
nav_order: 7
6+
permalink: /abstractions/microservices
7+
---
8+
9+
# Microservices
10+
11+
Broadly speaking, there are two options for diagramming microservices when using the C4 model, although it depends
12+
what you mean by "microservice". With that in mind, let's start from the beginning.
13+
14+
## Stage 1 - monolithic architectural style
15+
16+
Imagine that we work for a small cash-strapped startup company and our task is to build a software system (named "X")
17+
that offers business capabilities A, B, and C to our customers. Our system context diagram might look like this:
18+
19+
![](/images/microservices/1.png)
20+
21+
Arguably the quickest and cheapest way to get something delivered, especially as a cash-strapped startup with a
22+
small engineering team, is to use a monolithic architecture, consisting of a single monolithic web application
23+
reading from and writing to a single monolithic database schema. The resulting container diagram looks like this:
24+
25+
![](/images/microservices/2.png)
26+
27+
## Stage 2 - microservices architectural style
28+
29+
A couple of years have gone by - we have some paying customers, traffic is starting to scale, we've hired a few
30+
more engineers, and the codebase is growing. Our monolithic architecture is starting to slow us down, so we
31+
make the decision to transition to a microservices architecture. That raises the question - what is a microservice?
32+
33+
To answer this question, we'll refer to [Microservices](https://martinfowler.com/articles/microservices.html) written
34+
by James Lewis and Martin Fowler:
35+
36+
> In short, the microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery.
37+
38+
To help us align this with the C4 model, let's substitute "application" for "software system":
39+
40+
> In short, the microservice architectural style is an approach to developing a single __software system__ as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery.
41+
42+
In this stage of our startup's journey, although we've hired a few more engineers, we've decided to stay
43+
as a single team. Our system context diagram remains the same:
44+
45+
![](/images/microservices/3.png)
46+
47+
But our container diagram has changed. We've decided to retain the single monolithic UI of the existing
48+
web application, but move the business logic and data into individual microservices. The resulting container diagram
49+
now looks like this:
50+
51+
![](/images/microservices/4.png)
52+
53+
As we're still a single engineering team, transitioning to a microservices architecture is an implementation detail
54+
that is only apparent inside the team boundary. This is why all seven containers are shown inside the software system
55+
boundary, with each "microservice" being a combination of an API container and a database schema container.
56+
As a result, you will notice that this container diagram doesn't show microservices as explicit boxes.
57+
Instead, this version of the diagram uses colour coding the show the relationship between pairs of API and database
58+
schema containers. If you wanted to be more explicit about this pairing, you could draw a box around each pair to
59+
show they are grouped together.
60+
61+
![](/images/microservices/5.png)
62+
63+
Imagine now that we are going to expand the scope of our software system to also include business capability D.
64+
The revised system context diagram would look like this:
65+
66+
![](/images/microservices/6.png)
67+
68+
And if that new business capability was implemented by a new microservice, which is just a single stateless AWS lambda,
69+
the revised container diagram would look like this:
70+
71+
![](/images/microservices/7.png)
72+
73+
## Stage 3 - Conway's Law
74+
75+
As our company grows, and moves from startup to scaleup, we start looking at ways to optimise
76+
delivery, and decide to look at [Conway's Law](https://en.wikipedia.org/wiki/Conway%27s_law) as a way to do this.
77+
In summary, we decide to split our single engineering team into a number of teams, the result of which is that each
78+
microservice will be owned by a separate team:
79+
80+
- Team X: owns software system X providing the UI related to business capabilities A, B, C, and D.
81+
- Team A: owns service A.
82+
- Team B: owns service B.
83+
- Team C: owns service C.
84+
- Team D: owns service D.
85+
86+
We can now use the C4 model to look at each software system from the perspective of the team that owns it,
87+
with each service being "promoted" from a pairing of containers into a software system. The system
88+
context diagram for team X now looks like this:
89+
90+
![](/images/microservices/8.png)
91+
92+
Team X has only retained the monolithic UI, so the revised container diagram for software system X looks like this:
93+
94+
![](/images/microservices/9.png)
95+
96+
And from the perspective of team A, the system context diagram for service A looks like this:
97+
98+
![](/images/microservices/10.png)
99+
100+
And the container diagram for service A looks like this:
101+
102+
![](/images/microservices/11.png)
103+
104+
## Summary
105+
106+
The approach to take for diagramming a microservices architectural style depends upon the ownership of
107+
the individual services, and whether you see them as an implementation detail inside a single software system or
108+
as separate software systems that are (or could be) owned by separate teams.

faq.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,6 @@ terms "module" and "function").
6868
Feel free to modify the terminology that you use to describe software architecture at different levels of abstraction.
6969
Just make sure that everybody explicitly understands it.
7070

71-
## How do you model microservices and serverless?
72-
73-
Broadly speaking, there are two options for diagramming microservices when using the C4 model, although it depends
74-
what you mean by "microservice".
75-
76-
### Approach 1: Each "microservice" is owned by a separate team
77-
78-
If your software system has a dependency upon a number of microservices that are outside your control (e.g.
79-
they are owned and/or operated by a separate team), model these microservices as external software systems, that
80-
you can't see inside.
81-
82-
### Approach 2: A single team owns multiple "microservices"
83-
84-
Imagine that you have an API app (e.g. Spring Boot, ASP.NET MVC, etc) that reads/writes to a relational database schema.
85-
Regardless of whether you consider the term "microservice" to refer to just the API app, or the combination of the API
86-
app and database schema ... if the microservices are a part of a software system that you are building
87-
(i.e. you own them), model every deployable thing as a container. In other words, you'd show two containers: the API
88-
app, and the database schema. Feel free to draw a box around these two containers to indicate they are related/grouped.
89-
The same is true for serverless functions/lambdas/etc; treat them as software systems or containers based upon ownership.
90-
9171
## How do you diagram large and complex software systems?
9272

9373
Even with a relatively small software system, it's tempting to try and include the entire story on a single diagram.

images/microservices/1.png

69.4 KB
Loading

images/microservices/10.png

70.9 KB
Loading

images/microservices/11.png

132 KB
Loading

images/microservices/2.png

115 KB
Loading

images/microservices/3.png

69.4 KB
Loading

images/microservices/4.png

394 KB
Loading

images/microservices/5.png

412 KB
Loading

0 commit comments

Comments
 (0)