Microservices Pattern: Pattern: Command Query Responsibility Segregation (CQRS) (original) (raw)

pattern [ service collaboration](/tags/service collaboration) [ implementing queries](/tags/implementing queries)


Want to learn more about this pattern?

Take a look at my self-paced, online bootcamp that teaches you how to use the Saga, API Composition, and CQRS patterns to design operations that span multiple services.

The regular price is 395/personbutusecouponOFFEFKCWtosignupfor395/person but use coupon OFFEFKCW to sign up for 395/personbutusecouponOFFEFKCWtosignupfor95 (valid until Sept 30th, 2025)

Context

You have applied the Microservices architecture pattern and the Database per service pattern. As a result, it is no longer straightforward to implement queries that join data from multiple services. Also, if you have applied the Event sourcing pattern then the data is no longer easily queried.

Problem

How to implement a query that retrieves data from multiple services in a microservice architecture?

Solution

Define a view database, which is a read-only ‘replica’ that is designed specifically to support that query, or a group related queries. The application keeps the database up to date by subscribing to Domain events published by the service that own the data. The type of database and its schema are optimized for the query or queries. It’s often a NoSQL database, such as a document database or a key-value store.

Examples

Resulting context

This pattern has the following benefits:

This pattern has the following drawbacks:

See also

Learn more


pattern [ service collaboration](/tags/service collaboration) [ implementing queries](/tags/implementing queries)


Copyright © 2026 Chris Richardson • All rights reserved • Supported by Kong.