kongkong.note

[도메인 주도 개발 시작하기] 11. CQRS 본문

DDD

[도메인 주도 개발 시작하기] 11. CQRS

hyokong 2026. 1. 18. 19:27

CQRS (Command Query Responsibility Segregation)

  • 쓰기(Command)와 읽기(Query)를 모델·책임·경로까지 분리하는 것
  • 보통 조회할 때는 2개 이상의 aggregate 가 필요하기 때문
  • 실무 사용 예시 : 조회는 QueryDSL / MyBatis, 쓰기는 JPA
// Command
public void approveTuition(Long id) {
    TuitionApplication app = repo.findById(id);
    app.approve();
}

// Query
public TuitionDetailDto getTuition(Long id) {
    return queryRepository.findDetail(id);
}