[HSC-288] recommendation-server-v0.0.2#31
Conversation
[HCR-278] 분석 서버 응답 발행 및 MSK IAM Kafka 인증 지원
[HCR-272] 추천 서비스 RAG 파이프라인 클래스화 및 카프카 연결
Summary of ChangesHello, 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! 이 Pull Request는 추천 시스템의 핵심 구성 요소인 추천 파이프라인과 Kafka 연동 방식을 대폭 개선하여 Highlights
Changelog
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
이 PR은 추천 파이프라인을 개선하고 Kafka 연동을 강화하는 중요한 변경사항을 담고 있습니다. 전반적으로 RAG 파이프라인 도입, 비동기 처리, Kafka 인증 및 outbox 패턴 강화 등 아키텍처가 크게 개선되었습니다. 코드 구조가 잘 잡혀 있고, 특히 프롬프트 관리나 설정 중앙화 등 좋은 사례들이 많이 보입니다. 다만, 메시지 중복 발행 가능성과 Kafka 프로듀서 관리 효율성에 대한 두 가지 주요 개선점을 발견하여 코멘트를 남겼습니다. 이 부분들을 수정하면 시스템의 안정성과 성능이 더욱 향상될 것입니다.
| WHERE request_id = $1 | ||
| AND dispatch_status <> 'ACKED'::dispatch_status |
There was a problem hiding this comment.
prepare_response_dispatch 메소드의 WHERE 조건이 불충분하여 메시지 중복 발행의 위험이 있습니다. 현재 dispatch_status <> 'ACKED'만 확인하고 있어, SENT 상태인 메시지도 다시 처리 대상으로 간주됩니다. kafka_analysis_consumer_service에서 배치 처리 중 일부 메시지 발행 실패로 재시도가 발생하면, 이미 성공적으로 발행된 메시지들이 다시 발행될 수 있습니다. WHERE 조건에 SENT 상태도 제외하여 중복 처리를 방지해야 합니다.
| WHERE request_id = $1 | |
| AND dispatch_status <> 'ACKED'::dispatch_status | |
| WHERE request_id = $1 | |
| AND dispatch_status NOT IN ('SENT', 'ACKED') |
| async def publish_recommendation_to_kafka( | ||
| member_id: int, | ||
| response: RecommendationResponse, | ||
| ) -> None: | ||
| """추천 결과를 Kafka recommendation-topic으로 발행. Spring Consumer가 수신 후 persona_recommendation 적재.""" | ||
| settings = get_settings() | ||
| topic = getattr(settings, "kafka_recommendation_topic", "recommendation") | ||
| bootstrap = getattr(settings, "kafka_bootstrap_servers", "").strip() | ||
| if not bootstrap: | ||
| logging.warning("recommendation: Kafka 미설정, 발행 스킵 member_id=%s", member_id) | ||
| return | ||
| payload = {"memberId": member_id, **response.model_dump(by_alias=True)} | ||
| producer = AIOKafkaProducer( | ||
| bootstrap_servers=[s.strip() for s in bootstrap.split(",") if s.strip()], | ||
| value_serializer=lambda v: json.dumps(v, ensure_ascii=False).encode("utf-8"), | ||
| ) | ||
| try: | ||
| await producer.start() | ||
| await producer.send_and_wait(topic, value=payload, key=str(member_id).encode("utf-8")) | ||
| logging.info("recommendation: Kafka 발행 완료 member_id=%s topic=%s", member_id, topic) | ||
| except Exception as e: | ||
| logging.error("recommendation: Kafka 발행 실패 member_id=%s: %s", member_id, e, exc_info=True) | ||
| finally: | ||
| await producer.stop() |
There was a problem hiding this comment.
publish_recommendation_to_kafka 함수가 호출될 때마다 AIOKafkaProducer 인스턴스를 새로 생성하고 시작/중지하고 있습니다. 이는 매 추천 발행 시마다 Kafka에 대한 새로운 연결을 설정하는 오버헤드를 유발하여 비효율적입니다. 프로듀서는 애플리케이션 시작 시 생성하고 종료 시 정리하는 긴 수명의 객체로 관리하는 것이 좋습니다. 예를 들어, recommendation-server의 lifespan 컨텍스트 관리자나 유사한 메커니즘을 사용하여 프로듀서 인스턴스를 재사용하도록 리팩토링하는 것을 고려해 보세요.
🚀배포 목적
recommendation-server-v0.0.2를 배포합니다.이전 recommendation 릴리즈 이후 반영된 추천 파이프라인 개선과 Kafka 연동 변경사항을 운영 환경에 배포하는 목적입니다.
🏷️ Release Level
📦 배포 대상 (1개 이상)
📝작업 내용
v0.0.2배포👀변경 사항
#29,#28🎫 Jira Ticket
#️⃣관련 이슈