Published on

Why Vertical Slice Architecture (VSA)?

Authors
  • avatar
    Name
    M. Seyda Armağan
    Twitter

Introduction

In the world of .NET development, Clean Architecture (or Onion Architecture) has been the de facto standard for building maintainable applications. It emphasizes separation of concerns by splitting the application into horizontal layers: Domain, Application, Infrastructure, and Presentation.

However, as applications grow, these horizontal layers can sometimes become barriers to feature development. Enter Vertical Slice Architecture (VSA).

What is Vertical Slice Architecture?

Instead of slicing the application horizontally (by technical concern), VSA suggests slicing it vertically (by business feature). Each "slice" contains everything needed to implement that feature: the API endpoint, the application logic, the data access code, and the domain model.

Key Benefits

  1. Cohesion: Code related to a specific feature is grouped together.
  2. Coupling: Changes to one feature are less likely to impact others.
  3. Simplicity: You don't need to implement layers that aren't necessary for a specific feature (e.g., a simple CRUD op doesn't need a complex domain service).

Comparison with Clean Architecture

FeatureClean ArchitectureVertical Slice Architecture
OrganizationBy Technical LayerBy Business Feature
CouplingHorizontal LayersVertical Slices
ComplexityUniform across featuresAdaptive to feature needs

Conclusion

VSA is not a silver bullet, but it offers a pragmatic approach to building systems that are easier to navigate and maintain, especially in complex domains. In the next posts, we'll dive deeper into implementing VSA with .NET 8 and MediatR.