Skip to content

feat: Replication Lag 완화 — 병렬 복제 + Sticky Primary#125

Merged
chooh1010 merged 2 commits into
mainfrom
feat/sticky-primary
May 16, 2026
Merged

feat: Replication Lag 완화 — 병렬 복제 + Sticky Primary#125
chooh1010 merged 2 commits into
mainfrom
feat/sticky-primary

Conversation

@chooh1010

@chooh1010 chooh1010 commented May 16, 2026

Copy link
Copy Markdown
Member

Summary

  • 쓰기 트랜잭션 커밋 후 STICKY_PRIMARY 쿠키(3초)를 발급하여 Read-your-own-writes 정합성 보장
  • StickyAwareRoutingDataSource가 LazyConnectionDataSourceProxy의 readOnlyDataSource로 동작하며, sticky 시 Master로 라우팅
  • TransactionSynchronization.afterCommit으로 커밋 성공 시에만 쿠키 발급 (롤백 시 미발급)
  • spring-boot-starter-aop 의존성 추가

부하테스트 결과 (1000 vusers, 10분)

지표 Before After 변화
Replication Lag 평균 66s 6s -91%
Replication Lag 최대 150s 27s -82%
P99 응답시간 366ms 153ms -58%

Test plan

  • StickyPrimaryHolderTest — ThreadLocal 격리, mark/clear 동작
  • StickyAwareRoutingDataSourceTest — sticky 시 Master, 아닐 때 Replica 라우팅
  • StickyPrimaryFilterTest — 쿠키 읽기, ThreadLocal 정리, 예외 시에도 clear

Closes #124

Write transactions set a STICKY_PRIMARY cookie (3s TTL) via
TransactionSynchronization.afterCommit. Subsequent requests within
the cookie window route readOnly queries to Master through
StickyAwareRoutingDataSource, guaranteeing users see their own writes
despite replication lag.

Closes #124

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chooh1010 chooh1010 linked an issue May 16, 2026 that may be closed by this pull request
@chooh1010 chooh1010 self-assigned this May 16, 2026
@chooh1010 chooh1010 added the feat add new features label May 16, 2026
Resolves SonarQube B security rating by setting cookie.setSecure()
using the existing guest.identifier.secure-cookie property.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@chooh1010 chooh1010 merged commit 574dccd into main May 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat add new features

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

feat: Replication Lag 완화 — 병렬 복제 + Sticky Primary

1 participant