SlideShare une entreprise Scribd logo
1  sur  43
CQRS 소개
Command Query Responsibility Segregation
명령 조회 책임 분리
ACID 세상 품의 포근함
Atomicity/ Consistency/ Isolation/ Durability
RDBMS
Domain ModelAwesome Front-End Techs
C
R
U
D
We have a
Hul…
ummmm…
ACID.
반응형 선언(Reactive Manifesto)
Command Query Responsibility Segregation
CQRS 여행 <
설계 원칙
CQRS
GUID
DDD와 CQRS
이벤트 소싱과 CQRS
사례 연구
내 얘기를
들어줘
REST
In 2000, Roy Fielding proposed Representational State Transfer (REST)
as an architectural approach to designing web services. REST is an
architectural style for building distributed systems based on
hypermedia.
If a POST method creates a new resource, it returns HTTP status code
201 (Created). The URI of the new resource is included in the Location
header of the response. The response body contains a representation
of the resource.
https://docs.microsoft.com/en-us/azure/architecture/best-practices/api-design
REST 증후군
[HttpPost]
public IActionResult PostComment(
[FromBody] AddCommentForm form,
[FromServices] CommentService service)
{
return Created(service.AddComment(form));
}
REST 증후군
public class Comment
{
public int Id { get; set; }
public int AuthorId { get; set; }
public string Content { get; set; }
}
public class User
{
public int Id { get; set; }
public string Username { get; set; }
public string PasswordHash { get; set; }
}
REST 증후군
public class CommentDto
{
public int Id { get; set; }
public UserDto Author { get; set; }
public string Content { get; set; }
}
public class UserDto
{
public int Id { get; set; }
public string Username { get; set; }
}
REST 증후군
public CommentDto AddComment(
AddCommentForm form,
DataAccess dao)
{
Validate(command);
Comment comment = CreateEntityWith(form);
dao.Insert(comment);
return AssembleCommentDto(comment, dao);
}
REST 증후군
[TestMethod]
public void AddComment_inserts_comment_entity_correctly()
{
// Arrange
SetupUser(…); // to make AssembleCommentDto method work
// Act
…
// Assert
…
}
Command Query Responsibility Segregation
CQRS 여행
설계 원칙 <
CQRS
GUID
DDD와 CQRS
이벤트 소싱과 CQRS
사례 연구
명령 조회 분리
• CQS(Command Query Separation)
• Bertrand Meyer
• 부작용이 없는 메서드만 값을 반환해야 한다.
단일 책임 원칙
• SRP(Single Responsibility Principle)
• Robert C. Martin
• 하나의 클래스는 하나의 변경 이유만 가져야 한다.
단일 책임 원칙
SRP 위배 SRP 준수
Calculator App
- Calculate
- Format
- Print
Calculator App
- Calculate
- Format
- Print
Command Query Responsibility Segregation
CQRS 여행
설계 원칙
CQRS <
GUID
DDD와 CQRS
이벤트 소싱과 CQRS
사례 연구
CQRS
• Command Query Responsibility Segregation
• Greg Young
• 명령과 조회는 각각 책임
• 𝑚 × 𝑛 → 𝑚 + 𝑛
CQRS is a very simple
pattern that enables
many opportunities for
architecture that may
otherwise not exist.
전형적인 아키텍처
Domain Model DatabaseView
CQRS
Command Model
Query Model
DatabaseView
CQRS
Command Model
Query Model
View
Command
Database
Query Database
Eventually
최종 일관성(Eventual Consistency)
• vs. 강한 일관성(Strong Consistency)
• 규모 확장
• 엔지니어링
• "Consistency is overrated."
Command Query Responsibility Segregation
CQRS 여행
설계 원칙
CQRS
GUID <
DDD와 CQRS
이벤트 소싱과 CQRS
사례 연구
CQRS와 REST
Command Executor
Read Model Façade
DatabaseREST
CQRS… 음…
[HttpPost]
public IActionResult PostComment(
[FromBody] AddCommentCommand command,
[FromServices] CommandExecutor commandExecutor,
[FromServices] ReadModelFacade readModelFacade)
{
commandExecutor.Execute(command);
return Created(readModelFacade.GetComment(commentId: ?));
}
GUID
[HttpPost]
public void IActionResult PostComment(
[FromBody] AddCommentCommand command,
[FromServices] CommandExecutor commandExecutor,
[FromServices] ReadModelFacade readModelFacade)
{
var commentId = Guid.NewGuid();
command.CommentId = commentId;
commandExecutor.Execute(command);
return Created(readModelFacade.GetComment(commentId));
}
GUID와 관계형 데이터베이스
• 4 bytes vs. 16 bytes
• "Disk space is cheap."
• "That’s not the point."
• Fragmentation
• GUID Primary Key + Clustered Index on Sequential Key
Command Query Responsibility Segregation
CQRS 여행
설계 원칙
CQRS
GUID
DDD와 CQRS <
이벤트 소싱과 CQRS
사례 연구
도메인 모델과 DTO(Data Transfer Object)
• 매핑은 고통
• 도메인 모델과 DTO는 각각 목적과 형태가 다름
도메인 주도 설계와 CQRS
명령 측(Command-Side) 책임
• 도메인 모델
• 구조
• 규칙
• 활동
• 불변식(Invariants)
• 무결성(Integrity)
• 정규화(Normalization)
조회 측(Query-Side) 책임
• 뷰 상태 모델
• 성능
• 활용
• 규모 확장
DDD와 CQRS 조합 사례
Date Date Date Date Date Date Date Date Date Date
Room Type
Room Type
Rate Plan
Rate Plan
Rate Plan
Channel
Channel
Channel
Channel
Key-Value Store
DDD와 CQRS 조합 사례
명령 모델 조회 모델
Aggregate Root
Aggregate Root
Entity
Value Object
Entity
Entity
Entity
Entity
Page Page Page Page
Page Page Page Page
Command Query Responsibility Segregation
CQRS 여행
설계 원칙
CQRS
GUID
DDD와 CQRS
이벤트 소싱과 CQRS <
사례 연구
이벤트 소싱(Event Sourcing)
• 도메인 모델에서 발생하는 모든 사건을 기록하는 기법
• 도메인 모델과 데이터 저장소 간 임피던스 불일치 존재 안함
• SSOT
• 감사 기록(Audit Log)
이벤트 소싱의 문제
• 다양한 조회 요구를 수용하기 어려움
이벤트 소싱과 CQRS
Command Executor
Event Store
RDB
No SQL
Read Model Façade
Presentation
Events
File System
Query Databases
이벤트 중심(Event-Driven) 아키텍처
Command Query Responsibility Segregation
CQRS 여행
설계 원칙
CQRS
GUID
DDD와 CQRS
이벤트 소싱과 CQRS
사례 연구 <
CQRS와 비동기 분산 명령 프로세스
UI
Read Model
Generator
Message BusAPI
Read Model
Database
Command
Processor
Event Store
Validate Command
Optimistically
Command
Command
Acceptance
Command Command
Raise Event
Update
Update View
Optimistically
1
2
4
5
3 6
7
8
전역 배치 비동기 분산 명령 프로세스
Command Forwarder
<< Service Bus >>
Message Broker
<< Event Hub >>
Processors
<< App Services >>
Event Store
<< Table Storage, SQL Database >>
Read Database
<< Cosmos DB >>
Read Database Replica
<< Cosmos DB >>
API
<< API App >>
UI(SPA)
<< Web App >>
Load Balancer
<< Traffic Manager >>
Satellite Region Hub Region
Validate Command
Optimistically
Replicate
Update Read Model
Command AcceptanceCommand
Update View Optimistically
1
2
3
4
5
6
7 8
9
10
11
물리적 구성
Command
Processor
Read
Model
Generator
Command
API
Query APIAPI Host
Processor Host
Command Side Query Side
CQRS
Deployment and Scaling
CQRS는 언제 사용하면 좋은가?
• 변화하는 도메인 모델
• 복잡한 논리
• 클라우드
• 높은 반응성
• 테스트 자동화

Contenu connexe

Similaire à CQRS

Cloud-Barista 제6차 오픈 컨퍼런스 : 멀티클라우드 애플리케이션 실행환경 통합 관리 (CB-Ladybug)
Cloud-Barista 제6차 오픈 컨퍼런스 : 멀티클라우드 애플리케이션 실행환경 통합 관리 (CB-Ladybug)Cloud-Barista 제6차 오픈 컨퍼런스 : 멀티클라우드 애플리케이션 실행환경 통합 관리 (CB-Ladybug)
Cloud-Barista 제6차 오픈 컨퍼런스 : 멀티클라우드 애플리케이션 실행환경 통합 관리 (CB-Ladybug)Cloud-Barista Community
 
Msrds game server
Msrds game serverMsrds game server
Msrds game serverperpet
 
AWS 12월 웨비나 │클라우드 마이그레이션을 통한 성공사례
AWS 12월 웨비나 │클라우드 마이그레이션을 통한 성공사례AWS 12월 웨비나 │클라우드 마이그레이션을 통한 성공사례
AWS 12월 웨비나 │클라우드 마이그레이션을 통한 성공사례Amazon Web Services Korea
 
[Partner TechShift 2017] AWS로 당신의 소프트웨어를 혁신하라
[Partner TechShift 2017] AWS로 당신의 소프트웨어를 혁신하라[Partner TechShift 2017] AWS로 당신의 소프트웨어를 혁신하라
[Partner TechShift 2017] AWS로 당신의 소프트웨어를 혁신하라Amazon Web Services Korea
 
신규 시장 개척과 클라우드 Offering을 위한 AWS 데이터베이스 서비스 이해 (최유정 데이터베이스 솔루션즈 아키텍트, AWS) :: ...
신규 시장 개척과 클라우드 Offering을 위한 AWS 데이터베이스 서비스 이해 (최유정 데이터베이스 솔루션즈 아키텍트, AWS) :: ...신규 시장 개척과 클라우드 Offering을 위한 AWS 데이터베이스 서비스 이해 (최유정 데이터베이스 솔루션즈 아키텍트, AWS) :: ...
신규 시장 개척과 클라우드 Offering을 위한 AWS 데이터베이스 서비스 이해 (최유정 데이터베이스 솔루션즈 아키텍트, AWS) :: ...Amazon Web Services Korea
 
[Partner TechShift 2017] APN 컨설팅 파트너사와 함께 하는 클라우드 소프트웨어 사업
[Partner TechShift 2017] APN 컨설팅 파트너사와 함께 하는 클라우드 소프트웨어 사업[Partner TechShift 2017] APN 컨설팅 파트너사와 함께 하는 클라우드 소프트웨어 사업
[Partner TechShift 2017] APN 컨설팅 파트너사와 함께 하는 클라우드 소프트웨어 사업Amazon Web Services Korea
 
Kgw2015 lg엔시스 안무정_최종본
Kgw2015 lg엔시스 안무정_최종본Kgw2015 lg엔시스 안무정_최종본
Kgw2015 lg엔시스 안무정_최종본무정 안
 
All about Data Center Migration Session 1. <Case Study> 오비맥주 사례로 알아보는 DC 마이그레...
All about Data Center Migration Session 1. <Case Study> 오비맥주 사례로 알아보는 DC 마이그레...All about Data Center Migration Session 1. <Case Study> 오비맥주 사례로 알아보는 DC 마이그레...
All about Data Center Migration Session 1. <Case Study> 오비맥주 사례로 알아보는 DC 마이그레...BESPIN GLOBAL
 
Cloud migration pattern using microservices
Cloud migration pattern using microservicesCloud migration pattern using microservices
Cloud migration pattern using microservicesSeong-Bok Lee
 
AWS기반 서버리스 데이터레이크 구축하기 - 김진웅 (SK C&C) :: AWS Community Day 2020
AWS기반 서버리스 데이터레이크 구축하기 - 김진웅 (SK C&C) :: AWS Community Day 2020AWS기반 서버리스 데이터레이크 구축하기 - 김진웅 (SK C&C) :: AWS Community Day 2020
AWS기반 서버리스 데이터레이크 구축하기 - 김진웅 (SK C&C) :: AWS Community Day 2020Jinwoong Kim
 
AWS기반 서버리스 데이터레이크 구축하기 - 김진웅 (SK C&C) :: AWS Community Day 2020
AWS기반 서버리스 데이터레이크 구축하기 - 김진웅 (SK C&C) :: AWS Community Day 2020 AWS기반 서버리스 데이터레이크 구축하기 - 김진웅 (SK C&C) :: AWS Community Day 2020
AWS기반 서버리스 데이터레이크 구축하기 - 김진웅 (SK C&C) :: AWS Community Day 2020 AWSKRUG - AWS한국사용자모임
 
Data Center to Cloud - AWS 마이그레이션 자동화 방법 및 도구 - AWS Summit Seoul 2017
Data Center to Cloud - AWS 마이그레이션 자동화 방법 및 도구 - AWS Summit Seoul 2017Data Center to Cloud - AWS 마이그레이션 자동화 방법 및 도구 - AWS Summit Seoul 2017
Data Center to Cloud - AWS 마이그레이션 자동화 방법 및 도구 - AWS Summit Seoul 2017Amazon Web Services Korea
 
Open standard open cloud engine for digital business process
Open standard open cloud engine for digital business process Open standard open cloud engine for digital business process
Open standard open cloud engine for digital business process uEngine Solutions
 
주니어 입장에서 바라보는 디자인패턴 & 아키텍쳐.pdf
주니어 입장에서 바라보는 디자인패턴 & 아키텍쳐.pdf주니어 입장에서 바라보는 디자인패턴 & 아키텍쳐.pdf
주니어 입장에서 바라보는 디자인패턴 & 아키텍쳐.pdf병근 손
 
AWS 클라우드로 천만명 웹 서비스 확장하기 - 윤석찬 백승현 - AWS Summit 2016
AWS 클라우드로 천만명 웹 서비스 확장하기 - 윤석찬 백승현 - AWS Summit 2016AWS 클라우드로 천만명 웹 서비스 확장하기 - 윤석찬 백승현 - AWS Summit 2016
AWS 클라우드로 천만명 웹 서비스 확장하기 - 윤석찬 백승현 - AWS Summit 2016Amazon Web Services Korea
 
누가 내 엔터프라이즈 고객을 클라우드로 옮겼을까?-양승호, Head of Cloud Modernization,AWS::AWS 마이그레이션 ...
누가 내 엔터프라이즈 고객을 클라우드로 옮겼을까?-양승호, Head of Cloud Modernization,AWS::AWS 마이그레이션 ...누가 내 엔터프라이즈 고객을 클라우드로 옮겼을까?-양승호, Head of Cloud Modernization,AWS::AWS 마이그레이션 ...
누가 내 엔터프라이즈 고객을 클라우드로 옮겼을까?-양승호, Head of Cloud Modernization,AWS::AWS 마이그레이션 ...Amazon Web Services Korea
 
Amazon EKS를 위한 AWS CDK와 CDK8s 활용법 - 염지원, 김광영 AWS 솔루션즈 아키텍트 :: AWS Summit Seou...
Amazon EKS를 위한 AWS CDK와 CDK8s 활용법 - 염지원, 김광영 AWS 솔루션즈 아키텍트 :: AWS Summit Seou...Amazon EKS를 위한 AWS CDK와 CDK8s 활용법 - 염지원, 김광영 AWS 솔루션즈 아키텍트 :: AWS Summit Seou...
Amazon EKS를 위한 AWS CDK와 CDK8s 활용법 - 염지원, 김광영 AWS 솔루션즈 아키텍트 :: AWS Summit Seou...Amazon Web Services Korea
 
[OpenInfra Days Korea 2018] (Track 2) Microservice Architecture, DevOps 그리고 5...
[OpenInfra Days Korea 2018] (Track 2) Microservice Architecture, DevOps 그리고 5...[OpenInfra Days Korea 2018] (Track 2) Microservice Architecture, DevOps 그리고 5...
[OpenInfra Days Korea 2018] (Track 2) Microservice Architecture, DevOps 그리고 5...OpenStack Korea Community
 
Code igniter 20160119
Code igniter 20160119Code igniter 20160119
Code igniter 20160119ko donghwi
 
Event storming based msa training commerce example add_handson_v3
Event storming based msa training commerce example add_handson_v3Event storming based msa training commerce example add_handson_v3
Event storming based msa training commerce example add_handson_v3uEngine Solutions
 

Similaire à CQRS (20)

Cloud-Barista 제6차 오픈 컨퍼런스 : 멀티클라우드 애플리케이션 실행환경 통합 관리 (CB-Ladybug)
Cloud-Barista 제6차 오픈 컨퍼런스 : 멀티클라우드 애플리케이션 실행환경 통합 관리 (CB-Ladybug)Cloud-Barista 제6차 오픈 컨퍼런스 : 멀티클라우드 애플리케이션 실행환경 통합 관리 (CB-Ladybug)
Cloud-Barista 제6차 오픈 컨퍼런스 : 멀티클라우드 애플리케이션 실행환경 통합 관리 (CB-Ladybug)
 
Msrds game server
Msrds game serverMsrds game server
Msrds game server
 
AWS 12월 웨비나 │클라우드 마이그레이션을 통한 성공사례
AWS 12월 웨비나 │클라우드 마이그레이션을 통한 성공사례AWS 12월 웨비나 │클라우드 마이그레이션을 통한 성공사례
AWS 12월 웨비나 │클라우드 마이그레이션을 통한 성공사례
 
[Partner TechShift 2017] AWS로 당신의 소프트웨어를 혁신하라
[Partner TechShift 2017] AWS로 당신의 소프트웨어를 혁신하라[Partner TechShift 2017] AWS로 당신의 소프트웨어를 혁신하라
[Partner TechShift 2017] AWS로 당신의 소프트웨어를 혁신하라
 
신규 시장 개척과 클라우드 Offering을 위한 AWS 데이터베이스 서비스 이해 (최유정 데이터베이스 솔루션즈 아키텍트, AWS) :: ...
신규 시장 개척과 클라우드 Offering을 위한 AWS 데이터베이스 서비스 이해 (최유정 데이터베이스 솔루션즈 아키텍트, AWS) :: ...신규 시장 개척과 클라우드 Offering을 위한 AWS 데이터베이스 서비스 이해 (최유정 데이터베이스 솔루션즈 아키텍트, AWS) :: ...
신규 시장 개척과 클라우드 Offering을 위한 AWS 데이터베이스 서비스 이해 (최유정 데이터베이스 솔루션즈 아키텍트, AWS) :: ...
 
[Partner TechShift 2017] APN 컨설팅 파트너사와 함께 하는 클라우드 소프트웨어 사업
[Partner TechShift 2017] APN 컨설팅 파트너사와 함께 하는 클라우드 소프트웨어 사업[Partner TechShift 2017] APN 컨설팅 파트너사와 함께 하는 클라우드 소프트웨어 사업
[Partner TechShift 2017] APN 컨설팅 파트너사와 함께 하는 클라우드 소프트웨어 사업
 
Kgw2015 lg엔시스 안무정_최종본
Kgw2015 lg엔시스 안무정_최종본Kgw2015 lg엔시스 안무정_최종본
Kgw2015 lg엔시스 안무정_최종본
 
All about Data Center Migration Session 1. <Case Study> 오비맥주 사례로 알아보는 DC 마이그레...
All about Data Center Migration Session 1. <Case Study> 오비맥주 사례로 알아보는 DC 마이그레...All about Data Center Migration Session 1. <Case Study> 오비맥주 사례로 알아보는 DC 마이그레...
All about Data Center Migration Session 1. <Case Study> 오비맥주 사례로 알아보는 DC 마이그레...
 
Cloud migration pattern using microservices
Cloud migration pattern using microservicesCloud migration pattern using microservices
Cloud migration pattern using microservices
 
AWS기반 서버리스 데이터레이크 구축하기 - 김진웅 (SK C&C) :: AWS Community Day 2020
AWS기반 서버리스 데이터레이크 구축하기 - 김진웅 (SK C&C) :: AWS Community Day 2020AWS기반 서버리스 데이터레이크 구축하기 - 김진웅 (SK C&C) :: AWS Community Day 2020
AWS기반 서버리스 데이터레이크 구축하기 - 김진웅 (SK C&C) :: AWS Community Day 2020
 
AWS기반 서버리스 데이터레이크 구축하기 - 김진웅 (SK C&C) :: AWS Community Day 2020
AWS기반 서버리스 데이터레이크 구축하기 - 김진웅 (SK C&C) :: AWS Community Day 2020 AWS기반 서버리스 데이터레이크 구축하기 - 김진웅 (SK C&C) :: AWS Community Day 2020
AWS기반 서버리스 데이터레이크 구축하기 - 김진웅 (SK C&C) :: AWS Community Day 2020
 
Data Center to Cloud - AWS 마이그레이션 자동화 방법 및 도구 - AWS Summit Seoul 2017
Data Center to Cloud - AWS 마이그레이션 자동화 방법 및 도구 - AWS Summit Seoul 2017Data Center to Cloud - AWS 마이그레이션 자동화 방법 및 도구 - AWS Summit Seoul 2017
Data Center to Cloud - AWS 마이그레이션 자동화 방법 및 도구 - AWS Summit Seoul 2017
 
Open standard open cloud engine for digital business process
Open standard open cloud engine for digital business process Open standard open cloud engine for digital business process
Open standard open cloud engine for digital business process
 
주니어 입장에서 바라보는 디자인패턴 & 아키텍쳐.pdf
주니어 입장에서 바라보는 디자인패턴 & 아키텍쳐.pdf주니어 입장에서 바라보는 디자인패턴 & 아키텍쳐.pdf
주니어 입장에서 바라보는 디자인패턴 & 아키텍쳐.pdf
 
AWS 클라우드로 천만명 웹 서비스 확장하기 - 윤석찬 백승현 - AWS Summit 2016
AWS 클라우드로 천만명 웹 서비스 확장하기 - 윤석찬 백승현 - AWS Summit 2016AWS 클라우드로 천만명 웹 서비스 확장하기 - 윤석찬 백승현 - AWS Summit 2016
AWS 클라우드로 천만명 웹 서비스 확장하기 - 윤석찬 백승현 - AWS Summit 2016
 
누가 내 엔터프라이즈 고객을 클라우드로 옮겼을까?-양승호, Head of Cloud Modernization,AWS::AWS 마이그레이션 ...
누가 내 엔터프라이즈 고객을 클라우드로 옮겼을까?-양승호, Head of Cloud Modernization,AWS::AWS 마이그레이션 ...누가 내 엔터프라이즈 고객을 클라우드로 옮겼을까?-양승호, Head of Cloud Modernization,AWS::AWS 마이그레이션 ...
누가 내 엔터프라이즈 고객을 클라우드로 옮겼을까?-양승호, Head of Cloud Modernization,AWS::AWS 마이그레이션 ...
 
Amazon EKS를 위한 AWS CDK와 CDK8s 활용법 - 염지원, 김광영 AWS 솔루션즈 아키텍트 :: AWS Summit Seou...
Amazon EKS를 위한 AWS CDK와 CDK8s 활용법 - 염지원, 김광영 AWS 솔루션즈 아키텍트 :: AWS Summit Seou...Amazon EKS를 위한 AWS CDK와 CDK8s 활용법 - 염지원, 김광영 AWS 솔루션즈 아키텍트 :: AWS Summit Seou...
Amazon EKS를 위한 AWS CDK와 CDK8s 활용법 - 염지원, 김광영 AWS 솔루션즈 아키텍트 :: AWS Summit Seou...
 
[OpenInfra Days Korea 2018] (Track 2) Microservice Architecture, DevOps 그리고 5...
[OpenInfra Days Korea 2018] (Track 2) Microservice Architecture, DevOps 그리고 5...[OpenInfra Days Korea 2018] (Track 2) Microservice Architecture, DevOps 그리고 5...
[OpenInfra Days Korea 2018] (Track 2) Microservice Architecture, DevOps 그리고 5...
 
Code igniter 20160119
Code igniter 20160119Code igniter 20160119
Code igniter 20160119
 
Event storming based msa training commerce example add_handson_v3
Event storming based msa training commerce example add_handson_v3Event storming based msa training commerce example add_handson_v3
Event storming based msa training commerce example add_handson_v3
 

Plus de Gyuwon Yi

Event sourcing spring camp 2017.public
Event sourcing spring camp 2017.publicEvent sourcing spring camp 2017.public
Event sourcing spring camp 2017.publicGyuwon Yi
 
Why you always fail with tdd
Why you always fail with tddWhy you always fail with tdd
Why you always fail with tddGyuwon Yi
 
CQRS - Show me the code
CQRS - Show me the codeCQRS - Show me the code
CQRS - Show me the codeGyuwon Yi
 
프로그래밍, 설계 그리고 패턴
프로그래밍, 설계 그리고 패턴프로그래밍, 설계 그리고 패턴
프로그래밍, 설계 그리고 패턴Gyuwon Yi
 
VSTS와 Azure를 이용한 팀 프로세스 관리
VSTS와 Azure를 이용한 팀 프로세스 관리VSTS와 Azure를 이용한 팀 프로세스 관리
VSTS와 Azure를 이용한 팀 프로세스 관리Gyuwon Yi
 
Unit testing
Unit testingUnit testing
Unit testingGyuwon Yi
 
Xamarin Forms, MVVM and Testing
Xamarin Forms, MVVM and TestingXamarin Forms, MVVM and Testing
Xamarin Forms, MVVM and TestingGyuwon Yi
 
Reactive Model-View-ViewModel Architecture
Reactive Model-View-ViewModel ArchitectureReactive Model-View-ViewModel Architecture
Reactive Model-View-ViewModel ArchitectureGyuwon Yi
 
Introduction to IoC Container
Introduction to IoC ContainerIntroduction to IoC Container
Introduction to IoC ContainerGyuwon Yi
 
Introduction to TPL
Introduction to TPLIntroduction to TPL
Introduction to TPLGyuwon Yi
 

Plus de Gyuwon Yi (10)

Event sourcing spring camp 2017.public
Event sourcing spring camp 2017.publicEvent sourcing spring camp 2017.public
Event sourcing spring camp 2017.public
 
Why you always fail with tdd
Why you always fail with tddWhy you always fail with tdd
Why you always fail with tdd
 
CQRS - Show me the code
CQRS - Show me the codeCQRS - Show me the code
CQRS - Show me the code
 
프로그래밍, 설계 그리고 패턴
프로그래밍, 설계 그리고 패턴프로그래밍, 설계 그리고 패턴
프로그래밍, 설계 그리고 패턴
 
VSTS와 Azure를 이용한 팀 프로세스 관리
VSTS와 Azure를 이용한 팀 프로세스 관리VSTS와 Azure를 이용한 팀 프로세스 관리
VSTS와 Azure를 이용한 팀 프로세스 관리
 
Unit testing
Unit testingUnit testing
Unit testing
 
Xamarin Forms, MVVM and Testing
Xamarin Forms, MVVM and TestingXamarin Forms, MVVM and Testing
Xamarin Forms, MVVM and Testing
 
Reactive Model-View-ViewModel Architecture
Reactive Model-View-ViewModel ArchitectureReactive Model-View-ViewModel Architecture
Reactive Model-View-ViewModel Architecture
 
Introduction to IoC Container
Introduction to IoC ContainerIntroduction to IoC Container
Introduction to IoC Container
 
Introduction to TPL
Introduction to TPLIntroduction to TPL
Introduction to TPL
 

CQRS

  • 1. CQRS 소개 Command Query Responsibility Segregation 명령 조회 책임 분리
  • 2. ACID 세상 품의 포근함 Atomicity/ Consistency/ Isolation/ Durability RDBMS Domain ModelAwesome Front-End Techs C R U D We have a Hul… ummmm… ACID.
  • 4. Command Query Responsibility Segregation CQRS 여행 < 설계 원칙 CQRS GUID DDD와 CQRS 이벤트 소싱과 CQRS 사례 연구
  • 6. REST In 2000, Roy Fielding proposed Representational State Transfer (REST) as an architectural approach to designing web services. REST is an architectural style for building distributed systems based on hypermedia. If a POST method creates a new resource, it returns HTTP status code 201 (Created). The URI of the new resource is included in the Location header of the response. The response body contains a representation of the resource. https://docs.microsoft.com/en-us/azure/architecture/best-practices/api-design
  • 7.
  • 8. REST 증후군 [HttpPost] public IActionResult PostComment( [FromBody] AddCommentForm form, [FromServices] CommentService service) { return Created(service.AddComment(form)); }
  • 9. REST 증후군 public class Comment { public int Id { get; set; } public int AuthorId { get; set; } public string Content { get; set; } } public class User { public int Id { get; set; } public string Username { get; set; } public string PasswordHash { get; set; } }
  • 10. REST 증후군 public class CommentDto { public int Id { get; set; } public UserDto Author { get; set; } public string Content { get; set; } } public class UserDto { public int Id { get; set; } public string Username { get; set; } }
  • 11. REST 증후군 public CommentDto AddComment( AddCommentForm form, DataAccess dao) { Validate(command); Comment comment = CreateEntityWith(form); dao.Insert(comment); return AssembleCommentDto(comment, dao); }
  • 12. REST 증후군 [TestMethod] public void AddComment_inserts_comment_entity_correctly() { // Arrange SetupUser(…); // to make AssembleCommentDto method work // Act … // Assert … }
  • 13.
  • 14. Command Query Responsibility Segregation CQRS 여행 설계 원칙 < CQRS GUID DDD와 CQRS 이벤트 소싱과 CQRS 사례 연구
  • 15. 명령 조회 분리 • CQS(Command Query Separation) • Bertrand Meyer • 부작용이 없는 메서드만 값을 반환해야 한다.
  • 16. 단일 책임 원칙 • SRP(Single Responsibility Principle) • Robert C. Martin • 하나의 클래스는 하나의 변경 이유만 가져야 한다.
  • 17. 단일 책임 원칙 SRP 위배 SRP 준수 Calculator App - Calculate - Format - Print Calculator App - Calculate - Format - Print
  • 18. Command Query Responsibility Segregation CQRS 여행 설계 원칙 CQRS < GUID DDD와 CQRS 이벤트 소싱과 CQRS 사례 연구
  • 19. CQRS • Command Query Responsibility Segregation • Greg Young • 명령과 조회는 각각 책임 • 𝑚 × 𝑛 → 𝑚 + 𝑛 CQRS is a very simple pattern that enables many opportunities for architecture that may otherwise not exist.
  • 23. 최종 일관성(Eventual Consistency) • vs. 강한 일관성(Strong Consistency) • 규모 확장 • 엔지니어링 • "Consistency is overrated."
  • 24. Command Query Responsibility Segregation CQRS 여행 설계 원칙 CQRS GUID < DDD와 CQRS 이벤트 소싱과 CQRS 사례 연구
  • 25. CQRS와 REST Command Executor Read Model Façade DatabaseREST
  • 26. CQRS… 음… [HttpPost] public IActionResult PostComment( [FromBody] AddCommentCommand command, [FromServices] CommandExecutor commandExecutor, [FromServices] ReadModelFacade readModelFacade) { commandExecutor.Execute(command); return Created(readModelFacade.GetComment(commentId: ?)); }
  • 27. GUID [HttpPost] public void IActionResult PostComment( [FromBody] AddCommentCommand command, [FromServices] CommandExecutor commandExecutor, [FromServices] ReadModelFacade readModelFacade) { var commentId = Guid.NewGuid(); command.CommentId = commentId; commandExecutor.Execute(command); return Created(readModelFacade.GetComment(commentId)); }
  • 28. GUID와 관계형 데이터베이스 • 4 bytes vs. 16 bytes • "Disk space is cheap." • "That’s not the point." • Fragmentation • GUID Primary Key + Clustered Index on Sequential Key
  • 29. Command Query Responsibility Segregation CQRS 여행 설계 원칙 CQRS GUID DDD와 CQRS < 이벤트 소싱과 CQRS 사례 연구
  • 30. 도메인 모델과 DTO(Data Transfer Object) • 매핑은 고통 • 도메인 모델과 DTO는 각각 목적과 형태가 다름
  • 31. 도메인 주도 설계와 CQRS 명령 측(Command-Side) 책임 • 도메인 모델 • 구조 • 규칙 • 활동 • 불변식(Invariants) • 무결성(Integrity) • 정규화(Normalization) 조회 측(Query-Side) 책임 • 뷰 상태 모델 • 성능 • 활용 • 규모 확장
  • 32. DDD와 CQRS 조합 사례 Date Date Date Date Date Date Date Date Date Date Room Type Room Type Rate Plan Rate Plan Rate Plan Channel Channel Channel Channel
  • 33. Key-Value Store DDD와 CQRS 조합 사례 명령 모델 조회 모델 Aggregate Root Aggregate Root Entity Value Object Entity Entity Entity Entity Page Page Page Page Page Page Page Page
  • 34. Command Query Responsibility Segregation CQRS 여행 설계 원칙 CQRS GUID DDD와 CQRS 이벤트 소싱과 CQRS < 사례 연구
  • 35. 이벤트 소싱(Event Sourcing) • 도메인 모델에서 발생하는 모든 사건을 기록하는 기법 • 도메인 모델과 데이터 저장소 간 임피던스 불일치 존재 안함 • SSOT • 감사 기록(Audit Log)
  • 36. 이벤트 소싱의 문제 • 다양한 조회 요구를 수용하기 어려움
  • 37. 이벤트 소싱과 CQRS Command Executor Event Store RDB No SQL Read Model Façade Presentation Events File System Query Databases
  • 39. Command Query Responsibility Segregation CQRS 여행 설계 원칙 CQRS GUID DDD와 CQRS 이벤트 소싱과 CQRS 사례 연구 <
  • 40. CQRS와 비동기 분산 명령 프로세스 UI Read Model Generator Message BusAPI Read Model Database Command Processor Event Store Validate Command Optimistically Command Command Acceptance Command Command Raise Event Update Update View Optimistically 1 2 4 5 3 6 7 8
  • 41. 전역 배치 비동기 분산 명령 프로세스 Command Forwarder << Service Bus >> Message Broker << Event Hub >> Processors << App Services >> Event Store << Table Storage, SQL Database >> Read Database << Cosmos DB >> Read Database Replica << Cosmos DB >> API << API App >> UI(SPA) << Web App >> Load Balancer << Traffic Manager >> Satellite Region Hub Region Validate Command Optimistically Replicate Update Read Model Command AcceptanceCommand Update View Optimistically 1 2 3 4 5 6 7 8 9 10 11
  • 42. 물리적 구성 Command Processor Read Model Generator Command API Query APIAPI Host Processor Host Command Side Query Side CQRS Deployment and Scaling
  • 43. CQRS는 언제 사용하면 좋은가? • 변화하는 도메인 모델 • 복잡한 논리 • 클라우드 • 높은 반응성 • 테스트 자동화

Notes de l'éditeur

  1. https://en.wikipedia.org/wiki/ACID_(computer_science)
  2. https://www.reactivemanifesto.org/
  3. 질문은 대답을 변경하지 않아야 한다. 항상 CQS가 가능한 것은 아니다. Pop(), MoveNext(), …
  4. https://en.wikipedia.org/wiki/Single_responsibility_principle
  5. https://docs.microsoft.com/en-us/azure/architecture/patterns/cqrs CQRS Journey https://docs.microsoft.com/en-us/previous-versions/msp-n-p/jj554200(v=pandp.10)
  6. Cosmos DB 일관성 수준 소개
  7. https://docs.microsoft.com/en-us/azure/architecture/patterns/event-sourcing
  8. https://martinfowler.com/articles/201701-event-driven.html https://www.youtube.com/watch?v=STKCRSUsyP0
  9. Type I Error vs. Type II Error
  10. CQRS가 유용한 도메인 소개