Skip to content

Comments

[REFACTOR] 알림 조회 redis 캐싱 추가#404

Merged
1000hyehyang merged 2 commits intodevfrom
refactor/403-notification
Feb 19, 2026
Merged

[REFACTOR] 알림 조회 redis 캐싱 추가#404
1000hyehyang merged 2 commits intodevfrom
refactor/403-notification

Conversation

@1000hyehyang
Copy link
Member

Summary

미읽음 알림 개수 조회 API(GET /api/v1/notifications/unread-count) 성능 개선을 위해 Redis 캐시를 적용했습니다.

Changes

  • NotificationUnreadCountCache 컴포넌트 추가 (캐시 키: notification:unread:{userId}, TTL: 10분)
  • NotificationQueryService.getUnreadCount(): 캐시 조회 → 미스 시 DB 조회 후 캐시 저장
  • NotificationQueryService.getNotifications(): unread count를 getUnreadCount()로 조회해 캐시 재사용
  • NotificationService: 알림 생성, 읽음 처리, 전체 읽기, 소프트 삭제 시 캐시 무효화
  • Redis 장애 시 DB 조회로 폴백 (예외 처리 추가)

Type of Change

  • Bug fix (기존 기능에 영향을 주지 않는 버그 수정)
  • New feature (기존 기능에 영향을 주지 않는 새로운 기능 추가)
  • Breaking change (기존 기능에 영향을 주는 수정)
  • Refactoring (기능 변경 없는 코드 개선)
  • Documentation (문서 수정)
  • Chore (빌드, 설정 등 기타 변경)
  • Release (develop → main 배포)

Related Issues

Closes #403

참고 사항

@1000hyehyang 1000hyehyang self-assigned this Feb 19, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @1000hyehyang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 PR은 미읽음 알림 개수 조회 API의 성능을 개선하기 위해 Redis 캐싱을 도입합니다. 사용자별 미읽음 알림 개수를 Redis에 캐시하여 데이터베이스 부하를 줄이고 응답 시간을 단축하는 것이 주요 목적입니다. 알림 상태 변경 시 캐시를 적절히 무효화하여 데이터 일관성을 유지하며, Redis 장애 시에도 서비스가 정상 작동하도록 폴백 메커니즘을 구현했습니다.

Highlights

  • Redis 캐시 컴포넌트 추가: 미읽음 알림 개수 캐싱을 위한 NotificationUnreadCountCache 컴포넌트가 새로 구현되었습니다. 이 캐시는 notification:unread:{userId} 형식의 키를 사용하며, 10분 TTL을 가집니다.
  • 미읽음 알림 개수 조회 로직 개선: NotificationQueryServicegetUnreadCount 메서드가 Redis 캐시를 우선 조회하도록 변경되었습니다. 캐시에 데이터가 없을 경우 데이터베이스에서 조회한 후 캐시에 저장하여 다음 요청에 대비합니다.
  • 캐시 무효화 로직 구현: NotificationService에서 알림 생성, 읽음 처리, 전체 읽기, 소프트 삭제와 같은 알림 상태 변경 작업이 발생할 때마다 해당 사용자의 미읽음 알림 개수 캐시를 즉시 무효화하도록 로직이 추가되었습니다.
  • Redis 장애 폴백 처리: Redis 캐시 작업 중 예외가 발생할 경우, 데이터베이스 조회로 안전하게 폴백할 수 있도록 NotificationUnreadCountCache 컴포넌트에 예외 처리 로직이 포함되었습니다.
Changelog
  • src/main/java/com/example/RealMatch/notification/application/service/NotificationQueryService.java
    • NotificationUnreadCountCache 의존성이 주입되었습니다.
    • getNotifications 메서드에서 미읽음 알림 개수 조회 로직이 캐시를 사용하는 getUnreadCount 메서드로 변경되었습니다.
    • getUnreadCount 메서드에 Redis 캐시 조회 및 저장 로직이 추가되었습니다.
  • src/main/java/com/example/RealMatch/notification/application/service/NotificationService.java
    • NotificationUnreadCountCache 의존성이 주입되었습니다.
    • 알림 생성, 읽음 처리, 전체 읽기, 소프트 삭제 시 해당 사용자의 미읽음 알림 개수 캐시 무효화 로직이 추가되었습니다.
  • src/main/java/com/example/RealMatch/notification/infrastructure/redis/NotificationUnreadCountCache.java
    • 새로운 Redis 캐시 컴포넌트가 추가되었습니다.
    • 사용자 ID 기반으로 미읽음 알림 개수를 Redis에 저장, 조회, 무효화하는 메서드가 구현되었습니다.
    • Redis 작업 중 발생하는 예외를 처리하고 DB 폴백을 지원하는 로깅 로직이 포함되었습니다.
Activity
  • 이 PR은 아직 활동이 없습니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

미읽음 알림 개수 조회의 성능 개선을 위해 Redis 캐시를 도입한 점이 좋습니다. Cache Aside 패턴을 적절히 활용하였고, Redis 장애 시 DB로 폴백하는 로직도 잘 구현되었습니다. 다만, Spring의 트랜잭션 환경에서 캐시 무효화(Invalidation) 시점이 트랜잭션 커밋 이전이기 때문에 발생할 수 있는 데이터 정합성 문제에 대해 개선이 필요합니다.

@1000hyehyang
Copy link
Member Author

/gemini review 현재 리팩토링에 잠재적인 문제가 있는지 다시한번 검토하고 없다면 없다고 말해.

@1000hyehyang
Copy link
Member Author

@gemini-code-assist

/gemini review 현재 리팩토링에 잠재적인 문제가 있는지 다시한번 검토하고 없다면 없다고 말해.

@1000hyehyang 1000hyehyang merged commit 2f550ea into dev Feb 19, 2026
1 check passed
@1000hyehyang 1000hyehyang deleted the refactor/403-notification branch February 19, 2026 17:17
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces Redis caching for the unread notification count, which is a good step towards performance optimization. The implementation correctly handles cache invalidation after transactional operations and includes a fallback mechanism for Redis failures. The NotificationUnreadCountCache component is well-designed for this specific caching need. The review suggests an improvement in logging for data corruption issues and clarifies the acceptable handling of cache invalidation failures, aligning with the principle of accepting simpler solutions for non-critical edge cases.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces Redis caching for unread notification count lookup. The cache invalidation strategy and the use of invalidateAfterCommit are well implemented, and no security vulnerabilities were found. Please address a critical compile error related to TransactionSynchronization and consider the suggestion for improving readability of the cache logic.

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.

[REFACTOR] 알림 조회 성능 개선

1 participant