Command Query Responsibility Segregation (CQRS) | Redis (2024)

The future of fast is coming to an event in your city.Join us at Redis Released

Back

Command Query Responsibility Segregation (CQRS) | Redis (5)

Search

Optimize queries to reduce costs in microservice applications

Solutions brief

Learn more about microservices

What is CQRS?

Command Query Responsibility Segregation (CQRS) is a pattern within microservice architectures that decouples reads (queries) from writes (commands). This enables an application to optimize database writes to a slower disk-based SQL database, while pre-fetching and caching that data using Redis Enterprise’s integrated Change Data Capture (CDC) capability for read-optimized querying. Doing so enables the data to be shared with other microservices without breaking isolation and coupling their deployments.

What is a CQRS pattern in microservices?

CQRS is a microservices design pattern that separates read and update operations for a data store to optimize its performance, scalability, and security.

Command Query Responsibility Segregation (CQRS) | Redis (6)

How it works in a payment app

  1. Data is written to the system-of-record database within a microservice sub-domain (payment approval).
  2. Data is pre-fetched to the Redis Enterprise cache from the system of record. The cache uses its own data schema optimized for queries and can perform dynamic indexing for searches.
  3. Another microservice (payment history) reads directly from the cache with no coupling to the system of record command (write) database.
  4. The Redis integrated Change Data Capture (CDC) capability tracks the updates in the command database transaction log, transforms row level change data into a read-optimized Redis data structure or model, and replicates the updates to the query database in near real time.

Address challenges of scale, latency, and resiliency in microservice architectures

When to use CQRS pattern

  • Data from one domain needs to be queried by a different service without creating dependencies.
  • The command database has complex business logic and must persist data for long term recordkeeping, but the read microservice just needs to query the data.
  • Services have significantly more reads than writes.
  • Read performance and scalability are critical requirements.
  • The read data store is updated in near real time with changes in the write database (eventually consistent).

Solves your challenges

The problemThe Redis Enterprise solution
Accessing data across domains creates too many dependenciesCommand Query Responsibility Segregation (CQRS) | Redis (7) Maintain isolation among microservices by creating a separate read-only cache to serve data to different services.
Command Query Responsibility Segregation (CQRS) | Redis (8) Segregate the read and write data stores to create maintainable and flexible application models.
Cannot optimize for both writes (durability and consistency) and reads (real-time queries)Command Query Responsibility Segregation (CQRS) | Redis (9) Use a simple read-optimize schema for the query cache; employ a write-optimized schema for the system-of-record that requires persistent updates and complex business logic.
Command Query Responsibility Segregation (CQRS) | Redis (10) Store a materialized view of the data to avoid complex joins or mappings during data access.
Excessive reads cause performance penalties and higher infrastructure costsCommand Query Responsibility Segregation (CQRS) | Redis (11) Minimize infrastructure requirements and mainframe MIPS by offloading read processing to a cache, enabling fast queries and reducing the burden on the system of record.
Command Query Responsibility Segregation (CQRS) | Redis (12) Rely on Redis Enterprise support for multiple data structures, with easy scalability to deliver millions of operations per second throughput at <1ms latency.
Developing code for syncing data increases complexity and OpEx costCommand Query Responsibility Segregation (CQRS) | Redis (13) Why build your own? Use Redis Enterprise’s integrated CDC instead of implementing a separate syncing solution and incurring the associated costs of doing so.

Benefits of implementing CQRS pattern

  • Improved read performance of repetitive queries.
  • Independent scaling and optimization of write and read operations.
  • Support of multiple data structures and models on unified data platform.
  • Decreased burden on the command database (systems of record) saving infrastructure costs.
  • Reduced developer resources due to simplicity of deploying Redis Enterprise cache and integrated CDC capability.

Learn more

Command Query Responsibility Segregation (CQRS) | Redis (14)

Dev resources

Tutorials and code samples

Demos

5 microservices misconceptions blog

Command Query Responsibility Segregation (CQRS) | Redis (15)

DevOp & Architect resources

Download solution brief

Watch DevOps.com webinar

Mutualink case study

Microservices key concepts blog

Related resources

Industries

Financial services

Mobile banking

Fraud detection

Retail

Real-time inventory

Gaming

Healthcare

Architectures

Microservices

Caching

Technical Solutions

Query caching

Interservice communications

FAQs

  • What are microservice domains?
    • Typically in microservices architectures, Domain-Driven Design (DDD) refers to the application’s business function as the domain. A domain consists of multiple subdomains, which corresponds to a different part of the business. As an example, in an retail eCommerce website domain may consist of several subdomains including product catalog, shopping cart, checkout, inventory and order management, etc.
  • How does the CQRS pattern differ from traditional CRUD-based architectures?
    • CRUD stands for Create, Read, Update, and Delete and is the most common pattern for traditional data operations for applications. It uses the same data store and model for read and write operations as opposed to Command Query Responsibility Segregation (CQRS) which separates the read and write data models. One of the primary advantages of CRUD design is its simplicity, you can use the same set of classes for all functions.For applications which employ simple business logic, e.g. a user registration app for managing registration, storing a list of users, updating user information, and removing users, CRUD is the best fit. However, as your application become increasingly complex, say in a financial services app with payments, fraud detection, settlement, and compliance domains using a microservice architecture with dozens or hundreds of services each with different databases and access requirements, a CQRS pattern could be a better match in this scenario.
  • What is CDC?
    • Change data capture (CDC) refers to the tracking of all changes in a data source so they can be replicated and sync’d to the destination systems. CDC provides data integrity and consistency across domains and services.
  • What are Advantages and Disadvantages of CQRS?
    • One of the main advantages of using the CQRS design pattern is that it allows for better scalability and performance. Since the read and write operations are separated, they can be optimized independently, resulting in faster response times for read operations. However, the CQRS pattern can also add complexity to an application. Developers need to be careful to maintain consistency between the read and write models, and the additional complexity can make the application harder to maintain.
  • How do Event Sourcing and CQRS work together?
    • Event Sourcing is a technique that can capture every change made to an application’s state as a series of events. Instead of storing the current state of an application, Event Sourcing stores the history of all the events that led up to the current state. This means that at any point in time, you can reconstruct the state of the application by replaying the events that led up to it. Event Sourcing can be used in conjunction with CQRS to provide a scalable and efficient way to have separate read and write data models to optimize performance of specific microservices. When you use Event Sourcing with CQRS, the write model can use an event store like Redis Streams to capture data updates. The read model then uses this update event stream to maintain eventual consistency, making it easier to scale the read model independently from the write model. Another option is to use Change Data Capture solutions like Oracle Goldengate, Kafka Connect, or Redis Enterprise integrated CDC capability that are designed for this use case with multiple source and sink connectors to different database vendors.
  • What is Integration of CQRS with DDD?
    • CQRS can be integrated with Domain Driven Design (DDD), which is an approach to software development that focuses on the business domain and its processes. The synergy between CQRS and DDD creates a powerful combination that allows for efficient and scalable software development. CQRS also allows for a better separation of concerns. The domain model can focus on the business logic, while the read model can focus on querying and reporting. This separation makes the application easier to understand and maintain. Another advantage of using CQRS in DDD is that it simplifies testing and debugging. Since the read and write operations are separated, they can be tested independently, making it easier to isolate and fix issues.
Command Query Responsibility Segregation (CQRS) | Redis (2024)
Top Articles
Creating Your First Avatar | VRChat Creation
The University of Chicago
Spasa Parish
Rentals for rent in Maastricht
159R Bus Schedule Pdf
Sallisaw Bin Store
Black Adam Showtimes Near Maya Cinemas Delano
Espn Transfer Portal Basketball
Pollen Levels Richmond
11 Best Sites Like The Chive For Funny Pictures and Memes
Things to do in Wichita Falls on weekends 12-15 September
Craigslist Pets Huntsville Alabama
Paulette Goddard | American Actress, Modern Times, Charlie Chaplin
Red Dead Redemption 2 Legendary Fish Locations Guide (“A Fisher of Fish”)
What's the Difference Between Halal and Haram Meat & Food?
R/Skinwalker
Rugged Gentleman Barber Shop Martinsburg Wv
Jennifer Lenzini Leaving Ktiv
Justified - Streams, Episodenguide und News zur Serie
Epay. Medstarhealth.org
Olde Kegg Bar & Grill Portage Menu
Cubilabras
Half Inning In Which The Home Team Bats Crossword
Amazing Lash Bay Colony
Juego Friv Poki
Dirt Devil Ud70181 Parts Diagram
Truist Bank Open Saturday
Water Leaks in Your Car When It Rains? Common Causes & Fixes
What’s Closing at Disney World? A Complete Guide
New from Simply So Good - Cherry Apricot Slab Pie
Drys Pharmacy
modelo julia - PLAYBOARD
Poker News Views Gossip
Abby's Caribbean Cafe
Joanna Gaines Reveals Who Bought the 'Fixer Upper' Lake House and Her Favorite Features of the Milestone Project
Tri-State Dog Racing Results
Navy Qrs Supervisor Answers
Trade Chart Dave Richard
Lincoln Financial Field Section 110
Free Stuff Craigslist Roanoke Va
Wi Dept Of Regulation & Licensing
Pick N Pull Near Me [Locator Map + Guide + FAQ]
Crystal Westbrooks Nipple
Ice Hockey Dboard
Über 60 Prozent Rabatt auf E-Bikes: Aldi reduziert sämtliche Pedelecs stark im Preis - nur noch für kurze Zeit
Wie blocke ich einen Bot aus Boardman/USA - sellerforum.de
Infinity Pool Showtimes Near Maya Cinemas Bakersfield
Dermpathdiagnostics Com Pay Invoice
How To Use Price Chopper Points At Quiktrip
Maria Butina Bikini
Busted Newspaper Zapata Tx
Latest Posts
Article information

Author: Ouida Strosin DO

Last Updated:

Views: 6588

Rating: 4.6 / 5 (56 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Ouida Strosin DO

Birthday: 1995-04-27

Address: Suite 927 930 Kilback Radial, Candidaville, TN 87795

Phone: +8561498978366

Job: Legacy Manufacturing Specialist

Hobby: Singing, Mountain biking, Water sports, Water sports, Taxidermy, Polo, Pet

Introduction: My name is Ouida Strosin DO, I am a precious, combative, spotless, modern, spotless, beautiful, precious person who loves writing and wants to share my knowledge and understanding with you.