Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#62] feat : 선착순 쿠폰 발행 실패 -> 쿠폰 발행 배치 구현 #65

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

zzangoobrother
Copy link
Collaborator

작업 요약

  • 선착순 쿠폰 발행 실패 -> 쿠폰 발행 밸치 구현

작업 내용

선착순 쿠폰 발행 실패 -> 쿠폰 발행 배치로 쿠폰 발행
read 는 쿼리 조회를 zero offset 으로 조회 했고, write는 배치 insert를 사용 했습니다.

@zzangoobrother zzangoobrother self-assigned this Aug 6, 2023
private final EntityManagerFactory entityManagerFactory;
private final CouponBatchWriterRepository couponBatchWriterRepository;

private static final int chunkSize = 10;
Copy link
Collaborator

Choose a reason for hiding this comment

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

말씀 드렸지만, chunkSize는 파라미터로 받도록 하는게 운영할 때 유연해서 유용합니다.

String sql = "INSERT INTO coupon_issue (coupon_issue_token, member_id, coupon_id, used_yn, created_at, used_at) VALUES (UUID_TO_BIN(?), ?, ?, ?, ?, ?)";

jdbcTemplate.batchUpdate(sql,
new BatchPreparedStatementSetter() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@f-lab-thor
Copy link
Collaborator

f-lab-thor commented Aug 8, 2023

[생각해보기]

  • 배치 모니터링은 어떻게 해야 할까?
  • 배치 성공, 실패 알림을 어떻게 받으면 좋을까?
  • 로그는 어떻게 쌓는게 좋을까?
  • 운영툴로 만들면 좋을게 뭐가 있을까?

@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
CouponIssueFailedEntity entity = couponIssueFailedEntities.get(i);
ps.setObject(1, entity.getId());
Copy link
Collaborator

Choose a reason for hiding this comment

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

매직넘버 이네요.. 매직 넘버가 어떤 문제가 있을지 찾아보시면 좋을것 같습니다.

master:
jdbc-url: jdbc:mysql://118.67.135.217:32770/goodchoice
username: root
password: 1234
Copy link
Collaborator

Choose a reason for hiding this comment

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

실무에서는 이런 민감 정보는 key 관리 시스템에 위임 합니다.

}

@Test
void failedCouponJob() throws Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

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

저번처럼 해피케이스만 있네요? ㅎㅎ
말씀드렸지만 오히려 실패 했을때, 트랜잭션이 롤백되는지 확인하고
데이터 정합성 이슈가 없는지 동작 체킹하는게 더 중요합니다.

@f-lab-thor
Copy link
Collaborator

쿠폰 발행이 실패 된 케이스가 정상적으로 선착순이 안되서 실패 할 수도 있을텐데 그건 다시 배치로 발행하면 안되는거 잖아요?

정책으로 맞지 않을거 같은데 검토가 필요할것 같습니다.

@f-lab-thor
Copy link
Collaborator

스프링 배치 메트릭 수집 및 그라파나 대쉬보드 구성해보고
배치가 돌지 않을 때 슬랙으로 알림 발송까지 해보면
실무에서 모니터링 구축하는거랑 비슷하게 해보실수 있을거 같아요

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.

2 participants