Skip to content

Conversation

@opixxx
Copy link

@opixxx opixxx commented Jan 28, 2025

회원

  • 세션을 사용하여 인증을 구현했습니다.
  • 회원 가입 시 이벤트 발행을 통해 메인계좌가 생성하도록 했습니다.

계좌

  • 메인 계좌 충전
    • 사용자 당 메인 계좌가 하나이기 때문에 하나의 메인 계좌의 동시에 많은 충전 요청이 오지는 않을 것이라고 생각했습니다.
    • 메인 계좌 충전 비즈니스 로직에서 데이터를 반복해서 읽는 부분이 없기 때문에 Non-Repeatable Read 문제가 발생하지는 않을 것이라고 생각했습니다.
    • 그렇기 때문에 트랜잭션 격리 레벨을 Read Committed + 낙관적 락을 선택했습니다.
  • 메인 계좌에서 적금 계좌로 송금
    • 사용자 당 메인 계좌는 하나이고, 적금 계좌는 여러 개입니다.
    • 메인 계좌에서 적금 계좌로의 송금 또한 동시에 많은 송금 요청이 이루어지지는 않을 것이라고 생각했습니다.
    • 이 비즈니스 로직 마찬가지로 Non-Repeatable Read 문제가 발생하지는 않을 것이라고 생각했습니다.
    • 그렇기 때문에 Read Committed + 낙관적 락을 선택했습니다.
  • 충전 한도 관리
    • 메인 계좌 엔티티에서 컬럼으로 관리할 수 있도록 했습니다.
    • 0시 00분에 스케줄러를 사용해 chargeLimit가 3,000,000 미만인 메인 계좌를 조회해 한도를 다시 초기화 해주도록 했습니다.
    • 메인 계좌 데이터가 많다고 생각했을 때, 성능을 생각하여 JdbcTemplate를 사용해서 구현했다. 이 부분은 추후 성능 테스트를 해봐도 좋을 것 같다.

opixxx added 12 commits January 23, 2025 18:36
- 세션을 사용하여 회원가입, 로그인 구현
- ArgumentResolver 을 활용 하여 로그인 회원 정보 조회
- 인터셉터를 사용하여 사용자 인증 기능 구현
- 다른 패키지에서 빈을 인식을 못하는 버그가 인텔리제이 있어 패키지를 member 내부로 이동
- 회원 가입 시 EventListener 를 통해 메인 계좌 생성 이벤트를 발행
- session 에 accountId 메인 계좌 PK를 추가
   - 사용자와 메인 계좌는 1:1 관계라고 생각해서 같이 조회되는 경우가 많을 것이라고 생각되서 Member 에서 accountId 를 관리하도록 구현
- 회원 가입 시 EventListener 를 통해 메인 계좌 생성 이벤트를 발행
- session 에 accountId 메인 계좌 PK를 추가
   - 사용자와 메인 계좌는 1:1 관계라고 생각해서 같이 조회되는 경우가 많을 것이라고 생각되서 Member 에서 accountId 를 관리하도록 구현
- 스케줄러를 사용하여 00시 00분에 현재 충전 한도가 3,000,000 이하인 메인 계좌를 조회 후 3,000,000으로 초기화 하도록 구현함
- jdbcTemplate 를 사용해서 배치 쿼리를 작성함
- 송금 트랜잭션 격리 수준 Read Committed + 낙관적 락으로 구현
-
@opixxx opixxx self-assigned this Jan 28, 2025
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@sonarqubecloud
Copy link

Copy link

@ZZAMBAs ZZAMBAs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

잘 봤습니다! 낙관적 락 방식과 JPA 더티 체킹을 이용해서 DB에 락을 최소화하신 것 같고 이에 따라 동시성 성능이 좋을 것 같다는 생각입니다. 고생 많으셨어요!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이벤트 발행을 통한 처리는 신선했던 것 같아요

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

관련 클래스에 상수를 적지 않고 따로 상수 클래스에 상수를 모아두신 이유가 있을까요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여러 클래스에서 상수 값이 사용되는 경우가 빈번하다보니 하나의 상수 클래스에서 관리한 것 같습니다.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아주 꼼꼼히 작성하신 것 같아요. 여기에 추가적인 동시성 테스트도 있으면 좋을 것 같습니다. 예를 들면 메인 계좌에서 다른 계좌로 돈이 빠져나가는 상황이 동시에 발생하는 상황처럼요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

step2에서 송금에서의 동시성 테스트 작성해보겠습니다

Copy link
Contributor

@hellozo0 hellozo0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 전제는 메인 계좌에 접근하려고 하는 트랜잭션이 많을것이다(ex : 메인 => 적금 계좌로 돈을 충전할때, 여러계좌에서 메인계좌로 돈이 충전될때) 생각해서 그로인한 Non-Repeatable Read 를 방지하고자 Repeatable Read를 선택했는데, 실제 상황을 생각해보니 Read Commited+ 낙관적 락을 사용하는 방법도 부분적으로 필요하겠다는 생각이 드네요..!
Version2로 각각 구현해보고 나중에 테스트해보겠습니다..

코드의 흐름은 비슷해서 리뷰할 내용은 거의 없습니다!
세션을 통한 로그인 방법은 저도 추후에 공부해서 적용해보겠습니다 :) 너무 잘 구현해 두셔서 참고할께요!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 코드 작성하신 방법 참고해서 테스트 코드 작성해 보겠습니다..! Good... 👍

@opixxx opixxx merged commit 833bf7a into base/opixxx Feb 4, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants