Repository navigation
Seminar/#7 - #11
Open
kaswhy wants to merge 18 commits into
Open
Seminar/#7#11kaswhy wants to merge 18 commits into
kaswhy wants to merge 18 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔥Pull requests
👷 과제 구현
필수과제
구현한 내용에 대해서 설명해주세요
구현하며 고민했던 내용을 적어주세요 (사소한 것도 좋아요)
트랜잭션 설계 관련 고민 및 결정 사항
1.
@Transactional적용 위치에 대한 고민 (클래스 단위 vs 메서드 단위)유스케이스 분리 구조에서
@Transactional을 클래스 단위로 적용할지, 메서드 단위로 적용할지를 고민했습니다.트랜잭션은 트랜잭션 경계에 적용하는 것이 원칙이며, 현재 프로젝트에서는 하나의 유스케이스 클래스가 하나의 비즈니스 흐름을 담당하고 있습니다.
즉, 유스케이스 자체가 트랜잭션 경계 역할을 하고 있다고 판단했습니다.
메서드 단위로 트랜잭션을 적용할 경우, 동일한 유스케이스 내에서 트랜잭션 경계가 분산되어 오히려 흐름을 파악하기 어려워질 수 있다고 보았습니다.
이에 따라 다음과 같은 기준으로 판단했습니다.
이 기준에 따라, 기본 정책으로 클래스 단위에
@Transactional을 적용하고,필요한 경우에만 메서드 단위로 분리하기로 결정했습니다.
2.
readOnly = true사용 여부에 대한 고민조회 유스케이스에서
readOnly = true를 명시적으로 사용하는 것이 의미가 있는지 고민했습니다.JPA 기준으로
readOnly = true설정 시 다음 동작이 생략됩니다.엔티티 개수가 많아질수록 이 비용은 무시하기 어렵고,
특히 목록 조회나 대량 조회 API에서는 불필요한 오버헤드가 된다고 판단했습니다.
따라서 다음 기준으로 사용 여부를 결정했습니다.
위 조건에 해당하는 경우
readOnly = true를 명시적으로 적용하기로 했습니다.3. 조회 시 트랜잭션 적용 여부에 대한 고민
조회 로직에도 항상 트랜잭션을 적용해야 하는지에 대해 고민했습니다.
트랜잭션을 사용하는 이유는 다음 세 가지로 정리할 수 있습니다.
조회 로직에서는 주로 2번과 3번이 쟁점이 됩니다.
DTO Projection 기반 조회의 경우 다음과 같은 특성이 있습니다.
이로 인해 DTO Projection 기반 조회에는 트랜잭션을 적용할 필요가 없다고 판단했습니다.
반면, 다음과 같은 경우에는 조회라도 트랜잭션이 필요하다고 보았습니다.
이를 기준으로 조회 로직의 트랜잭션 적용 여부를 구분했습니다.
4.
jakarta.transaction.Transactionalvs Spring@Transactional선택에 대한 고민트랜잭션 어노테이션으로
jakarta.transaction.Transactional과org.springframework.transaction.annotation.Transactional중 어떤 것을 사용할지 고민했습니다.본 프로젝트는 Spring 트랜잭션 AOP 기반으로 동작하며, 다음과 같은 설정이 필요합니다.
이러한 요구사항을 고려했을 때, Spring에서 제공하는
org.springframework.transaction.annotation.Transactional이 더 적합하다고 판단했습니다.이에 따라 본 프로젝트에서는 Spring 트랜잭션 어노테이션을 사용하기로 결정했습니다.
🚨 참고 사항