Vertical Slice Architecture
Vertical Slice Architecture
Layered architectures are the base of many software systems, but they group the system by technical layers, which don’t always work closely together. What if you wanted to organize the system around features and ensure all parts of a single feature are closely linked? In this article, we will discuss Vertical Slice Architecture, which does exactly that organizing the system around features.
Drawback of Layered Architecture
Layered architectures split the software into different layers or tiers, with each layer often being its own project for example N-tier and Clean architecture. This approach makes the system easier to understand and maintain, offering benefits like maintainability, flexibility, and loose coupling.
However, layered architectures can be restrictive because the dependencies between layers are fixed. For example, in Clean Architecture:
- The domain has no dependencies
- The application layer can reference the Domain
- Infrastructure can reference both Applications
- Domain and Presentation can reference both Application and Domain
This setup leads to high coupling within layers and low coupling between them, which increases complexity due to many abstractions that need to be maintained.
What is Vertical Slice Architecture
Vertical Slice Architecture is a design approach where a system is divided into vertical slices, each representing a feature or a specific functionality of the application. Unlike traditional layered architecture, where the system is split into horizontal layers (e.g., presentation, business logic, data access), vertical slices focus on delivering complete features from the UI down to the database.
Each slice in this architecture contains everything needed to implement a specific feature, including:
- Controllers (or API endpoints)
- Application logic
- Domain logic (business rules)
- Data access logic
This approach promotes separation of concerns and allows for better scalability and maintainability. It also aligns with Domain-Driven Design (DDD) by focusing on the business domain.
Here’s an example of a folder structure in a .NET Core Web API project following the Vertical Slice Architecture.
📁-- Features/
📁 -- CreateOrder/
📁-- CreateOrderRequest.cs
📁 -- CreateOrderHandler.cs
📁 -- CreateOrderResponse.cs
📁 -- CreateOrderController.cs
📁-- GetOrder/
📁 -- GetOrderRequest.cs
📁 -- GetOrderHandler.cs
📁 -- GetOrderResponse.cs
📁 -- GetOrderController.cs
Each vertical slice typically includes:
- Request: A class representing the input data for the slice (e.g., a DTO).
- Handler: A class responsible for handling the request, containing the business logic.
- Response: A class representing the output data (e.g., a DTO or ViewModel).
- Controller: The API endpoint that interacts with the request and response classes.
Here’s how you can visualize vertical slices:

Benefits of Vertical Slice Architecture
- Feature Isolation: Each slice is self-contained, making it easier to understand and modify specific features without impacting the entire system.
- Scalability: As features are isolated, teams can work on different slices independently, enabling parallel development and deployment.
- Testability: Since each slice is independent, it’s easier to write and maintain unit and integration tests.
- Flexibility: You can use different technologies or patterns for different slices if needed, adapting to the specific needs of each feature.
The best part is you can remove or disable any feature at any time if it’s not needed. Simply exclude it from the project, build the application, and run it. This won’t cause any problems because the removed feature is not linked to any other feature, as all features are independent.
Read – CQRS implementation with Vertical Slice Architecture using Mediator. This article explains how to implement Vertical Slice Architecture in CQRS design pattern with Mediator using Mediatr library, in asp.net core Web API application.