Skip to content

Conversation

@bo-ram-bo-ram
Copy link
Member

@bo-ram-bo-ram bo-ram-bo-ram commented Feb 26, 2025

Pull request

Related issue

Resolve #300

Motivation and context

기존에는 채팅 서버에서 카프카를 통해 히스토리 서버로 데이터를 전달하기 전에 RDB를 이용해 고유한 ID를 생성하였습니다. 그러나 분산 환경에서 AUTO_INCREMENT 사용 시 발생할 수 있는 문제와 RDB에 데이터를 쓰는 과정에서의 지연 문제를 파악하였고, 이를 해결하기 위해 Snowflake 알고리즘을 이용한 ID 생성 방식으로 변경하였습니다.

Solution

SnowflakeIdGenerator 클래스를 추가하여 Snowflake 알고리즘을 활용한 고유 ID를 생성하도록 구현하였습니다.

기존 RDB에서 ID를 생성하는 방식에서 SnowflakeIdGenerator.nextId()를 호출하는 방식으로 변경하였습니다.

ChatService의 createCommonData 메서드에서 기존 Thread 객체의 ID를 RDB에서 가져오던 방식에서 Snowflake를 사용하여 생성하는 방식으로 변경하였습니다.

How has this been tested

로컬 환경에서 SnowflakeIdGenerator를 이용한 ID 생성이 정상적으로 동작하는지 확인하였습니다.

채팅 메시지를 전송하고, Kafka를 통해 히스토리 서버로 정상적으로 ID가 포함된 메시지가 전달되는지 테스트하였습니다.

멀티 스레드 환경에서 ID 충돌 없이 고유한 값이 생성되는지 확인하였습니다.

기존 API와의 호환성을 유지하면서 변경 사항이 정상적으로 반영되었는지 테스트하였습니다.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the docs/CONTRIBUTING.md document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@sgdevcamp2025 sgdevcamp2025 deleted a comment from netlify bot Feb 26, 2025
@bo-ram-bo-ram bo-ram-bo-ram self-assigned this Feb 26, 2025
@bo-ram-bo-ram bo-ram-bo-ram added ✨ Feature 기능 추가 🎮 BE 백엔드 labels Feb 26, 2025
@mirlee0304 mirlee0304 merged commit edd3972 into dev Feb 27, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🎮 BE 백엔드 ✨ Feature 기능 추가

Projects

None yet

Development

Successfully merging this pull request may close these issues.

채팅서버 rdb로직 삭제 후 snowFlake 구현

4 participants