Stackbook Logo
architecture-descriptionestablished · low operational burden

Vertical Slice Architecture

Also known as: feature-slices, slice-based-architecture

Intent

Organize code by feature or request so each slice contains everything from interface to data access.

Problem

Horizontal layering spreads one feature across many folders, so every change touches presentation, service, and data layers and merge conflicts abound. Shared abstractions fit some features badly.

Forces

  • •Changes arrive per feature, not per layer
  • •Features differ in complexity and need different designs
  • •Shared code risks coupling unrelated features
  • •Some duplication is the price of independence

Solution

Overview

Vertical slice architecture, popularized by Jimmy Bogard, flips the usual layout. Instead of grouping by technical role, it groups by feature. To change how an order is placed, you open one folder.

How it works

Each request is handled by a handler within its slice, often via a mediator.

features/
  place-order/    PlaceOrder.cs  (request, validator, handler, SQL)
  cancel-order/   CancelOrder.cs
  get-invoice/    GetInvoice.cs
  shared/         only proven reusable code
export async function placeOrder(cmd: PlaceOrder, db: Db) {
  validate(cmd)
  const stock = await db.query("select qty from stock where sku = $1", [cmd.sku])
  if (stock < cmd.qty) throw new OutOfStock()
  await db.exec("insert into orders ...")
}

A simple read slice can query the database directly and return a DTO. A complex command slice can load an aggregate and invoke domain methods. Rules shared by several slices live in the domain model, not in a generic service layer.

Pitfalls

  • Slices invoking other slices, which creates tangled implicit dependencies.
  • Abstracting too early; wait for the third repetition before extracting.
  • Skipping a domain model where invariants clearly span slices.
  • Having no conventions, so each slice looks different.
  • Using it as an excuse for no architecture tests.

Key takeaways

  • Organize by what changes together.
  • Let each slice choose its own design depth.
  • Share only what has proven shared.
  • Keep invariants in a common domain model when they cross slices.

✓ When to Use

  • •Feature-driven products with frequent, independent changes
  • •Teams wanting low coupling between features
  • •CQRS-style systems with distinct commands and queries

✗ When Not to Use

  • •Teams needing a rigid uniform structure for onboarding
  • •Highly shared domain logic spread across many operations
  • •Very small apps where layers are adequate

Pros

  • +Changes localized to one folder
  • +Each feature uses the right level of design
  • +Fewer merge conflicts across teams

Cons

  • −Duplication across slices
  • −Inconsistent approaches without conventions
  • −Shared domain rules need deliberate placement

Cost Profile

Infrastructure

None — code organization

Operational

Low

Cognitive

Low to medium

Failure Modes

  • Slices calling each other and recreating hidden layers

  • Copy-pasted business rules diverging between slices

  • Shared folder growing into a new monolithic layer

Real-World Examples

Alternatives

    Related Patterns

      Competency Domains

      economics evolutionrequirements constraints