Skip to content

S3, Redis 재요청 제한 처리 재작업#123

Open
yeomin4242 wants to merge 47 commits into
devfrom
be/dev/fix-attachment-duplicated-request#122
Open

S3, Redis 재요청 제한 처리 재작업#123
yeomin4242 wants to merge 47 commits into
devfrom
be/dev/fix-attachment-duplicated-request#122

Conversation

@yeomin4242

@yeomin4242 yeomin4242 commented Apr 1, 2026

Copy link
Copy Markdown
Member

#️⃣연관된 이슈

ex) #이슈번호, #이슈번호

#122

📝작업 내용

이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능)

이전에 작업한 내용 #111에서 더 나아가 S3, Redis 중복 요청을 더 줄이고자했습니다.

BE에 멱등키 기반 요청 제어를 도입하고, Redis 상태 저장 + Redisson 분산락 최적화, 를 적용했습니다.
또한 첨부파일 업로드에 deterministic S3 key 전략을 적용해 동일 요청 재시도 시 중복 업로드가 발생하지 않도록 개선했습니다.

주요 변경 사항

  • Board, Study, Project 생성/수정/종료 API에서 X-Idempotency-Key를 받을 수 있도록 컨트롤러를 확장했습니다.
  • 도메인별 Facade에서 payload hash를 계산하고 IdempotencyExecutor를 통해 공통 멱등 처리 흐름을 적용했습니다.
  • Redis에 요청 상태를 PROCESSING, COMPLETED, FAILED_RETRYABLE로 저장하도록 구성했습니다.
  • 동일 idempotencyKey + payload 요청은 기존 결과를 재사용하고, 동일 키에 다른 payload가 들어오면 mismatch 예외로 처리하도록 했습니다.
  • Redisson 분산락을 사용해 멀티 인스턴스 환경에서도 동일 요청의 동시 실행을 제어하도록 했습니다.
  • 완료/처리 중 요청은 락 획득 전에 Redis record만 확인하고 바로 반환하는 fast-path를 추가했습니다.
  • 첨부파일 업로드에는 idempotent-v1/{memberId}/{idempotencyKey}/{fileHash} 형태의 deterministic S3 key를 적용했습니다.
  • 동일 key 재시도 시 S3 HEAD/PUT 중복 호출을 줄이기 위해 local cache + in-flight collapse를 적용했습니다.

전/후 비교

1. 멱등키 + 분산락 적용 효과

항목 개선 전 개선 후 변화
동일 요청당 실제 업로드 실행 횟수 1000회 1회 -99.9%
중복 요청 차단율 0.00% 100.00% +100.00%p
중복 파일 생성 건수 999건 0건 제거

2. Redis 제어 경로 최적화

항목 1차 적용 후 2차 최적화 후 변화
요청 1건당 Redis 연산 수 2.096 1.021 -51.3%

3. S3 deterministic 업로드 최적화

항목 개선 전 개선 후 변화
HEAD 호출 수 1000회 1회 -99.9%
PUT 호출 수 397회 1회 -99.7%
요청 1건당 S3 연산 수 1.397 0.002 -99.86%

스크린샷 (선택)

💬리뷰 요구사항(선택)

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요
ex) 메서드 XXX의 이름을 더 잘 짓고 싶은데 혹시 좋은 명칭이 있을까요?

…benchmark mode handling in StudyDomainService and StudyParticipantDomainService #118
…sitory and fetching creator ID in StudyQueryRepository #118
…refactor-scheduler-logic-for-saving-request-data#119
…date BoardControllerTest for role-based access control
@yeomin4242 yeomin4242 requested a review from minwoonggi April 1, 2026 01:07

@minwoonggi minwoonggi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

진짜 보고 공부한 기분이긴 합니다
멱등처리에 있어서 분산락도 fast-path도 이해 잘되게 쓰셔서 보기 편하고 좋았습니다.
LGTM~

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