Slice Boundaries
Slice Boundaries
Two slices coexisting in the same codebase need rules for what they can share and how they communicate. Get this wrong and VSA collapses back into layered architecture — just nested one folder deeper.
What can a slice depend on?
| Target | Allowed? |
|---|---|
| Another slice's domain types | No — tight coupling |
| Another slice's domain events | Yes — events are the contract |
| Another slice's use cases | No — use cases are slice-internal |
| Another slice's HTTP API | No — internal calls bypass the API |
Shared kernel (shared/) |
Yes, sparingly |
| True infrastructure (logging, DB, HTTP) | Yes |
Cross-slice communication
Three legal channels:
- Domain events. Slice A publishes; Slice B subscribes. Slice B reacts after Slice A's transaction commits.
- IDs. Slice A holds
Slice B's entity ID(aUUID, an int). When it needs data, it goes through Slice B's public interface (use case or — for read models — a query service). - Shared kernel. Truly shared concepts (
Money,UserId,EventId) live inshared/. Frozen as much as possible — every team depends on it.
What goes in the shared kernel
Almost nothing. Specifically:
- VOs used in multiple slices (
Money,Email,PhoneNumber). - Cross-cutting types (
EventId,TraceContext). - Domain-agnostic utilities (
ClockProtocol,Result).
What does not belong:
- Repositories.
- Aggregates.
- Use cases.
- Anything one slice owns.
Detecting a leak
Symptoms that slice boundaries have rotted:
- Slice A imports
from order.domain.order import Order. Order's shape is part of Slice A's API now. - Slice A's use case calls
Slice B's use case directly. Internal coupling via Python imports. - "Shared" folder growing every week. Means the wrong things are landing there.
- Renaming a field in Slice B's aggregate breaks Slice A's tests.
Anti-patterns
- Kitchen-sink
common/. Every utility ends up here. Becomes a god module that every slice imports — coupling to it is invisible. - Hidden coupling via SQL. Slice A's repository joins Slice B's tables directly. SQL bypasses the type system; coupling is invisible.
- One database, no schema discipline. Tables shared, foreign keys span slices, migrations require coordination. The boundaries exist only in folders.
How to test boundary discipline
Add a static import check (via import-linter or similar). Encode the rule: "Slice A must not import from slice_b.domain, only from slice_b.events or shared/." CI fails when a developer accidentally couples slices.
The hardest rule
Two slices may share a database, but they should never share a write transaction. Cross-slice writes are events, not joins. Cross-slice reads are explicit queries with their own DTOs, not JOIN aliases.