Within software development, we have many ways to structure an application. One of these is to organize our application by features, which is where Vertical Slice Architecture comes in.
Index
1 - What is vertical architecture?
Using vertical architecture means you define the structure of your project in vertical layers, or as they are called in English, slices.
Don't confuse this with other architectures that are based on layers (in English, layers), which typically refer to horizontal layers.
These vertical layers contain all the logic of a feature, from the interface layer to the domain or data access layers. The most common representation is a cake, because when you cut a cake, you have a slice that contains all the layers.
It is very common to see a representation like this:
Which in my opinion is a poor representation, because the first thing I see is three layers, and each feature has a part in a layer…
But that's not vertical slice architecture, that's layered architecture.
The main idea of this architecture is to group all the logic of each feature together, making it very easy to identify where you are working or what you need to modify.
Personally, I think that this image actually represents the opposite. In theory, you are not supposed to share different layers like presentation, data, infra, etc., but when I look at the image, that's all I see.
For me, a true representation of Vertical Slice Architecture is this one:
Here, you can clearly see the separation of layers by features, and each feature repeats the necessary layers if needed.
The big problem I see when explaining the concept of Vertical Slice Architecture is that it is explained alongside clean/onion architecture. Adding an infrastructure layer and having the project that calls that layer not know the implementation is Clean Architecture. Since half of the blog posts out there are copies of others, everyone falls into the same problem: they don't know how to separate one from the other. But that's a topic for a whole book, because the same thing happens with CQRS and event sourcing or CQRS and mediatr, as if one couldn't be done without the other.
It is not wrong to mix both architectures, but when explaining them, they should be well differentiated.
For me, if you are doing vertical slice architecture and your elements are simple , for example, a DTO of one line, a mapper of one line, data access of one line, and a logic line , you can put everything in the same file.
2 - Advantages of vertical architecture
In the case of the previously shown image, if we understand each feature as a project (even if they are in the same csproj), we can define how best to access data or use request-response, according to what suits us. Many people (including Jimmy Bogard, creator of VSA) specify that this architecture naturally and automatically leads you to implement CQRS. I'll let you in on a secret: I don't know how software was built over 15 years ago, but since I started professionally, I've always separated reads from writes 🤷, mainly out of common sense.
Having this separation by features also allows changes you make not to affect other features, making iteration easier, especially if you are working on a monolith or a microlith,
With this separation, when the time comes, you can split the feature into an individual project quite easily.
Therefore, it facilitates migration to modular monoliths or even splitting off services themselves, if necessary, enabling continuous development and integration of the feature itself.
3 - My opinion of Vertical Slice Architecture
This time it's going to be simple. My only criticism is that such a radical separation doesn't always work well, and sometimes certain parts of the domain should be shared so you don't end up duplicating information many times over.
Other than that, I'm fine with it, as each feature owns its code, which, translated to the real world, means each team owns its code and is not forced to implement completely unnecessary patterns just because another part of the system uses them.
If there is any problem you can add a comment bellow or contact me in the website's contact form