Skip to content

feat: 메뉴 목록 로컬 캐시 + Redis Pub/Sub 무효화 - #367

Merged
Jjiggu merged 3 commits into
developfrom
feature#-cache-pub-sub
Oct 27, 2026
Merged

Jjiggu merged 3 commits into
developfrom
feature#-cache-pub-sub

Conversation

@Jjiggu

@Jjiggu Jjiggu commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

작업 요약

  • 메뉴 조회 N+1(메뉴마다 이미지 조회)을 LEFT JOIN 한 번으로 변경 (MenuRepository.findAllWithImagesByStoreId)
  • menus(store_id, deleted, sort_order) 인덱스 추가
  • user-api 메뉴 목록에 Caffeine 로컬 캐시(DistributedCachedMenuDao, key: storeId, TTL 기본 1d) 적용
  • admin-api 메뉴/메뉴 이미지 변경 시 커밋 후 Redis Pub/Sub(cache:menus)으로 storeId 무효화 메시지 발행
  • 성능 측정 스크립트·결과 performance/menu-cache/

Issue Link

문제점 및 어려움

  • user-api가 여러 대일 때 로컬 캐시 간 일관성
  • 커밋 전에 무효화를 발행하면 구독 측이 커밋 전 값을 다시 읽어 TTL 동안 캐싱됨
  • Redis 연결이 끊긴 동안 놓친 무효화 메시지

해결 방안

  • 값은 공유하지 않고 키만 Pub/Sub으로 전파 (직렬화 불필요, 결과적 일관성)
  • CacheInvalidationPublisher가 afterCommit에서 발행
  • 재구독(onChannelSubscribed) 시 로컬 캐시 전체 비움
  • user-api 조회에서 @Transactional(readOnly = true) 제거 (스냅샷 안에서 캐시 미스 로딩 방지)
  • nowait.cache.menu.ttl=0s로 캐시 끄기 가능
  • 히트율 메트릭: cache_gets_total{cache="cache:menus"}

측정 (EC2, 1,000 req/s 기준 메뉴 쿼리 59,808 → 123, p95 200ms 내 최대 부하 100 → 4,000 req/s)

단계 요청당 쿼리 요청당 읽은 행 p95 200ms 내 최대 부하
N+1 22 4,041 100
JOIN 2 4,042 500
+ 인덱스 2 62 2,000
+ 캐시 1 1 4,000

Reference

  • performance/menu-cache/README.md

🤖 Generated with Claude Code

Jjiggu and others added 3 commits October 28, 2026 01:40
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions
github-actions Bot requested a review from HyemIin October 27, 2026 16:41
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Jjiggu
Jjiggu merged commit e31ce85 into develop Oct 27, 2026
1 check 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.

1 participant