Skip to content

Conversation

@hyerinhwang-sailin
Copy link
Collaborator

@hyerinhwang-sailin hyerinhwang-sailin commented Sep 11, 2025

Related issue 🛠

Work Description ✏️

플랫폼(auth) 조회 전에 후보 ID를 (size×5, 최대 50개)로 미리 샘플링하여 넘기도록 변경했습니다. 또한 RandomPicker를 ThreadLocalRandom 기반으로 교체했습니다. 그 결과 URI 길이가 항상 짧게 유지되어 414가 재발하지 않습니다.

배경 / 문제상황

  • 운영 중 아래와 같은 에러가 다수 관측되었습니다.
    • feign.FeignException$BadRequest: [...] Invalid external api request [414 Request-URI Too Large] during [GET] to [/api/v1/users?userIds=... (14377 bytes)]
    • 호출 경로:
      • PokeController → PokeFacade → FriendRecommender → (플레이그라운드 후보 계산) → PlatformService.getPlatformUserInfosResponse → GET /api/v1/users?userIds=...
    • 원인: 수백 개의 userId를 반복 쿼리 파라미터로 붙여 플랫폼에 한 번에 조회 → URI 길이(약 14KB) 초과로 414 발생.

원인 분석

  1. 추천 후보 풀을 한 번에 플랫폼으로 조회하면서 **쿼리 파라미터(userIds=...&userIds=...)**가 매우 길어짐.
  2. 플랫폼 API가 GET 기반 멀티 파라미터라 본문(Body)로 전달 불가(현 시점).
  3. 호출 전 단계에서 ID 개수에 상한이 없었음.

변경 사항

  1. FriendRecommender
  • getRecommendableUserProfiles(...)에서 플랫폼 조회 전에 후보 ID를 (size×5, cap 50) 만큼만 RandomPicker로 추출하여 전달.
  • size <= 0일 때 빈 리스트 반환(가드 추가).
  • 변수명 통일: overSampleCount → oversampleCount.
  1. RandomPicker
  • 내부 난수 생성기를 static final Random → ThreadLocalRandom 으로 변경.
    • 다중 스레드 경합 제거, 성능/안정성 향상.
  • 기능/알고리즘(Fisher–Yates 부분 샘플링)은 동일, 재현성(seed 고정) 요구 없음.
    참고사항) 컨트롤러/Facade 등 외부 인터페이스 변경 없음. 최종 size 맞추기는 기존대로 바깥 RandomPicker.pickRandom(..., size)가 담당합니다(코드 변경 최소화).

기대 상황

  • 한 번에 플랫폼으로 보내는 ID 수를 최대 50개로 제한하므로,
    GET /api/v1/users?userIds=... URI 길이 ≈ < 1KB 수준으로 유지 → 414 임계(보통 8~16KB) 를 확실히 피함.
  • 플랫폼 호출 당 ID 수 감소로 쿼리 길이 단축 + 불필요한 대량 조회 감소.
  • ThreadLocalRandom 전환으로 경합 감소.

Trouble Shooting ⚽️

Related ScreenShot 📷

Uncompleted Tasks 😅

향후 개선(장기)

  • 플랫폼에 POST /api/v1/users/bulk (JSON Body) 추가 요청
    → 쿼리 파라미터 대신 바디 전달로 구조적으로 URI 길이 이슈 제거
    → 배치 크기 100~200까지도 안전 운용 가능

To Reviewers 📢

@hyerinhwang-sailin hyerinhwang-sailin linked an issue Sep 11, 2025 that may be closed by this pull request
1 task
@height
Copy link

height bot commented Sep 11, 2025

Link Height tasks by mentioning a task ID in the pull request title or commit messages, or description and comments with the keyword link (e.g. "Link T-123").

💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.

@hyerinhwang-sailin hyerinhwang-sailin self-assigned this Sep 11, 2025
@hyerinhwang-sailin hyerinhwang-sailin added 🛠️ BugFix 버그 해결 and removed size/M labels Sep 11, 2025
@hyerinhwang-sailin hyerinhwang-sailin merged commit 5a94434 into dev Sep 11, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] 콕찌르기 친구 추천 관련 feign error 해결

1 participant