[Refactor] 비동기 안정화#480
Hidden character warning
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can enable review details to help with troubleshooting, context usage and more.Enable the |
Issue Number
#466
안녕하세요!
급한대로 짜두었던 코드를 좀 더 정돈해서 문서화까지 완료되어 PR 올립니다🥹
rate limit 관련 문서 정리: https://mint-scissor-943.notion.site/rate-limit-3220c7355c2a802d8abaf2b9cbaa1405?source=copy_link
As-Is
클라이언트에서의 예기치 못한 무한루프 등, 짧은 시간에 동일한 API 요청이 수십회 반복될 경우 사용자에게 적절한 피드백을 하고 상황을 종료 시켜 서버 부담을 줄입니다. 빠른 대응을 위해 에러 모니터링을 구축합니다.
To-Be
설계 요약
목적
파일별 역할
apis/rateLimit/slidingWindow.tspruneOutsideWindow: 윈도우 밖 타임스탬프 제거.isWithinLimit: 윈도우 내 개수로 허용 여부 판단.appendTimestamp: 윈도우 밖 제거 후 타임스탬프 추가 (불변).apis/rateLimit/rateLimiter.tsRATE_LIMIT_WINDOW_MS,RATE_LIMIT_MAX_COUNT,RATE_LIMIT_ENABLED_BY_METHOD,SKIP_LIST.Map<key, number[]>— 키별 타임스탬프 배열 (key =method\nendPoint).tryAcquire(method, endPoint, options?, now?)— 적용 대상이면 체크 후 기록, 초과 시false반환.getSnapshotForReporting(method, endPoint)— 해당 키의 타임스탬프 배열 복사본 반환 (Sentry용).apis/apiClient.tsrequestApi진입 시rateLimiter.tryAcquire(method, endPoint, options)호출.getSnapshotForReporting→monitor.reportClientRateLimitError→window.location.replace(TOO_MANY_REQUESTS)→ pending Promise 반환 (fetch 미실행).monitor.reportServerTooManyRequest호출 후 기존대로ApiErrorthrow.shared/utils/monitor.ts(monitor)reportClientRateLimitError(method, endPoint, timestamps): 태그rate_limit_source: client, Extra에 page, api_method, api_endpoint, rate_limit_timestamps, rate_limit_request_count.reportServerTooManyRequest(method, endPoint, serverMessage?): 태그rate_limit_source: server, Extra에 page, api_method, api_endpoint, (선택) server_message.window.location으로 현재 페이지 계산, Sentry에만 의존.흐름 요약
apiClient→rateLimiter.tryAcquire(slidingWindow 로직 사용).window.location.replace→ 요청 중단.에러 페이지
ROUTE_PATH.TOO_MANY_REQUESTS(/error/too-many-requests).window.location.replace로 진입하므로 SPA 상태 초기화.Check List
(Optional) Additional Description
현재 의사 결정을 논의할 부분을 정리하면,
입니다!
각 이유는 문서에 정리해두었어요!
코드에 있는 설명 주석은 PR 피드백 완료되면 제거한 후 머지하겠습니다!
감사합니다 ㅎㅎ