CQRS separates write operations (Commands) from read operations (Queries). At its simplest it is a folder discipline: Commands/ and Queries/ instead of one ServiceLayer. Commands change state and return void or an ID. Queries return read models and must have no side effects. MediatR is popular but not required. Vertical Slice Architecture takes CQRS further by co-locating all code for one feature (handler, validator, endpoint, DTO) in a single file/folder.
Vertical Slice Architecture: one folder per feature, all layers co-located.
Split into Commands/ and Queries/. You don't need MediatR or two databases for CQRS to pay dividends.
A Query handler must never write to the database. Queries are safe to retry, cache, and parallel-execute.
Co-locate endpoint + command + handler + validator in features/FeatureName/. This beats the horizontal layers (Controllers/, Services/, Repos/) anti-pattern.
Sign in to share your feedback and join the discussion.