{"id":"6b08bd3180884893657cc924","slug":"cqrs","title":"CQRS: one model for changing, another for reading","summary":"Command Query Responsibility Segregation without overdoing it: from Bertrand Meyer's CQS, through three levels of CQRS, to projections and eventual consistency. Commands, queries and projections in C#, TypeScript, Java, Go and Python.","servedLang":"en","availableLangs":["pl","en"],"topics":["cqrs","event-sourcing","vertical-slice-architecture"],"techs":["dotnet","java","typescript","go","python"],"tags":["architecture","cqrs","cqs","projections","read-models","eventual-consistency"],"level":"intermediate","kind":"article","access":"members","status":"published","cover":null,"author":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","community":false},"readingMinutes":12,"stats":{"views":3,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-26T23:13:53.695Z","updatedAt":"2026-11-27T13:10:10.084Z","requestedLang":"en","theme":{"hero":"classic","heroMedia":null,"accent":"teal","background":"grid","weaveResources":true,"toc":"right"},"seoDescription":"CQRS (Command Query Responsibility Segregation): commands and queries, write and read models, projections, eventual consistency, the difference from CQS and event sourcing, examples in C#, TypeScript, Java, Go and Python, MediatR, @nestjs/cqrs, Axon.","wordCount":2293,"doc":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"The board in Halina's kitchen shows the queue of tickets: what to make, how many pieces, how many minutes the customer has been waiting. To display it, the system ran a query joining five tables and computed everything on the fly, while the same ORM "},{"type":"text","text":"Order","marks":[{"type":"code"}]},{"type":"text","text":" model also handled placing orders, discounts and invoices. Every read optimisation broke the writes and vice versa. "},{"type":"text","text":"CQRS","marks":[{"type":"bold"}]},{"type":"text","text":" (Command Query Responsibility Segregation) separates these two responsibilities: one model for changing state, another for reading."}]},{"type":"callout","attrs":{"variant":"tip","title":"In short"},"content":[{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"A "},{"type":"text","text":"command","marks":[{"type":"bold"}]},{"type":"text","text":" changes state and returns no data (apart from, say, an identifier); a "},{"type":"text","text":"query","marks":[{"type":"bold"}]},{"type":"text","text":" returns data and changes nothing."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The write side uses a domain model that guards the rules, the read side uses "},{"type":"text","text":"models tailored to screens","marks":[{"type":"bold"}]},{"type":"text","text":" (views, projections)."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"CQRS is not event sourcing or separate databases – it's a pattern you can adopt "},{"type":"text","text":"gradually","marks":[{"type":"bold"}]},{"type":"text","text":", and only where it pays off."}]}]}]}]},{"type":"stats","attrs":{"items":[{"value":"1988","label":"the CQS principle","hint":"Bertrand Meyer, \"Object-Oriented Software Construction\""},{"value":"2009","label":"\"Clarified CQRS\"","hint":"Udi Dahan sorts out the concepts"},{"value":"3","label":"levels of CQRS","hint":"from separate handlers to separate data stores"}]}},{"type":"heading","attrs":{"level":2,"id":"context-and-forces"},"content":[{"type":"text","text":"Context and forces"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Asymmetric load","marks":[{"type":"bold"}]},{"type":"text","text":" – the kitchen board, order history and menu are read hundreds of times more often than an order is placed."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Different data shapes","marks":[{"type":"bold"}]},{"type":"text","text":" – writes need an aggregate with rules, reads need a flat list ready for display."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Complex write rules","marks":[{"type":"bold"}]},{"type":"text","text":" – the hundred-pierogi limit, statuses and payments shouldn't compete with report performance."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Many views of the same data","marks":[{"type":"bold"}]},{"type":"text","text":" – the kitchen, the customer, Halina in the admin panel and accounting all see an order differently."}]}]}]},{"type":"heading","attrs":{"level":2,"id":"from-cqs-to-cqrs"},"content":[{"type":"text","text":"From CQS to CQRS"}]},{"type":"paragraph","content":[{"type":"text","text":"In 1988, Bertrand Meyer formulated the "},{"type":"text","text":"CQS","marks":[{"type":"bold"}]},{"type":"text","text":" (Command–Query Separation) principle at the method level: a method either changes the state of an object or returns a value – never both. In the late 2000s, Greg Young lifted it to the architectural level: if methods can be separated, so can "},{"type":"text","text":"models","marks":[{"type":"bold"}]},{"type":"text","text":". Udi Dahan in "},{"type":"text","text":"Clarified CQRS","marks":[{"type":"italic"}]},{"type":"text","text":" (2009) and Martin Fowler in a short 2011 post added an important caveat: it's a pattern for selected parts of a system, not for the whole."}]},{"type":"heading","attrs":{"level":2,"id":"structure"},"content":[{"type":"text","text":"Structure"}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"flowchart LR\n  ui[\"UI: kitchen, customer app, Halina's panel\"]\n  subgraph write[\"Write side\"]\n    direction TB\n    ch[\"Command handlers<br/>PlaceOrder, MarkOrderReady\"]\n    agg[\"Order aggregate<br/>rules and invariants\"]\n    wdb[(\"Write database<br/>normalised\")]\n    ch --> agg --> wdb\n  end\n  subgraph read[\"Read side\"]\n    direction TB\n    qh[\"Query handlers<br/>GetKitchenBoard, GetOrderHistory\"]\n    rdb[(\"Read models<br/>views, flat tables, cache\")]\n    qh --> rdb\n  end\n  proj[\"Projections<br/>(synchronous or via events)\"]\n  ui -- \"commands\" --> ch\n  ui -- \"queries\" --> qh\n  agg -- \"events: OrderPlaced, OrderReady\" --> proj --> rdb","caption":"CQRS: commands go to the write model, queries to the read model"}},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Level"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"What it means"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Consistency"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"When it's enough"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"1. Separate commands and queries"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Separate request and handler classes, the same database and model"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"immediate"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"almost always – good order in the code"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"2. Separate read models"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Queries read views or denormalised tables in the same database"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"immediate or eventual"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"when screens need joins and aggregations"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"3. Separate stores"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Read models in another database (Elasticsearch, Redis, a replica), updated by events"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"eventual"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"large read scale, search, reporting"}]}]}]}]},{"type":"heading","attrs":{"level":2,"id":"what-it-looks-like-in-code"},"content":[{"type":"text","text":"What it looks like in code"}]},{"type":"paragraph","content":[{"type":"text","text":"The write side goes through the aggregate, the read side reads a table tailored to the kitchen board – no ORM and no joins:"}]},{"type":"codeGroup","attrs":{"title":"Command and query"},"content":[{"type":"codeBlock","attrs":{"language":"csharp","filename":"CommandAndQuery.cs"},"content":[{"type":"text","text":"// WRITE SIDE – a command changes state through the domain model and returns (almost) nothing\npublic sealed record MarkOrderReady(Guid OrderId) : IRequest;\n\ninternal sealed class MarkOrderReadyHandler(OrdersDb db, IPublisher events) : IRequestHandler<MarkOrderReady>\n{\n    public async Task Handle(MarkOrderReady cmd, CancellationToken ct)\n    {\n        var order = await db.Orders.Include(o => o.Lines).SingleAsync(o => o.Id == cmd.OrderId, ct);\n        order.MarkReady();                                    // invariants guarded by the aggregate\n        await db.SaveChangesAsync(ct);\n        await events.Publish(new OrderReady(order.Id, order.Phone), ct);\n    }\n}\n\n// READ SIDE – a query never changes state and reads a model shaped for the screen\npublic sealed record GetKitchenBoard(int Limit = 30) : IRequest<IReadOnlyList<KitchenTicketView>>;\npublic sealed record KitchenTicketView(Guid OrderId, string Summary, int Pieces, DateTime PlacedAt, int MinutesWaiting);\n\ninternal sealed class GetKitchenBoardHandler(IDbConnection sql)\n    : IRequestHandler<GetKitchenBoard, IReadOnlyList<KitchenTicketView>>\n{\n    public async Task<IReadOnlyList<KitchenTicketView>> Handle(GetKitchenBoard q, CancellationToken ct) =>\n        (await sql.QueryAsync<KitchenTicketView>(new CommandDefinition(\"\"\"\n            SELECT TOP (@Limit) OrderId, Summary, Pieces, PlacedAt,\n                   DATEDIFF(minute, PlacedAt, SYSUTCDATETIME()) AS MinutesWaiting\n            FROM read.KitchenBoard           -- a denormalised table, no joins\n            ORDER BY PlacedAt\n            \"\"\", new { q.Limit }, cancellationToken: ct))).AsList();   // Dapper, no ORM tracking\n}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"kitchen.cqrs.ts"},"content":[{"type":"text","text":"import { CommandHandler, ICommandHandler, IQueryHandler, QueryHandler, EventBus } from \"@nestjs/cqrs\";\n\n// WRITE SIDE\nexport class MarkOrderReadyCommand {\n  constructor(public readonly orderId: string) {}\n}\n\n@CommandHandler(MarkOrderReadyCommand)\nexport class MarkOrderReadyHandler implements ICommandHandler<MarkOrderReadyCommand> {\n  constructor(private readonly orders: OrdersRepository, private readonly events: EventBus) {}\n\n  async execute({ orderId }: MarkOrderReadyCommand): Promise<void> {\n    const order = await this.orders.get(orderId);\n    order.markReady(); // invariants guarded by the aggregate\n    await this.orders.save(order);\n    this.events.publish(new OrderReadyEvent(order.id, order.phone));\n  }\n}\n\n// READ SIDE\nexport class GetKitchenBoardQuery {\n  constructor(public readonly limit = 30) {}\n}\n\n@QueryHandler(GetKitchenBoardQuery)\nexport class GetKitchenBoardHandler implements IQueryHandler<GetKitchenBoardQuery> {\n  constructor(private readonly db: Kysely<ReadDb>) {}\n\n  execute({ limit }: GetKitchenBoardQuery): Promise<KitchenTicketView[]> {\n    return this.db\n      .selectFrom(\"kitchen_board\") // a denormalised table maintained by a projection\n      .selectAll()\n      .orderBy(\"placed_at\")\n      .limit(limit)\n      .execute();\n  }\n}"}]},{"type":"codeBlock","attrs":{"language":"java","filename":"KitchenCqrs.java"},"content":[{"type":"text","text":"// WRITE SIDE\npublic record MarkOrderReady(UUID orderId) {}\n\n@Service\nclass MarkOrderReadyHandler {\n    private final OrderRepository orders;\n    private final ApplicationEventPublisher events;\n\n    MarkOrderReadyHandler(OrderRepository orders, ApplicationEventPublisher events) {\n        this.orders = orders;\n        this.events = events;\n    }\n\n    @Transactional\n    public void handle(MarkOrderReady cmd) {\n        var order = orders.findById(cmd.orderId()).orElseThrow();\n        order.markReady();                                  // invariants guarded by the aggregate\n        events.publishEvent(new OrderReady(order.id(), order.phone()));\n    }\n}\n\n// READ SIDE\npublic record KitchenTicketView(UUID orderId, String summary, int pieces, Instant placedAt) {}\n\n@Service\nclass KitchenBoardQueries {\n    private final JdbcClient jdbc;\n\n    KitchenBoardQueries(JdbcClient jdbc) { this.jdbc = jdbc; }\n\n    @Transactional(readOnly = true)\n    public List<KitchenTicketView> board(int limit) {\n        return jdbc.sql(\"\"\"\n                SELECT order_id, summary, pieces, placed_at\n                FROM read_kitchen_board              -- denormalised, no joins\n                ORDER BY placed_at LIMIT :limit\n                \"\"\")\n            .param(\"limit\", limit)\n            .query(KitchenTicketView.class)\n            .list();\n    }\n}"}]},{"type":"codeBlock","attrs":{"language":"go","filename":"kitchen/cqrs.go"},"content":[{"type":"text","text":"package kitchen\n\n// WRITE SIDE\ntype MarkOrderReady struct{ OrderID string }\n\ntype MarkOrderReadyHandler struct {\n\tOrders OrderRepository\n\tEvents EventPublisher\n}\n\nfunc (h MarkOrderReadyHandler) Handle(ctx context.Context, cmd MarkOrderReady) error {\n\torder, err := h.Orders.Get(ctx, cmd.OrderID)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif err := order.MarkReady(); err != nil { // invariants guarded by the aggregate\n\t\treturn err\n\t}\n\tif err := h.Orders.Save(ctx, order); err != nil {\n\t\treturn err\n\t}\n\treturn h.Events.Publish(ctx, OrderReady{OrderID: order.ID, Phone: order.Phone})\n}\n\n// READ SIDE – a separate, read-only path straight to a view table\ntype KitchenTicketView struct {\n\tOrderID  string    `json:\"orderId\"`\n\tSummary  string    `json:\"summary\"`\n\tPieces   int       `json:\"pieces\"`\n\tPlacedAt time.Time `json:\"placedAt\"`\n}\n\nfunc KitchenBoard(ctx context.Context, db *sql.DB, limit int) ([]KitchenTicketView, error) {\n\trows, err := db.QueryContext(ctx,\n\t\t`SELECT order_id, summary, pieces, placed_at FROM read_kitchen_board ORDER BY placed_at LIMIT $1`, limit)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer rows.Close()\n\tvar out []KitchenTicketView\n\tfor rows.Next() {\n\t\tvar v KitchenTicketView\n\t\tif err := rows.Scan(&v.OrderID, &v.Summary, &v.Pieces, &v.PlacedAt); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tout = append(out, v)\n\t}\n\treturn out, rows.Err()\n}"}]},{"type":"codeBlock","attrs":{"language":"python","filename":"kitchen/cqrs.py"},"content":[{"type":"text","text":"from dataclasses import dataclass\n\nfrom sqlalchemy import text\n\n\n# WRITE SIDE\n@dataclass(frozen=True)\nclass MarkOrderReady:\n    order_id: str\n\n\nclass MarkOrderReadyHandler:\n    def __init__(self, orders: \"OrderRepository\", events: \"EventPublisher\"):\n        self.orders, self.events = orders, events\n\n    def __call__(self, cmd: MarkOrderReady) -> None:\n        order = self.orders.get(cmd.order_id)\n        order.mark_ready()  # invariants guarded by the aggregate\n        self.orders.save(order)\n        self.events.publish(OrderReady(order_id=order.id, phone=order.phone))\n\n\n# READ SIDE – plain SQL against a denormalised view, returns dicts ready for JSON\ndef kitchen_board(session, limit: int = 30) -> list[dict]:\n    rows = session.execute(\n        text(\"SELECT order_id, summary, pieces, placed_at FROM read_kitchen_board \"\n             \"ORDER BY placed_at LIMIT :limit\"),\n        {\"limit\": limit},\n    )\n    return [dict(r._mapping) for r in rows]"}]}]}]},"toc":[{"id":"context-and-forces","text":"Context and forces","level":2,"locked":false},{"id":"from-cqs-to-cqrs","text":"From CQS to CQRS","level":2,"locked":false},{"id":"structure","text":"Structure","level":2,"locked":false},{"id":"what-it-looks-like-in-code","text":"What it looks like in code","level":2,"locked":false},{"id":"cqrs-and-event-sourcing","text":"CQRS and event sourcing","level":2,"locked":true},{"id":"trade-offs","text":"Trade-offs","level":2,"locked":true},{"id":"adoption-path","text":"Adoption path","level":2,"locked":true},{"id":"in-practice","text":"In practice","level":2,"locked":true},{"id":"anti-patterns","text":"Anti-patterns","level":2,"locked":true},{"id":"related-topics","text":"Related topics","level":2,"locked":true},{"id":"test-yourself","text":"Test yourself","level":2,"locked":true}],"locked":true,"paywall":null,"previewRatio":0.3,"totalBlocks":36,"visibleBlocks":13,"resources":[{"id":"6b0857be3c96f2d34d0b422d","type":"article","provider":"web","url":"https://udidahan.com/2009/12/09/clarified-cqrs","embedUrl":null,"title":"Clarified CQRS","description":"","author":"Udi Dahan","thumbnailUrl":null,"durationSec":null,"lang":"en","topics":["cqrs"],"techs":["general"],"tags":["software-architecture"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":70,"verifiedAt":"2026-11-26T11:26:00.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:59.965Z","updatedAt":"2026-11-26T16:00:59.965Z"},{"id":"6b0857b53c96f2d34d0b3a3f","type":"article","provider":"web","url":"https://martinfowler.com/bliki/CQRS.html","embedUrl":null,"title":"CQRS: Command Query Responsibility Segregation (2011)","description":"CQRS (Command Query Responsibility Segregation) is the notion that you can use a different model to update information than the model you use to read information","author":"martinfowler.com","thumbnailUrl":"https://martinfowler.com/bliki/images/cqrs/cqrs.png","durationSec":null,"lang":"en","topics":["cqrs"],"techs":["general"],"tags":["software-architecture","hacker-news"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"hn","publishedAt":"2020-11-11T12:48:09.000Z","popularity":60,"verifiedAt":"2026-11-26T11:15:54.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:52.228Z","updatedAt":"2026-11-26T16:00:52.228Z"},{"id":"6b0857a53c96f2d34d0b3216","type":"video","provider":"youtube","url":"https://www.youtube.com/watch?v=JHGkaShoyNs","embedUrl":"https://www.youtube-nocookie.com/embed/JHGkaShoyNs","title":"Greg Young - CQRS and Event Sourcing - Code on the Beach 2014","description":"","author":"Code on the Beach","thumbnailUrl":"https://i.ytimg.com/vi/JHGkaShoyNs/hqdefault.jpg","durationSec":null,"lang":"en","topics":["cqrs","event-sourcing"],"techs":["general"],"tags":[],"price":"free","featured":true,"featuredOrder":12,"packageName":null,"source":"seed","publishedAt":null,"popularity":0,"verifiedAt":"2026-11-26T00:00:00.000Z","curated":true,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:37.067Z","updatedAt":"2026-11-26T16:00:37.067Z"},{"id":"6b0857bf3c96f2d34d0b42a0","type":"article","provider":"web","url":"https://learn.microsoft.com/en-us/azure/architecture/patterns/cqrs","embedUrl":null,"title":"CQRS Pattern","description":"Learn how to segregate operations that read data from operations that update data by using the Command Query Responsibility Segregation (CQRS) pattern.","author":"Microsoft Azure Architecture Center","thumbnailUrl":"https://learn.microsoft.com/en-us/media/open-graph-image.png","durationSec":null,"lang":"en","topics":["cqrs"],"techs":["general"],"tags":["azure","cloud","software-architecture"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":63,"verifiedAt":"2026-11-26T11:07:47.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T16:01:02.417Z"},{"id":"6b0857b73c96f2d34d0b3bcd","type":"podcast","provider":"apple-podcasts","url":"https://podcasts.apple.com/us/podcast/57-o-faktach-i-mitach-wzorca-cqrs-z-oskarem-dudyczem/id1508298430?i=1000608274059","embedUrl":"https://embed.podcasts.apple.com/us/podcast/id1508298430?i=1000608274059","title":"57. O faktach i mitach wzorca CQRS z Oskarem Dudyczem","description":"CQRS, czyli Command Query Responsibility Segregation, jest wzorcem wyjątkowo popularnym i powszechnie stosowanym w wielu systemach. Mało kto jednak sięgnął po oryginalny dokument autorstwa Grega Younga, który opisuje założenia tego konceptu architektonicznego i z czasem obrósł on kilkoma mitami…","author":"Better Software Design","thumbnailUrl":"https://is1-ssl.mzstatic.com/image/thumb/Podcasts115/v4/a9/6d/bb/a96dbb46-a01a-9cf6-40ef-27a27cef3c73/mza_18038037312547630971.jpg/600x600bb.jpg","durationSec":3417,"lang":"pl","topics":["cqrs"],"techs":["general"],"tags":["podcast","software-architecture"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"itunes","publishedAt":"2023-04-10T23:00:00.000Z","popularity":69,"verifiedAt":"2026-11-26T10:58:49.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:53.924Z","updatedAt":"2026-11-26T16:00:53.924Z"},{"id":"6b0857be3c96f2d34d0b41ec","type":"article","provider":"web","url":"https://martinfowler.com/bliki/CommandQuerySeparation.html","embedUrl":null,"title":"bliki: Command Query Separation","description":"a bliki entry for Command Query Separation","author":"Martin Fowler","thumbnailUrl":"https://martinfowler.com/logo-sq.png","durationSec":null,"lang":"en","topics":["cqrs"],"techs":["general"],"tags":["martin-fowler","software-architecture"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":75,"verifiedAt":"2026-11-26T11:07:17.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:59.965Z","updatedAt":"2026-11-26T16:00:59.965Z"}],"challenges":[{"id":"6b093dc091bd8fbaf2a0c8c0","slug":"event-sourced-account","title":"Event-sourced bank account","summary":"An account aggregate whose state comes only from replaying events, an event store with optimistic concurrency and a repository that saves only new facts. Queries about past state come for free.","servedLang":"en","availableLangs":["pl","en"],"kind":"code","category":"architecture","status":"published","difficulty":"hard","topics":["event-sourcing","cqrs"],"techs":["typescript","javascript","python","dotnet","java","go"],"tags":["event-sourcing","aggregate","event-store","optimistic-concurrency","ddd"],"languages":["typescript","javascript","python","csharp","java","go"],"questionCount":null,"xp":40,"stats":{"attempts":0,"solves":0,"solutions":0,"comments":0},"solveRate":null,"publishedAt":"2026-11-27T08:22:24.935Z"},{"id":"6b093dc191bd8fbaf2a0c8d0","slug":"inventory-cqrs","title":"Inventory with CQRS – separate write and read models","summary":"Warehouse commands validated on their own write model, events on a bus and a projection building a read model with a low-stock report. The read model can be rebuilt from events alone.","servedLang":"en","availableLangs":["pl","en"],"kind":"code","category":"architecture","status":"published","difficulty":"medium","topics":["cqrs","event-driven-architecture"],"techs":["typescript","javascript","python","dotnet","java","go"],"tags":["cqrs","read-model","projection","events","inventory"],"languages":["typescript","javascript","python","csharp","java","go"],"questionCount":null,"xp":20,"stats":{"attempts":0,"solves":0,"solutions":0,"comments":0},"solveRate":null,"publishedAt":"2026-11-27T08:22:25.519Z"}],"attachments":[],"hasCode":true,"repoUrl":null,"series":[{"slug":"architecture-path","title":"From monolith to microservices","items":[{"slug":"monolith","title":"The Monolith: one application, one deployment, and why it is often the right start","current":false},{"slug":"modular-monolith","title":"The Modular Monolith: hard boundaries without the cost of the network","current":false},{"slug":"layered-architecture","title":"Layered architecture: presentation, logic, data – and where it breaks","current":false},{"slug":"hexagonal-architecture","title":"Pierogi in the Hexagon","current":false},{"slug":"clean-architecture","title":"Clean Architecture: the dependency rule and use cases at the centre","current":false},{"slug":"onion-architecture","title":"Onion architecture: the domain model in the middle, infrastructure outside","current":false},{"slug":"vertical-slice-architecture","title":"Vertical slice architecture: code by feature, not by layer","current":false},{"slug":"cqrs","title":"CQRS: one model for changing, another for reading","current":true},{"slug":"event-sourcing","title":"Event sourcing: store the facts, not just the latest state","current":false},{"slug":"event-driven-architecture","title":"Event-driven architecture: who publishes, who listens and what can go wrong","current":false},{"slug":"microservices","title":"Microservices: independent deployments, real costs and when it pays off","current":false},{"slug":"ddd-strategic-design","title":"DDD strategic design: subdomains, bounded contexts and context maps","current":false}]}],"prev":{"slug":"vertical-slice-architecture","title":"Vertical slice architecture: code by feature, not by layer"},"next":{"slug":"event-sourcing","title":"Event sourcing: store the facts, not just the latest state"},"featured":false,"authorCard":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","headline":"Wzorce projektowe · Architektura · AI i LLM","community":false,"reputation":{"points":3900,"level":{"key":"mentor","label":"Mentor"}},"articles":68,"skills":[{"key":"typescript","title":"TypeScript","level":5,"levelLabel":"Authority","articles":63},{"key":"dotnet","title":".NET","level":5,"levelLabel":"Authority","articles":53},{"key":"python","title":"Python","level":5,"levelLabel":"Authority","articles":52},{"key":"java","title":"Java","level":5,"levelLabel":"Authority","articles":38}]}}