---
title: "CQRS (Command Query Responsibility Segregation) — Definition & Engineering Context"
description: "CQRS is an architectural pattern that separates database read (query) operations from write (command) operations into distinct models, allowing each side to be optimized, scaled, and secured independently."
canonical: https://erpstack.io/glossary/cqrs
markdown_url: https://erpstack.io/glossary/cqrs.md
publisher: ERPStack
---

# CQRS (Command Query Responsibility Segregation)

> **Definition:** CQRS is an architectural pattern that separates database read (query) operations from write (command) operations into distinct models, allowing each side to be optimized, scaled, and secured independently.

## In depth

In a standard CRUD application, read and write operations compete for the same database resources. CQRS splits the data model: commands mutate state through an OLTP write database, while queries read from an optimized read replica or materialized view. This is particularly valuable in ERP systems where real-time reporting queries (e.g., 'show all orders in the last 30 days') would otherwise lock the same tables processing new order writes.

## How ERPStack applies this

We implement CQRS using PostgreSQL read replicas for analytics dashboards, keeping writes on the primary instance. This allows real-time reporting without impacting transaction throughput on the write path.

## Related reading

- [OLAP vs. OLTP Database Partitioning](https://erpstack.io/glossary/olap-vs-oltp)
- [Event-Driven Architecture](https://erpstack.io/glossary/event-driven)
- [Headless ERP](https://erpstack.io/glossary/headless-erp)
