Title: Vertical Slice Architecture – handling side-effects without cross-slice coupling
Hi 👋
I’m applying a vertical slice architecture with MediatR, and I’m running into a design concern around side-effects and coupling between slices.
Context
After each student is created, I want to fire:
StudentCreatedNotification
This notification is handled by multiple handlers:
StudentReminderWorker
StudentViewedNotificationHandler
Current command handler:
public class CommandHandler : IRequestHandler<Command, int>
{
private readonly SchoolContext _db;
public CommandHandler(SchoolContext db) => _db = db;
public async Task<int> Handle(Command message, CancellationToken token)
{
var student = new Student
{
FirstMidName = message.FirstMidName,
LastName = message.LastName,
EnrollmentDate = message.EnrollmentDate!.Value
};
await _db.Students.AddAsync(student, token);
await _db.SaveChangesAsync(token);
mediator.get().publish(
StudentCreatedNotification(student.Id)
);
return student.Id;
}
}
Problem
Now the Student vertical slice is directly aware of and publishing a notification that belongs to another module/slice.
This introduces coupling between:
- Student slice (core business behavior)
- Notification/Worker slices (side-effects)
Which feels like it breaks vertical slice isolation.
Questions
- Where should this kind of side-effect live in a vertical slice architecture?
- How do you avoid coupling between slices when publishing notifications/events?
Would really appreciate guidance
Title: Vertical Slice Architecture – handling side-effects without cross-slice coupling
Hi 👋
I’m applying a vertical slice architecture with MediatR, and I’m running into a design concern around side-effects and coupling between slices.
Context
After each student is created, I want to fire:
StudentCreatedNotificationThis notification is handled by multiple handlers:
StudentReminderWorkerStudentViewedNotificationHandlerCurrent command handler:
Problem
Now the Student vertical slice is directly aware of and publishing a notification that belongs to another module/slice.
This introduces coupling between:
Which feels like it breaks vertical slice isolation.
Questions
Would really appreciate guidance