Backend · 1 min read

Kotlin Coroutine 실전 적용기 - 초당 10만 요청 처리

카카오 메시징 시스템에서 Kotlin Coroutine을 도입하며 겪은 시행착오와 성능 개선 과정

김현우

Kotlin Coroutine 실전 적용기

레거시 Java 시스템을 Kotlin으로 마이그레이션하면서 Coroutine을 도입했다.

기존 문제

  • Thread Pool 고갈로 인한 타임아웃
  • 동시 접속자 증가 시 응답 지연
  • 리소스 사용 비효율

Coroutine 도입 후

suspend fun sendMessage(userId: Long, message: Message): Result {
return coroutineScope {
    val userDeferred = async { userService.getUser(userId) }
    val quotaDeferred = async { quotaService.check(userId) }

    val user = userDeferred.await()
    val quota = quotaDeferred.await()

    if (quota.exceeded) return@coroutineScope Result.QuotaExceeded

    messageQueue.send(user, message)
}
}

성능 개선

지표 Before After
평균 응답시간 120ms 45ms
P99 응답시간 800ms 180ms
처리량 8,000 RPS 35,000 RPS

Thread 대비 메모리 사용량이 1/10로 줄었다.

이 글 공유하기

댓글 0개

댓글을 작성하려면 로그인이 필요합니다.

로그인하기

아직 댓글이 없습니다

첫 번째 댓글을 남겨보세요!