ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๋ฐ˜์‘ํ˜•

๐ŸŽฏ Kafka Concurrency Control

Race Condition

๊ฒฝ์Ÿ์ƒํƒœ๋Š” ๋‘ ๊ฐœ ์ด์ƒ์˜ ์Šค๋ ˆ๋“œ๊ฐ€ ๊ณต์œ  ๋ฐ์ดํ„ฐ์— ์•ก์„ธ์Šค ํ•  ์ˆ˜ ์žˆ๊ณ , ๋™์‹œ์— ๋ณ€๊ฒฝ์„ ํ•˜๋ ค๊ณ  ํ•  ๋•Œ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ

  • Race Condition ์œผ๋กœ ๋™์‹œ์— ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ๋“ค์ด ๊ฐฑ์‹  ์ „ ๊ฐ’์„ ์ฝ๊ณ , ์ˆ˜์ •ํ•˜๋ฉด์„œ
  • ์‹ค์ œ ๊ฐฑ์‹ ์ด ๋ˆ„๋ฝ๋˜๋Š” ํ˜„์ƒ์ด ๋ฐœ์ƒ

Series

Java Concurrency Control

Database Concurrency Control

Redis Concurrency Control

Kafka Concurrency Control

Compare Concurrency Control

๐Ÿน Kafka

๋ถ„์‚ฐ ์ŠคํŠธ๋ฆฌ๋ฐ ํ”Œ๋žซํผ์œผ๋กœ, ์ฃผ๋กœ ๋Œ€๊ทœ๋ชจ ์‹ค์‹œ๊ฐ„ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ์™€ ๋ฉ”์‹œ์ง•์— ์‚ฌ์šฉ

๋ฆฌ๋” ์„ ์ถœ(Leader Election) ๋˜๋Š” ํ˜‘์กฐ์  ์†Œ๋น„์ž ํŒจํ„ด(Cooperative Consumer Pattern) ์„ ํ™œ์šฉํ•˜์—ฌ ํŠน์ • ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•œ ์ ‘๊ทผ์„ ์กฐ์œจ


.

๋™์ž‘ ๋ฐฉ์‹.

  • ๋ฆฌ๋” ์„ ์ถœ์„ ํ†ตํ•œ ๋ฝ
    • Kafka์˜ ํŒŒํ‹ฐ์…˜๊ณผ ์˜คํ”„์…‹์„ ์ด์šฉํ•˜์—ฌ, ํŠน์ • ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ๋ฆฌ๋” ์„ ์ถœ
      • ํ•˜๋‚˜์˜ Kafka ํŒŒํ‹ฐ์…˜์—์„œ ๋ฉ”์‹œ์ง€๋ฅผ ์†Œ๋น„ํ•˜๋Š” ์—ฌ๋Ÿฌ ์ปจ์Šˆ๋จธ ์ค‘ ํ•˜๋‚˜๊ฐ€ ๋ฆฌ๋”๊ฐ€ ๋˜์–ด ํŠน์ • ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•œ ์ž‘์—…์„ ์ˆ˜ํ–‰ โ†’ ์ด ๋ฆฌ๋” ์—ญํ• ์ด ์ผ์ข…์˜ ๋ฝ ์—ญํ• 
      • ๋งŒ์•ฝ ๋ฆฌ๋”๊ฐ€ ์‹คํŒจํ•˜๊ฑฐ๋‚˜ ํŠน์ • ์‹œ๊ฐ„ ๋™์•ˆ ์‘๋‹ตํ•˜์ง€ ์•Š์œผ๋ฉด, ๋‹ค๋ฅธ ์ปจ์Šˆ๋จธ๊ฐ€ ์ƒˆ๋กœ์šด ๋ฆฌ๋”๋กœ ์„ ์ถœ๋˜์–ด ์ž‘์—…์„ ์ด์–ด๋ฐ›์Œ
  • ํ˜‘์กฐ์  ์†Œ๋น„์ž ํŒจํ„ด:
    • ์—ฌ๋Ÿฌ ์ปจ์Šˆ๋จธ๊ฐ€ ๋™์ผํ•œ Kafka ํ† ํ”ฝ์—์„œ ๋ฉ”์‹œ์ง€๋ฅผ ์†Œ๋น„ํ•  ๋•Œ, ์„œ๋กœ ํ˜‘๋ ฅํ•˜์—ฌ ํŠน์ • ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•œ ์ ‘๊ทผ์„ ์กฐ์œจ
    • ํŠน์ • ๋ฆฌ์†Œ์Šค๋ฅผ ๋™์‹œ์— ์ ‘๊ทผํ•˜์ง€ ์•Š๋„๋ก ํ˜‘์˜ํ•˜๋Š” ๊ณผ์ •์ด ํ•„์š” โ†’ ๋ฝ๊ณผ ์œ ์‚ฌํ•œ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ ๊ฐ€๋Šฅ
  • ๋ถ„์‚ฐ ํŠธ๋žœ์žญ์…˜ ๊ด€๋ฆฌ:
    • Kafka ํŠธ๋žœ์žญ์…˜ ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•˜์—ฌ, ๋ฉ”์‹œ์ง€๋ฅผ ์ฒ˜๋ฆฌํ•˜๋ฉด์„œ ๋ฝ์„ ์„ค์ •ํ•˜๊ณ  ํ•ด์ œ
    • ๋ฉ”์‹œ์ง€๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋™์•ˆ ํŠธ๋žœ์žญ์…˜์„ ์œ ์ง€ํ•˜๊ณ , ์ž‘์—…์ด ๋๋‚˜๋ฉด ํŠธ๋žœ์žญ์…˜์„ ์ปค๋ฐ‹ํ•˜๋ฉด์„œ ๋ฝ์„ ํ•ด์ œํ•˜๋Š” ๋ฐฉ์‹

์žฅ์ .

  • ๋†’์€ ํ™•์žฅ์„ฑ
    • ๋Œ€๊ทœ๋ชจ์˜ ๋ถ„์‚ฐ ์‹œ์Šคํ…œ์—์„œ ๋†’์€ ํ™•์žฅ์„ฑ์„ ์ œ๊ณตํ•˜๋„๋ก ์„ค๊ณ„
    • ์—ฌ๋Ÿฌ ์ปจ์Šˆ๋จธ๊ฐ€ ๋™์ผํ•œ Kafka ํด๋Ÿฌ์Šคํ„ฐ์—์„œ ๋ฝ์„ ๊ด€๋ฆฌ
  • ๋‚ด๊ฒฐํ•จ์„ฑ
    • ๋‚ด๊ฒฐํ•จ์„ฑ(fault-tolerance)์„ ์ง€์›
    • ๋ฆฌ๋” ์„ ์ถœ ๋ฐฉ์‹์ด๋‚˜ ํ˜‘์กฐ์  ์†Œ๋น„์ž ํŒจํ„ด์„ ์‚ฌ์šฉํ•˜๋ฉด ํŠน์ • ๋…ธ๋“œ๊ฐ€ ์‹คํŒจํ•˜๋”๋ผ๋„ ๋‹ค๋ฅธ ๋…ธ๋“œ๊ฐ€ ์ž‘์—…์„ ์ด์–ด๋ฐ›์•„ ๋ฝ์˜ ์•ˆ์ •์„ฑ์„ ๋ณด์žฅ
  • ์ค‘์•™ ์ง‘์ค‘ํ™”๋œ ๊ด€๋ฆฌ
    • Kafka ํ† ํ”ฝ์„ ์ด์šฉํ•˜์—ฌ ๋ฝ ์ƒํƒœ๋‚˜ ์ž‘์—… ์ƒํƒœ๋ฅผ ์ค‘์•™์—์„œ ๊ด€๋ฆฌ
    • ์‹œ์Šคํ…œ ์ „๋ฐ˜์˜ ์ƒํƒœ๋ฅผ ์‰ฝ๊ฒŒ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๊ณ  ๊ด€๋ฆฌ
  • ๋ณต์žกํ•œ ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ ๊ฐ€๋Šฅ
    • Kafka ํŠธ๋žœ์žญ์…˜ ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•˜๋ฉด ๋ฉ”์‹œ์ง€ ์ฒ˜๋ฆฌ์™€ ํ•จ๊ป˜ ๋ณต์žกํ•œ ํŠธ๋žœ์žญ์…˜์„ ๊ด€๋ฆฌ
    • ๋ฝ์„ ์œ ์ง€ํ•˜๋ฉด์„œ๋„ ๋ณต์žกํ•œ ์ž‘์—…์„ ์•ˆ์ „ํ•˜๊ฒŒ ์ˆ˜ํ–‰

๋‹จ์ .

  • ๋ณต์žก์„ฑ ์ฆ๊ฐ€
    • ํŠนํžˆ, ๋ฆฌ๋” ์„ ์ถœ์ด๋‚˜ ํ˜‘์กฐ์  ์†Œ๋น„์ž ํŒจํ„ด์„ ๊ตฌํ˜„ํ•˜๋ ค๋ฉด ๋” ๋งŽ์€ ์ฝ”๋”ฉ๊ณผ ์„ค์ •์ด ํ•„์š”
  • ์ง€์—ฐ ์‹œ๊ฐ„
    • Kafka ๋ถ„์‚ฐ ์•„ํ‚คํ…์ฒ˜์™€ ๋ฐ์ดํ„ฐ ์ „๋‹ฌ ์ง€์—ฐ์œผ๋กœ ์ธํ•ด ๋ฝ ํ•ด์ œ๋‚˜ ๋ฆฌ๋” ์„ ์ถœ ๊ณผ์ •์—์„œ ์ง€์—ฐ ๋ฐœ์ƒ
    • ์‹ค์‹œ๊ฐ„ ์ฒ˜๋ฆฌ๊ฐ€ ์ค‘์š”ํ•œ ํ™˜๊ฒฝ์—์„œ๋Š” ๋‹จ์ 
  • ์˜ค๋ฒ„ํ—ค๋“œ
    • ๋ฝ ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•ด ๋ฉ”์‹œ์ง€์˜ ์ƒ์‚ฐ, ์†Œ๋น„, ๋ฆฌ๋” ์„ ์ถœ ๊ณผ์ •์—์„œ ์ถ”๊ฐ€์ ์ธ ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ๋ฐœ์ƒ
    • ํŠนํžˆ, ๋ฝ์„ ์ž์ฃผ ์„ค์ •ํ•˜๊ณ  ํ•ด์ œํ•˜๋Š” ์ž‘์—…์ด ๋งŽ๋‹ค๋ฉด ์„ฑ๋Šฅ์—๋„ ์˜ํ–ฅ
  • ์ผ๊ด€์„ฑ ๋ฌธ์ œ
    • ๋ฝ์„ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐ ์žˆ์–ด์„œ ์ผ๊ด€์„ฑ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒ
      • ๋ฆฌ๋”๊ฐ€ ์„ ์ถœ๋˜๊ธฐ ์ „๊นŒ์ง€ ์—ฌ๋Ÿฌ ์ปจ์Šˆ๋จธ๊ฐ€ ๋™์ผํ•œ ๋ฆฌ์†Œ์Šค์— ์ ‘๊ทผํ•˜๋ ค๋Š” ๊ฒฝํ•ฉ์ด ๋ฐœ์ƒ
      • ์ผ๊ด€์„ฑ ๋ฌธ์ œ ํ•ด๊ฒฐ์„ ์œ„ํ•ด ์ถ”๊ฐ€์ ์ธ ์ œ์–ด ๋กœ์ง์ด ํ•„์š”
  • ํŠธ๋žœ์žญ์…˜ ๊ด€๋ฆฌ์˜ ๋ณต์žก์„ฑ
    • Kafka ํŠธ๋žœ์žญ์…˜ ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•˜์—ฌ ๋ฝ์„ ๊ด€๋ฆฌํ•˜๋ ค๋ฉด, ๋ณต์žกํ•œ ํŠธ๋žœ์žญ์…˜ ์ œ์–ด๊ฐ€ ํ•„์š”
    • ํŠธ๋žœ์žญ์…˜์ด ๊ธธ์–ด์ง€๊ฑฐ๋‚˜ ๋งŽ์€ ๋ฆฌ์†Œ์Šค๋ฅผ ์ž ๊ทธ๋Š” ๊ฒฝ์šฐ, ์„ฑ๋Šฅ ์ €ํ•˜๋‚˜ ๋ฐ๋“œ๋ฝ ๊ฐ™์€ ๋ฌธ์ œ๋ฅผ ์•ผ๊ธฐ

์‚ฌ๋ก€.

  • ๋ถ„์‚ฐ ์‹œ์Šคํ…œ์—์„œ์˜ ๋ฆฌ๋” ์„ ์ถœ
    • ์—ฌ๋Ÿฌ ๋…ธ๋“œ๊ฐ€ ๋™์ผํ•œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋ ค๊ณ  ํ•  ๋•Œ, ํ•˜๋‚˜์˜ ๋…ธ๋“œ๋ฅผ ๋ฆฌ๋”๋กœ ์„ ์ถœํ•˜์—ฌ ์ž‘์—…์„ ์กฐ์ •ํ•˜๋Š” ์ƒํ™ฉ
    • ex) ์—ฌ๋Ÿฌ ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค๊ฐ€ ๋™์ผํ•œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š๋„๋ก ๋ฆฌ๋”๋ฅผ ์„ ์ถœํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ
  • ํ˜‘์กฐ์  ์ž‘์—… ์ˆ˜ํ–‰
    • ์—ฌ๋Ÿฌ ์ปจ์Šˆ๋จธ๊ฐ€ ๋™์ผํ•œ Kafka ํ† ํ”ฝ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋ฉด์„œ, ํŠน์ • ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•œ ์ ‘๊ทผ์„ ์กฐ์œจํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ
    • ex) ์—ฌ๋Ÿฌ ์ปจ์Šˆ๋จธ๊ฐ€ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ…Œ์ด๋ธ”์— ์ ‘๊ทผํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•  ๋•Œ, Kafka ๋ฝ์„ ์‚ฌ์šฉํ•ด ๋ฐ์ดํ„ฐ ์ผ๊ด€์„ฑ์„ ์œ ์ง€
  • ๋ณต์žกํ•œ ๋ถ„์‚ฐ ํŠธ๋žœ์žญ์…˜
    • ๋ถ„์‚ฐ ํŠธ๋žœ์žญ์…˜์„ ๊ด€๋ฆฌํ•˜๋Š” ์ƒํ™ฉ์—์„œ Kafka์˜ ํŠธ๋žœ์žญ์…˜ ๊ธฐ๋Šฅ๊ณผ ๋ฝ์„ ๊ฒฐํ•ฉํ•˜์—ฌ, ์•ˆ์ „ํ•˜๊ฒŒ ์ž‘์—…์„ ์ˆ˜ํ–‰
    • ex) ๋ฉ”์‹œ์ง€ ์ฒ˜๋ฆฌ์™€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—…๋ฐ์ดํŠธ๊ฐ€ ๋™์‹œ์— ์ด๋ฃจ์–ด์ง€๋Š” ์ƒํ™ฉ์—์„œ Kafka ๋ฝ์„ ํ†ตํ•ด ์ผ๊ด€์„ฑ์„ ๋ณด์žฅ
  • ๋Œ€๊ทœ๋ชจ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ํŒŒ์ดํ”„๋ผ์ธ
    • ๋Œ€๊ทœ๋ชจ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ํŒŒ์ดํ”„๋ผ์ธ์—์„œ ์—ฌ๋Ÿฌ ์ž‘์—…์„ ์กฐ์œจํ•˜๊ณ  ๊ด€๋ฆฌํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ ์ž‘์—… ๊ฐ„์˜ ์ˆœ์„œ์™€ ์ผ๊ด€์„ฑ์„ ์œ ์ง€


...

Start Kafka

  • docker-compose.yml
version: '3' # Docker Compose ํŒŒ์ผ ๋ฒ„์ „ ์ง€์ •
services: # ์—ฌ๋Ÿฌ๊ฐœ์˜ Docker ์ปจํ…Œ์ด๋„ˆ ์„œ๋น„์Šค ์ •์˜
  zookeeper: # Zookeeper ์„œ๋น„์Šค ์ •์˜
    image: wurstmeister/zookeeper:3.4.6
    container_name: zookeeper
    ports:
      - "2181:2181" # ํ˜ธ์ŠคํŠธ์˜ 2181 ํฌํŠธ๋ฅผ ์ปจํ…Œ์ด๋„ˆ์˜ 2181 ํฌํŠธ์™€ ๋ฐ”์ธ๋”ฉ
  kafka: # kafka ์„œ๋น„์Šค ์ •์˜
    image: wurstmeister/kafka:2.12-2.5.0
    container_name: kafka
    ports:
      - "9092:9092" # ํ˜ธ์ŠคํŠธ์˜ 9092 ํฌํŠธ๋ฅผ ์ปจํ…Œ์ด๋„ˆ์˜ 9092 ํฌํŠธ์™€ ๋ฐ”์ธ๋”ฉ
    environment: # kafka ์ปจํ…Œ์ด๋„ˆ์˜ ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์„ค์ •
      KAFKA_ADVERTISED_LISTENERS: INSIDE://kafka:29092,OUTSIDE://localhost:9092 # ๋‚ด/์™ธ๋ถ€์—์„œ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๋ฆฌ์Šค๋„ˆ ์ฃผ์†Œ ์„ค์ •
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT # ๋ฆฌ์Šค๋„ˆ์˜ ๋ณด์•ˆ ํ”„๋กœํ† ์ฝœ ๋งคํ•‘
      KAFKA_LISTENERS: INSIDE://0.0.0.0:29092,OUTSIDE://0.0.0.0:9092 # ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์—์„œ ์‚ฌ์šฉํ•  ๋ฆฌ์Šค๋„ˆ ์ฃผ์†Œ ์„ค์ •
      KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE # ๋ธŒ๋กœ์ปค ๊ฐ„ ํ†ต์‹ ์— ์‚ฌ์šฉํ•  ๋ฆฌ์Šค๋„ˆ ์ด๋ฆ„
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 # Kafka๊ฐ€ Zookeeper์— ์—ฐ๊ฒฐํ•˜๊ธฐ ์œ„ํ•œ ์ฃผ์†Œ
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock # Docker ์†Œ์ผ“์„ ์ปจํ…Œ์ด๋„ˆ์™€ ๊ณต์œ ํ•˜์—ฌ Docker ์ด๋ฒคํŠธ๋ฅผ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •
  kafka-ui:
    image: provectuslabs/kafka-ui
    container_name: kafka-ui
    ports:
      - "8989:8080"
    restart: always
    environment:
      - KAFKA_CLUSTERS_0_NAME=local
      - KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS=kafka:29092
      - KAFKA_CLUSTERS_0_ZOOKEEPER=zookeeper:2181
  • run kafka
# ์นดํ”„์นด ์‹คํ–‰
$ docker-compose up -d
or
$ docker-compose -f docker-compose.yml up

# ํ† ํ”ฝ์ƒ์„ฑ
$ docker exec -it kafka kafka-topics.sh --bootstrap-server localhost:9092 --create --topic stock_decrease
Created topic testTopic.

# ํ”„๋กœ๋“€์„œ ์‹คํ–‰
$ docker exec -it kafka kafka-console-producer.sh --topic stock_decrease --broker-list 0.0.0.0:9092
>Hello

# ์ปจ์Šˆ๋จธ ์‹คํ–‰
$ docker exec -it kafka kafka-console-consumer.sh --topic stock_decrease --bootstrap-server localhost:9092
Hello

# ์นดํ”„์นด ์ข…๋ฃŒ
$ docker-compose down


.

commit log.


...

๐Ÿง kafka + redis ์ ์šฉ ๋ฐฉ์‹

  1. Producer๋Š” ๋ฉ”์‹œ์ง€ ๋ฐœํ–‰ ์ „ ๋ ˆ๋””์Šค๋กœ ์ž„๊ณ„๊ฐ’ ์ œ์–ด
    • ์ž„๊ณ„๊ฐ’์ด ๋„˜์ง€ ์•Š์•˜์„ ๊ฒฝ์šฐ: ์ดํ›„ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด Consumer์—๊ฒŒ ๋ฉ”์‹œ์ง€ ์ „์†ก
    • ์ž„๊ณ„๊ฐ’์ด ๋„˜์—ˆ์„ ๊ฒฝ์šฐ: ๋ฉ”์‹œ์ง€ ๋ฏธ๋ฐœํ–‰ ๋ฐ ์‚ฌ์šฉ์ž์—๊ฒŒ ์ฒ˜๋ฆฌ ๋ถˆ๊ฐ€ ์•Œ๋ฆผ
  2. Consumer๋Š” ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง๋งŒ ์ˆ˜ํ–‰

์ด๋ ‡๊ฒŒ ํ•  ๊ฒฝ์šฐ ์ž„๊ณ„๊ฐ’์€ ๋ ˆ๋””์Šค๋ฅผ ํ†ตํ•ด ๋น ๋ฅด๊ฒŒ ํ™•์ธํ•˜๊ณ , ์‹ค์ œ ์ฒ˜๋ฆฌ๋Š” ์ปจ์Šˆ๋จธ๊ฐ€ ๋น„๋™๊ธฐ๋กœ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.

 public void decrease(final Long userId, final Long stockId) {
      final KafkaStock stock = stockRepository.findById(stockId).orElseThrow();
      // ๋ ˆ๋””์Šค๋ฅผ ํ†ตํ•ด ์ž„๊ณ„๊ฐ’์„ ํ™•์ธ
      final Long count = redisIncrRepository.increment(stockId);
      stock.validQuantity(count);

      // ์‹ค์ œ ์ฒ˜๋ฆฌ๋Š” ์ปจ์Šˆ๋จธ๊ฐ€ ๋น„๋™๊ธฐ๋กœ ์ฒ˜๋ฆฌ
      stockDecreaseProducer.create(userId, stockId);
  }


.

๐Ÿ› ๏ธ ์„ฑ๋Šฅ ํ…Œ์ŠคํŠธ.

  • ํ•œ์ • ์ˆ˜๋Ÿ‰: 50,000

  • User: 296

  • Processes: 8

  • Threads: 37

  • Duration: 3 min (01:52)

    ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ฉด ์ •ํ™•ํ•˜๊ฒŒ 50,000 ๊ฑด๋งŒ ์„ฑ๊ณต์œผ๋กœ ์ฒ˜๋ฆฌ๋œ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

    00:46 ์ดํ›„์—๋Š” ๋ชจ๋“  ์ˆ˜๋Ÿ‰์ด 0์œผ๋กœ ์กฐํšŒ๋˜์–ด, ์žฌ๊ณ  ๋ถ€์กฑ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๊ฒŒ ๋œ๋‹ค.

    Result


Kafka ๋ฉ”์‹œ์ง€๋„ ์ •ํ™•ํžˆ 50,000 ๊ฑด๋งŒ ์ „์†ก์ด ๋˜์—ˆ๋‹ค.

Result


๋งŒ์ผ ์ปจ์Šˆ๋จธ์—์„œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ๋ณ„๋„๋กœ ์ฒ˜๋ฆฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋กœ๊ทธ๋ฅผ ๋‚จ๊ฒจ๋‘˜ ์ˆ˜๋„ ์žˆ๋‹ค.

Result

๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
๋งํฌ
Total
Today
Yesterday