
Architectures in Comparison: Onion or Vertical Slice?
For many years, we have successfully relied on the Onion Architecture in our applications. In recent projects, however, we have also used the Vertical Slice Architecture. In this blog post, we present both approaches, share our experiences, and explain in which situations each architecture is the better choice.
Onion Architecture
The Onion Architecture was introduced by Jeffrey Palermo in 2008 and is based on Dependency Inversion (one of the SOLID principles). The dependencies always point inward, never outward.
In the core, the business logic and interfaces are defined, which are independent of the technology implementation in the infrastructure layer. At runtime, the implementation is loaded via dependency injection, allowing individual components such as the database to be exchanged without changing the business logic. This concept also allows the business logic to be tested independently of the outer layers.
The layers are represented by concentric circles that resemble an onion – hence the name.

Core Layer
The Core Layer contains the business logic, domain models, entities, interfaces, and services.
- The goal is independence from frameworks, databases, or the UI. This layer only knows the logic, not specific technologies.
- The logic can be tested in isolation and remains stable even if the outer technology changes.
Infrastructure Layer
The Infrastructure Layer implements database access, logging, access to external APIs, and file operations.
- Implements the technical interfaces from the Core Layer and thus provides the required technical functionality.
- The technology can be replaced without changing the business logic in the Core Layer.
Presentation Layer
The Presentation Layer implements the UI, web frontend, REST controllers, etc.
- Presents data, accepts input, and communicates with the Core Layer through services.
- The UI can be developed and changed independently of the logic.
In addition to the Onion Architecture, there are also the Hexagonal Architecture by Alistair Cockburn (2005) and the Clean Architecture by Robert C. Martin (2012). These three architectures are quite similar.
Vertical Slice Architecture
The Vertical Slice Architecture was designed by Jimmy Bogard. The main characteristic of this architecture is its use case or feature-oriented structure. The goal is to achieve low coupling between slices and high cohesion within each slice. This makes it possible to add or modify features easily. In both cases, existing code is not modified, and adjustments are usually localized (per slice). This corresponds to the Open/Closed Principle of SOLID.
Due to the separated slices, there is a risk of code duplication. To prevent this, shared methods and data access can be extracted into common services or abstracted using the Repository Design Pattern.

The following example visualizes how the Vertical Slice Architecture works: the REST controller receives a POST request and sends a message to the mediator. The mediator forwards the message to the corresponding handler, which executes the business logic. Finally, the result is written to the database via the repository.
The mediator is not strictly required but provides additional decoupling and integrates well via dependency injection. In our recent projects, we used MediatR together with FluentValidation and Automapper.

The approach offers the following advantages:
- Provides built-in methods for Request/Response (Command or Query to a handler) as well as notifications (to multiple handlers).
- Pipeline Behaviors make it easier to implement logging, validation (FluentValidation), and error handling centrally with less code.
- Enables better decoupling and testability, since communication happens through MediatR, which also reduces the number of mocks needed in unit tests.
- Open/Closed Principle: new functionality is added through new handlers or behaviors.
- Automapper maps objects based on rules.
Comparison
| Criterion | Onion Architecture | Vertical Slice Architecture |
|---|---|---|
| Low application complexity e.g. Address management (CRUD) |
Less suitable due to higher overhead. | Very suitable due to easy maintenance, clear feature structure, and low overhead. |
| Medium application complexity e.g. Meeting room booking system (multiple use cases with simple, isolated business logic) |
Well suited, especially for long-term applications. | Very well suited for fast development and clear feature organization. |
| High application complexity e.g. Fleet management system with scheduling, maintenance management, and cost control |
Very suitable for complex or shared domain logic and when using DDD (Domain-Driven Design). | Possible, but better suited for clearly separated use cases with minimal shared logic. |
| Modularity / Isolation | Separation by layer. The goal is to separate business logic from technical implementation. | Separation by feature or use case. The goal is to make features independent for implementation or modification. |
| Testability | Very good. Focus on business logic testing, strong regression testability, also in combination with E2E tests. | Very good. Focus on E2E tests to verify feature behavior. Debugging with MediatR is more complex, requiring a good structure. |
| Decoupling from Infrastructure | Very high – infrastructure is isolated from business logic and easily exchangeable. | Possible but often implemented less strictly. |
| Maintainability | Good if layers are kept clean. | Very good, as changes often affect only one slice. |
| Cross-cutting concerns (logging, error handling, etc.) | Centralized and well controlled. | Must be handled or abstracted per slice. MediatR Behaviors help here. |
| Learning curve / Onboarding and development speed | Requires understanding of layering, dependency inversion, and possibly DDD. Less boilerplate but more layer traversal and higher initial effort. | Developers can focus on individual features but may need to get familiar with MediatR. Fast for parallel development but more boilerplate per feature, offering high autonomy for teams. |
Conclusion
The Onion Architecture is ideal for long-term applications where testability, infrastructure decoupling, and maintainability are priorities. The slightly higher initial effort pays off, especially for complex systems or when many features are based on shared logic.
The Vertical Slice Architecture is particularly well suited for microservices or agile projects with clearly defined use cases and less shared complex domain logic. It excels when features need to be delivered or adapted quickly, or when multiple developers are working independently on the project.
In our projects, we also use a combination of both architectures:
The Onion Architecture forms the structural foundation with a clear separation of Domain, Application, Infrastructure, and Presentation Layers.
Within the application layer, use cases are implemented as Vertical Slices with MediatR, Commands, Queries, and Handlers.
This combination enables high maintainability both at the feature level and when technological changes occur in the infrastructure. The trade-off is some additional boilerplate code, which is justified by the resulting improvements in structure, testability, and maintainability.
CSA Engineering AG has the know-how and experience to implement these architectures efficiently. We are happy to support you in the conception and development of your software solutions.
Patrick Heiniger
Dipl. Technician HF in Computer Science / NDS Software Engineering SWS
Software Engineer
About the author
Patrick Heiniger has been working as a software engineer at CSA for over 19 years.
He supports customers in the .NET environment with the architecture and development of web and cloud projects. Thanks to his interest in new technologies and his motivation to continuously expand his knowledge, he always stays at the cutting edge of technology.