패턴 탐색 / 서비스 아키텍처 / B020
command query responsibility segregation

CQRS

읽기와 쓰기 작업을 별도 데이터 모델로 분리하는 패턴

01 / UNDERSTAND

구조와 동작 원리

화살표를 단계별로 확인하세요.

읽기와 쓰기의 책임을 나눈다. 서로 다른 DB나 이벤트 소싱은 필수 조건이 아니다.

기대 효과

읽기/쓰기 모델 독립 최적화로 성능·확장성·보안 개선

트레이드오프

데이터스토어 간 최종 일관성과 읽기 지연을 유발

은행 잔액·재고·안전 필수 제어처럼 쓰기 직후 동일 데이터가 즉시 보여야 하는 경우 부적합

02 / APPLY

운영 및 적용 가이드

종합 설명 · 원문 인용으로 검증된 항목과 구분됩니다. 실제 적용 전 확인이 필요합니다.

언제 사용하는가

읽기/쓰기 부하 특성이 크게 다르고 고처리량·저지연, 복잡한 도메인, 감사·규제 요구가 있는 시스템에 적합하다. 예: 주식 거래, 주문·재고 조회가 분리된 이커머스.

시나리오

중형 온라인 쇼핑몰이 초당 수천 건 상품 조회와 상대적으로 적은 주문 쓰기를 처리해야 하고, 주문 직후 재고·주문 상태를 빠르게 보여주되 수 초 지연은 허용한다고 가정한다. 쓰기 측은 주문·재고 명령을 검증해 write DB에 저장하고 이벤트를 발행하며, 읽기 측은 별도 read model을 갱신해 상품 목록·주문 조회를 서비스한다. 결제 후 주문 완료 화면은 read-your-writes로 방금 쓴 내용을 우선 보여주고, 읽기 모델 지연을 모니터링한다.

배치 원칙

  • 쓰기 모델/DB는 명령 검증과 트랜잭션의 원본으로 배치
  • 읽기 모델/DB는 조회 전용으로 분리하고 필요 시 복제본·캐시 사용
  • 도메인 이벤트는 메시지 브로커를 통해 쓰기에서 읽기로 전달
  • 프로젝션/인덱서는 읽기 모델을 갱신하도록 별도 배포
  • Kubernetes에서는 write/read 서비스와 Redis master/replica, Helm 차트를 분리 배치

온프레미스

온프레미스에서는 컨테이너화한 명령·조회 서비스, 메시지 브로커, 읽기·쓰기 저장소를 사내 Kubernetes나 VM에 배치하고 네트워크·스토리지 격리, 보안·데이터 프라이버시, TCO, 백업·복구를 검토한다. 읽기 복제 지연과 브로커 적체를 모니터링하고 배포·업그레이드 절차를 표준화한다.

03 / VERIFY

14개 관점별 근거

조사 당시 근거 보유 여부입니다. 출처의 정확성과 최신성을 별도로 판단하세요.

정의·개요근거 있음

읽기와 쓰기 작업을 별도 데이터 모델로 분리하는 패턴

Segregate the read and write operations for a data store into separate data models.

learn.microsoft.com 원문 ↗

해결하는 문제근거 있음

단일 모델로 읽기·쓰기의 상이한 성능·확장 요구를 최적화하기 어려운 문제를 해결

As applications grow, it can become increasingly difficult to optimize read and write operations on a single data model.

learn.microsoft.com 원문 ↗

주요 구성 컴포넌트·리소스근거 있음

웹 앱(마이크로서비스), 쓰기/읽기 데이터스토어 등으로 구성 가능

It has basically three components: * A web app written in NodeJS (which can be thought of a microservice)

github.com 원문 ↗

데이터·에셋 배치 원칙근거 있음

쓰기용 마스터 저장소와 읽기용 복제본/읽기 모델을 분리 배치

A 'write' datastore (implemented using Redis master instance) * A 'read' datastore (implemented using Redis replica instances )

github.com 원문 ↗

대표 유스케이스근거 있음

고성능·확장성, 복잡한 도메인, 감사·규제 요구가 큰 시스템(예: 주식 거래 플랫폼)

CQRS is great for a stock trading platform where performance, scalability, and regulatory compliance are paramount.

www.confluent.io 원문 ↗

시나리오 예시근거 있음

사용자가 폼 제출 후 읽기 모델 지연으로 이전 데이터를 보고 재제출하는 시나리오

the command succeeds, the read model has not caught up, the user's next page load shows old data

hld.handbook.academy 원문 ↗

부적합 상황·주의근거 있음

은행 잔액·재고·안전 필수 제어처럼 쓰기 직후 동일 데이터가 즉시 보여야 하는 경우 부적합

banking balances, inventory counts at checkout, safety-critical controls- don't tolerate eventual consistency well.

gainhq.com 원문 ↗

온프레미스 관점(개발·배포·운영)근거 있음

컨테이너 기반 마이크로서비스를 온프레미스 Kubernetes에 배포 가능

You can take a containerized microservices-based application and deploy it into an on-premises Kubernetes cluster.

www.techtarget.com 원문 ↗

클라우드 관점(개발·배포·운영)근거 있음

컨테이너화 후 관리형 Kubernetes(예: OCI Kubernetes Engine)에 배포·테스트

After you containerize your microservices, you can deploy them to OCI Kubernetes Engine.

docs.oracle.com 원문 ↗

Kubernetes 관점(개발·배포·운영)근거 있음

Kubernetes에서 Node.js, Redis, Helm 등으로 CQRS 구성요소를 배포·운영

implementation of CQRS (Command Query Responsibility Segregation) architectural pattern on Kubernetes using NodeJS, Redis and Helm.

github.com 원문 ↗

장애 대응 관점근거 있음

읽기 모델이 쓰기 후 갱신되어 짧은 구간 쿼리가 최신 변경을 반영하지 못함

the read models are updated after the write, so for a short interval a query may not reflect a change

design.babushkai.com 원문 ↗

장점근거 있음

읽기/쓰기 모델 독립 최적화로 성능·확장성·보안 개선

This approach allows you to optimize each model independently and can improve the performance, scalability, and security of an application.

learn.microsoft.com 원문 ↗

단점·트레이드오프근거 있음

데이터스토어 간 최종 일관성과 읽기 지연을 유발

The CQRS pattern typically results in eventual consistency between the data stores.

docs.aws.amazon.com 원문 ↗

대표 기술·도구근거 있음

Kubernetes, Node.js, Redis, Helm 등

on Kubernetes using NodeJS, Redis and Helm.

github.com 원문 ↗

추가 참고 문헌 (21)