Instead of separating an application horizontally (layers), a vertical slice groups all horizontal concerns together to encapsulate a feature. Here is a diagram that illustrates that:

Figure 17.1: Diagram representing a vertical slice crossing all layers
Jimmy Bogard, who is a pioneer of this type of architecture, wrote the following:
[The goal is to] minimize coupling between slices and maximize coupling within a slice.
What does that mean? Let’s split that sentence into two distinct points:
- “minimize coupling between slices” (improved maintainability, loose coupling)
- “maximize coupling within a slice” (cohesion)
We could see the former as one vertical slice should not depend on another, so when you modify a vertical slice, you don’t have to worry about the impact on the other slices because the coupling is minimal.We could see the latter as: instead of spreading code around multiple layers, with potentially superfluous abstractions along the way, let’s regroup and simplify that code. That helps keep the tight coupling inside a vertical slice to create a cohesive unit of code that serves a single purpose: handling the feature end to end.Then we could wrap that to create software around the business problem we are trying to solve instead of the developer’s concerns, which your customers have no interest in (such as data access).Now, what is a slice in more generic terms? I see slices as composite hierarchies. For example, a shipping manager program has a multistep creation workflow, a list, and a details page. Each step of the creation flow would be a slice responsible for handling its respective logic. When put together, they compose the “create slice”, which is responsible for creating a shipment (a bigger slice). The list and details pages are two other slices. Then, all of those slices become another bigger slice, leading to something like this:

Figure 17.2: A diagram displaying a top-down coupling structure where smaller parts (top) depend on bigger parts (middle) of complex features (bottom) based on their cohesion with one another (vertically)
There is strong coupling inside Step 1, with limited coupling between the other steps; they share some creation code as part of the Create slice. Create, List, and Details also share some code, but in a limited way; they are all part of the Shipments slice and access or manipulate the same entity: one or more shipments. Finally, the Shipments slice shares no code (or very little) with Other features.
Following the pattern I just described, we have limited coupling and maximum cohesion. The downside is that you must continuously design and refactor the application, which requires stronger design skills than a layered approach. Moreover, you must know how to build the feature end to end, limiting the division of tasks between people and centralizing them on each team member instead; each member becomes a full-stack developer. We revisit this example in the Continuing your journey section near the end of the chapter.
We explore the advantages and disadvantages next.
What are the advantages and disadvantages?
Let’s explore some advantages and disadvantages of Vertical Slice Architecture.
Leave a Reply