Architecture explained through C4¶
Introduction¶
Microservices are the modern solution to problems from the past. Which problems? Well. Most applications made prior to 2010-2015 are Monolithic. Before being able to answer why my project needs to use Microservices, we first need to understand why microservices are a vital part of the modern software stack.
C4 model is a lean graphical notation technique for modelling the architecture of software systems. It is based on a structural decomposition of a system into containers and components and relies on existing modelling techniques such as the Unified Modelling Language (UML) or Entity Relation Diagrams (ERD) for the more detailed decomposition of the architectural building blocks.
Theory¶
What is a Monolith, and why is it bad?
Even though your application may use a variety of standard design patterns, such as MVC, SOLID, etc. it may still be a monolith; a monolith typically is a single application in which all of its components can be consumed. Why is this problematic? During the turn of the century, the internet has become a massive part of our society. We must make applications that can handle a lot of users; and a typical disadvantage for a monolithic application is its scalability. Lets say you have a banking application, and the most used function is when an user checks their balance. Scaling this application means that components that are used way less also scale up.
Cloud has become a bigger part of the internet; for simple reasons, you want high availability and connectivity throughout the world; as your application may be used in the Netherlands, or in Australia. The biggest disadvantage that the Cloud (AWS, Azure, Akamai, etc.) all face are the costs. Thus, cutting down your application into multiple services means that this cost will not grow exponentially despite only one component being used often.
Thus, most Enterprise applications use a variety of Microservices, which still accomplishes the same thing as before–but with a focus towards the resources used in order to host the application.
What is stateful and why is it a problem?
Another problem that this microservice setup introduces is that applications can be stateful or stateless. Before I can explain why this is a problem, you first need to understand what these terms mean. A stateful application contains static information in order to make the application run. E.g. having login=true in your code. This is a problem in the Microservice scaleability; since a microservice might scale-up, but the second instance of the application may not recognize the login=true and this will throw problems in production.
The solution to this is making the Microservices stateless.
Execution¶
I used draw.io to create the diagrams, before being able to do so I did event-storming to get more clarity on complex issues.
C1 System context¶
A system context diagram is a good starting point to set up the technical architecture of the software system. The context displays the entire system on a high level.
C2 Containers en technological choices¶
The deployment diagram displays the entire system on high level. In it the responsibilities are displayed between various components.