๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
MSA

MSA๋กœ ์ „ํ–ฅํ•œ 11๋ฒˆ๊ฐ€์˜ ์‚ฌ๋ก€

by notcherry 2023. 12. 6.

 

๐Ÿ“ŒHystrix

netfilx๊ฐ€ ๋งŒ๋“  fault tolerance library๋กœ ์ฃผ๋กœ ์žฅ์•  ์ „ํŒŒ ๋ฐฉ์ง€์™€ resilience ๊ธฐ๋Šฅ์„ ํ•œ๋‹ค.

๐ŸŽจ์ ์šฉ ๋ฐฉ๋ฒ•

  1. Hystrix annotation ์‚ฌ์šฉ - hystrix javanic, spring cloud netfix์— ํฌํ•จ๋˜์–ด ์žˆ์Œ
@HystrixCommand
public String anyMethod() {
}
  1. Hystrix command ์ƒ์†
pulbic class SampleCommand extends HystrixCommand<String> {
@Override
protected String run() {}
}

hystrix command๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ๋ฒŒ์–ด์ง€๋Š” ์ผ

  1. ๋ฉ”์†Œ๋“œ๋ฅผ interceptํ•˜์—ฌ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค - thread isolation
  2. ๋ฉ”์†Œ๋“œ ์‹คํ–‰ ๊ฒฐ๊ณผ ์„ฑ๊ณต ํ˜น์€ ์‹คํŒจ ๋ฐœ์ƒ ์—ฌ๋ถ€๋ฅผ ์ธ์Šคํ„ด์Šค ๋‹จ์œ„๋กœ ๊ธฐ๋กํ•˜๊ณ  ํ†ต๊ณ„๋‚ธ๋‹ค. ํ†ต๊ณ„์— ๋”ฐ๋ผ circuit open ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค. - circuit breaker
  3. ์‹คํŒจํ•œ ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž๊ฐ€ ์ œ๊ณตํ•œ ๋ฉ”์†Œ๋“œ๋ฅผ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค - fallback
  4. ํŠน์ • ์‹œ๊ฐ„๋™์•ˆ ๋ฉ”์†Œ๋“œ๊ฐ€ ์ข…๋ฃŒ๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ exception์„ ๋ฐœ์ƒํ•œ๋‹ค - timeout

๐Ÿ˜ฒ๊ธฐ๋Šฅ์  ๊ด€์ ์—์„œ ๋ณธ Hystrix์˜ ์ฃผ์š” 4๊ฐ€์ง€ ๊ธฐ๋Šฅ

Circuit Breaker

hystrix.command.<commandKey>. //circuitbreaker ์„ ์–ธ 

metrics.rollingStats.timeInMilliseconds - Default 10์ดˆ
circuitBreaker.requestVolumeThreshold - Default 20๊ฐœ
circuitBreaker.errorThresholdPercentage - Default 50%
circuitBreaker.sleepWindowInMilliseconds - Default 5์ดˆ

hystrix command breaker๋Š” ํ•œ ํ”„๋กœ์„ธ์Šค ๋‚ด์—์„œ ์ฃผ์–ด์ง„ CommandKey ๋‹จ์œ„๋กœ ํ†ต๊ณ„๋ฅผ ๋‚ด๊ณ  ๋™์ž‘ํ•œ๋‹ค.

10์ดˆ ๋™์•ˆ 20๊ฐœ ์ด์ƒ์˜ ํ˜ธ์ถœ์ด ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ, 50%์ด์ƒ์˜ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด 5์ดˆ๊ฐ„ ํ˜ธ์ถœ ์ฐจ๋‹จ(circuit open)

์ผ์ • ์‹œ๊ฐ„(10์ดˆ) ๊ฒฝ๊ณผ ํ›„์— ๋‹จ ํ•œ ๊ฐœ์˜ ์š”์ฒญ์— ๋Œ€ํ•ด์„œ ํ˜ธ์ถœ์„ ํ—ˆ์šฉํ•˜๋ฉฐ(Half open), ์ด ํ˜ธ์ถœ์ด ์„ฑ๊ณตํ•˜๋ฉด → Circuit Close(ํ˜ธ์ถœ ํ—ˆ์šฉ)

Fallback

fallback์œผ๋กœ ์ง€์ •๋œ ๋ฉ”์†Œ๋“œ๋Š” ๋‹ค์Œ ๊ฒฝ์šฐ์— ์›๋ณธ ๋ฉ”์†Œ๋“œ๋ฅผ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค.

  1. circuit open
  2. any exception(HystrixBadRequestException ์ œ์™ธ)
  3. Semaphore/ ThreadPoolRejection
  4. Timeout
@HystrixCommand(commandKey = "ExtDep1", fallbackMethod="recommendFallback")
//์ถ”์ฒœ ์„œ๋ฒ„ ํ˜ธ์ถœ
public String anyMethod() {}
//๋ฏธ๋ฆฌ ์ค€๋น„๋œ ์ƒํ’ˆ ๋ชฉ๋ก
public String recommendFallback(){return "<๋ฏธ๋ฆฌ ์ค€๋น„๋œ ์ƒํ’ˆ ๋ชฉ๋ก>"}

๐Ÿงจ exception ํ„ฐ์ง€๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ์ฐพ๊ธฐ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ์Œ. ๋น„์ƒ์‹์ ์œผ๋กœ ์‘๋‹ต์ด ๋น ๋ฅด๋‹ค๋ฉด ๋ณธ ๋ฉ”์†Œ๋“œ(anyMethod)๊ฐ€ ์ œ๋Œ€๋กœ ์ž‘๋™ํ•˜๋Š”์ง€ ๋กœ๊น…ํ•ด ๋ณผ ๊ฒƒ.

๐ŸงจHystrixBadRequestException : ์ด ์˜ค๋ฅ˜๋Š” fallback์„ ์‹คํ–‰ํ•˜์ง€ ์•Š์œผ๋ฉฐ circuit open์„ ์œ„ํ•œ ํ†ต๊ณ„์—๋„ ์ง‘๊ณ„๋˜์ง€ ์•Š๋Š”๋‹ค. ์ž˜๋ชป๋œ ํŒŒ๋ผ๋ฏธํ„ฐ ์ „๋‹ฌ๊ณผ ๊ฐ™์€ method caller์˜ ์‹ค์ˆ˜์˜ ๊ฒฝ์šฐ ์ด ์˜ˆ์™ธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๋งŒ์•ฝ ๋‹ค๋ฅธ ์˜ˆ์™ธ๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค๋ฉด circuit breaker ํ†ต๊ณ„์— ์ง‘๊ณ„๋˜์–ด circuit open์ด ๋˜๊ฑฐ๋‚˜ fallback์ด ์‹คํ–‰๋˜์–ด ๊ฐœ๋ฐœ ๊ณผ์ •์— ์˜ค๋ฅ˜๋ฅผ ์ธ์ง€ํ• ์ง€ ๋ชป ํ•  ์ˆ˜ ์žˆ๋‹ค.

Timeout

hystrix์—์„œ๋Š” circuit breaker ๋‹จ์œ„๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

metrics.rollingStats.timeInMilliseconds - Default 1์ดˆ

๋ณดํ†ต์€ 1์ดˆ ๋ฏธ๋งŒ์œผ๋กœ ์‘๋‹ต์ด ์™€์•ผ ํ•˜์ง€๋งŒ, ui๋กœ์ง์ด ๋ณต์žกํ•˜๊ฑฐ๋‚˜ ๋“ฑ์˜ ์ด์œ ๋กœ ์กฐ๊ธˆ ๋” ๋Š˜๋ ค๋„ ์ข‹๋‹ค.

Isolation

์ตœ๋Œ€ ๊ฐœ์ˆ˜ ์ดˆ๊ณผ ์‹œ semaphore rejection(fallback) ๋ฐœ์ƒํ•œ๋‹ค.

๋‘ ๊ฐ€์ง€ isolation ๋ฐฉ์‹์„ ๋‹จ์œ„ ๋ณ„๋กœ ์ง€์ • ๊ฐ€๋Šฅ

semaphore

circuit breaker 1๊ฐœ๋‹น 1๊ฐœ์˜ semaphore ์ƒ์„ฑํ•˜๊ณ , command๋ฅผ ํ˜ธ์ถœํ•œ caller Thread์—์„œ fallback ๋ฉ”์†Œ๋“œ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค. ๐Ÿงจtimeout์ด ์ œ ์‹œ๊ฐ„์— ๋ฐœ์ƒํ•˜์ง€ ๋ชปํ•œ๋‹ค๋Š” ๋‹จ์ ์ด.. ์ด๊ฒƒ์€ ์Šค๋ž˜๋“œ๋กœ ํ•ด๊ฒฐ ๊ฐ€๋Šฅ

thread(default)

circuit breaker ๋ณ„๋กœ ์‚ฌ์šฉํ•  thread pool ์ง€์ •(ThreadPoolKey)

command๋ฅผ ํ˜ธ์ถœํ•œ thread๊ฐ€ ์•„๋‹Œ, thread pool์—์„œ fallback ๋ฉ”์†Œ๋“œ ์‹คํ–‰.


๐Ÿ“ŒRibbon

netflix๊ฐ€ ๋งŒ๋“  software load balancer๋ฅผ ๋‚ด์žฅํ•œ RPC library

-Client Load Balancer with HTTP Client

API์ฝœ๋Ÿฌ๋“ค์— ์ž๋™์œผ๋กœ ribbon client๊ฐ€ ๋ถ™๊ฒŒ ๋˜๋ฉด, ์ธํ”„๋ผ์˜ ๋„์›€ ์—†์ด๋„ ๋‹ค์ˆ˜์˜ ์„œ๋ฒ„ ๋ชฉ๋ก์„ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ•˜์ง€๋งŒ ์Šคํ”„๋ง ํด๋ผ์šฐ๋“œ์—์„œ๋Š” ribbon ํด๋ผ์ด์–ธํŠธ๋ฅผ ์‚ฌ์šฉ์ž๊ฐ€ ์ง์ ‘ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Œ! ์Šคํ”„๋ง ํด๋ผ์šฐ๋“œ์—๋Š” http ํ†ต์‹ ์ด ํ•„์š”ํ•œ ์š”์†Œ๊ฐ€ ๋‚ด์žฅ๋˜์–ด ์žˆ์Œ. (api gateway, feign, restTemplate(@LoadBalanced))


๐Ÿ“ŒEureka

netflix๊ฐ€ ๋งŒ๋“  dynamic service discovery

-๋“ฑ๋ก: ์„œ๋ฒ„๊ฐ€ ์ž์‹ ์˜ ์„œ๋น„์Šค ์ด๋ฆ„๊ณผ IP ์ฃผ์†Œ, ํฌํŠธ๋ฅผ ๋“ฑ๋ก

-์กฐํšŒ: ์„œ๋น„์Šค ์ด๋ฆ„์„ ๊ฐ–๊ณ  ์„œ๋ฒ„ ๋ชฉ๋ก์„ ์กฐํšŒ

Ribbon๊ณผ ์—ฐ๋™ํ•ด ์„œ๋ฒ„ ๋ชฉ๋ก์„ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋‹ค.

Server ์‹œ์ž‘ ์‹œ eureka ์„œ๋ฒ„์— ์ž๋™์œผ๋กœ ์ž์‹ ์˜ ์ƒํƒœ ๋“ฑ๋ก

์ฃผ๊ธฐ์  heartbeat์œผ๋กœ eureka server์— ์ž์‹ ์ด ์‚ด์•„์žˆ์Œ์„ ์•Œ๋ฆผ

server ์ข…๋ฃŒ ์‹œ eureka ์„œ๋ฒ„์— ์ž์‹ ์˜ ์ƒํƒœ ๋ณ€๊ฒฝ ํ˜น์€ ์ž์‹ ์˜ ๋ชฉ๋ก ์‚ญ์ œ

eureka ์ƒ์— ๋“ฑ๋ก๋œ ์ด๋ฆ„์€ “spring.application.name

Ribbon + Eureka in Spring cloud?

ํ•˜๋‚˜์˜ ์„œ๋ฒ„์—๋Š” eureka client ์™€ ribbon client๊ฐ€ ํ•จ๊ป˜ ์„ค์ •๋˜๋ฉด spring cloud๋Š” ๋‹ค์Œ์˜ ribbon bean์„ ๋Œ€์ฒด (์„œ๋ฒ„์˜ ๋ชฉ๋ก์„ ์„ค์ •์œผ๋กœ ๋ช…์‹œํ•˜๋Š” ๋Œ€์‹ , eureka๋ฅผ ํ†ตํ•ด์„œ look upํ•ด์˜ด)

  1. serverList<Server>→ ๋ณ€๊ฒฝ: DiscoverEnableNIWSServerList
  2. -๊ธฐ๋ณธ: ConfigurationBasedServerList
  3. IPing→ ๋ณ€๊ฒฝ: NIWSDiscoveryPing
  4. -๊ธฐ๋ณธ: DummyPing

๐ŸŽˆ API Gateway

msa ํ™˜๊ฒฝ์—์„œ api gateway์˜ ํ•„์š”์„ฑ

  1. single endpoint ์ œ๊ณต
  2. api ๊ณตํ†ต ๋กœ์ง ๊ตฌํ˜„ - logging, authentication, authorization
  3. traffic control - api quota, throttling

๐Ÿ”๋ฌธ์ œ ์ง๋ฉด!

100% ์ž์ฒด ๊ฐœ๋ฐœํ•œ api gateway๋ฅผ ๋‘๊ณ  spring cloud zuul์„ ๋„์ž…ํ•ด์•ผ ํ• ๊นŒ?

→yes!

์ด์œ  : ์„œ๋ฒ„์˜ ๋ชจ๋“  ํ˜ธ์ถœ์€ hystrix command๊ฐ€ ๊ฐ์‹ธ์„œ ํ˜ธ์ถœํ•œ๋‹ค. ๊ทธ ์•ˆ์—๋Š” ribbon client๊ฐ€ ์กด์žฌ. ๊ทธ ์•ˆ์—์„œ eureka client๋ฅผ ํ†ตํ•ด์„œ ์‹ค์ œ ์„œ๋ฒ„๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.

api gateway๋ฅผ ์‚ฌ์šฉํ•ด endpoint ๊ด€๋ฆฌ๋ฅผ ํ•˜์ง€ ์•Š์•„๋„ ๋˜๊ณ , service์— ์˜ค๋ฅ˜๊ฐ€ ๋‚˜๋„ ๋‚ด ๊ฒŒ์ดํŠธ ์›จ์ด๋Š” ์ฃฝ์ง€ ์•Š์„ ์ตœํ›„์˜ ๋ณด๋ฃจ๊ฐ€ ์ƒ๊ธด๋‹ค. circuit breaker์™€ isolation์ด ๋‚ด zuul์˜ ํ•œ ๊ตฐ์ด ์ฃฝ๋”๋ผ๋„ ๊ฒฉ๋ฆฌ ์‹œ์ผœ์ฃผ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. spring cloud zuul ์—์„œ hystrix isolation์€ semaphore์„ ๊ธฐ๋ณธ์œผ๋กœ ํ•œ๋‹ค.


๐ŸŽƒ์žฅ์•  ์‹œ๋‚˜๋ฆฌ์˜ค

hystrix, eureka, ribbon์„ ์‚ฌ์šฉํ•œ ์šฐ๋ฆฌ system์€ ์–ด๋Š ์ •๋„ resilience ํ•œ ๊ฑฐ์•ผ?


๐ŸŽˆ Spring Cloud Sleuth - Logging

spring cloud sleuth ์‚ฌ์šฉ ์‹œ application ๋กœ๊ทธ์— trace Id(uuid)๊ฐ€ ํ•จ๊ป˜ ์ถœ๋ ฅ

with Zipkin !

hystrix with turbin !

MSA๋กœ ์ „ํ–ฅํ•œ 11๋ฒˆ๊ฐ€์˜ ์‚ฌ๋ก€

๐Ÿ“ŒHystrix

netfilx๊ฐ€ ๋งŒ๋“  fault tolerance library๋กœ ์ฃผ๋กœ ์žฅ์•  ์ „ํŒŒ ๋ฐฉ์ง€์™€ resilience ๊ธฐ๋Šฅ์„ ํ•œ๋‹ค.

๐ŸŽจ์ ์šฉ ๋ฐฉ๋ฒ•

  1. Hystrix annotation ์‚ฌ์šฉ - hystrix javanic, spring cloud netfix์— ํฌํ•จ๋˜์–ด ์žˆ์Œ
@HystrixCommand
public String anyMethod() {
}
  1. Hystrix command ์ƒ์†
pulbic class SampleCommand extends HystrixCommand<String> {
@Override
protected String run() {}
}

hystrix command๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ๋ฒŒ์–ด์ง€๋Š” ์ผ

  1. ๋ฉ”์†Œ๋“œ๋ฅผ interceptํ•˜์—ฌ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค - thread isolation
  2. ๋ฉ”์†Œ๋“œ ์‹คํ–‰ ๊ฒฐ๊ณผ ์„ฑ๊ณต ํ˜น์€ ์‹คํŒจ ๋ฐœ์ƒ ์—ฌ๋ถ€๋ฅผ ์ธ์Šคํ„ด์Šค ๋‹จ์œ„๋กœ ๊ธฐ๋กํ•˜๊ณ  ํ†ต๊ณ„๋‚ธ๋‹ค. ํ†ต๊ณ„์— ๋”ฐ๋ผ circuit open ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค. - circuit breaker
  3. ์‹คํŒจํ•œ ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž๊ฐ€ ์ œ๊ณตํ•œ ๋ฉ”์†Œ๋“œ๋ฅผ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค - fallback
  4. ํŠน์ • ์‹œ๊ฐ„๋™์•ˆ ๋ฉ”์†Œ๋“œ๊ฐ€ ์ข…๋ฃŒ๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ exception์„ ๋ฐœ์ƒํ•œ๋‹ค - timeout

๐Ÿ˜ฒ๊ธฐ๋Šฅ์  ๊ด€์ ์—์„œ ๋ณธ Hystrix์˜ ์ฃผ์š” 4๊ฐ€์ง€ ๊ธฐ๋Šฅ

Circuit Breaker

hystrix.command.<commandKey>. //circuitbreaker ์„ ์–ธ 

metrics.rollingStats.timeInMilliseconds - Default 10์ดˆ
circuitBreaker.requestVolumeThreshold - Default 20๊ฐœ
circuitBreaker.errorThresholdPercentage - Default 50%
circuitBreaker.sleepWindowInMilliseconds - Default 5์ดˆ

hystrix command breaker๋Š” ํ•œ ํ”„๋กœ์„ธ์Šค ๋‚ด์—์„œ ์ฃผ์–ด์ง„ CommandKey ๋‹จ์œ„๋กœ ํ†ต๊ณ„๋ฅผ ๋‚ด๊ณ  ๋™์ž‘ํ•œ๋‹ค.

10์ดˆ ๋™์•ˆ 20๊ฐœ ์ด์ƒ์˜ ํ˜ธ์ถœ์ด ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ, 50%์ด์ƒ์˜ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด 5์ดˆ๊ฐ„ ํ˜ธ์ถœ ์ฐจ๋‹จ(circuit open)

์ผ์ • ์‹œ๊ฐ„(10์ดˆ) ๊ฒฝ๊ณผ ํ›„์— ๋‹จ ํ•œ ๊ฐœ์˜ ์š”์ฒญ์— ๋Œ€ํ•ด์„œ ํ˜ธ์ถœ์„ ํ—ˆ์šฉํ•˜๋ฉฐ(Half open), ์ด ํ˜ธ์ถœ์ด ์„ฑ๊ณตํ•˜๋ฉด → Circuit Close(ํ˜ธ์ถœ ํ—ˆ์šฉ)

Fallback

fallback์œผ๋กœ ์ง€์ •๋œ ๋ฉ”์†Œ๋“œ๋Š” ๋‹ค์Œ ๊ฒฝ์šฐ์— ์›๋ณธ ๋ฉ”์†Œ๋“œ๋ฅผ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค.

  1. circuit open
  2. any exception(HystrixBadRequestException ์ œ์™ธ)
  3. Semaphore/ ThreadPoolRejection
  4. Timeout
@HystrixCommand(commandKey = "ExtDep1", fallbackMethod="recommendFallback")
//์ถ”์ฒœ ์„œ๋ฒ„ ํ˜ธ์ถœ
public String anyMethod() {}
//๋ฏธ๋ฆฌ ์ค€๋น„๋œ ์ƒํ’ˆ ๋ชฉ๋ก
public String recommendFallback(){return "<๋ฏธ๋ฆฌ ์ค€๋น„๋œ ์ƒํ’ˆ ๋ชฉ๋ก>"}

๐Ÿงจ exception ํ„ฐ์ง€๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ์ฐพ๊ธฐ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ์Œ. ๋น„์ƒ์‹์ ์œผ๋กœ ์‘๋‹ต์ด ๋น ๋ฅด๋‹ค๋ฉด ๋ณธ ๋ฉ”์†Œ๋“œ(anyMethod)๊ฐ€ ์ œ๋Œ€๋กœ ์ž‘๋™ํ•˜๋Š”์ง€ ๋กœ๊น…ํ•ด ๋ณผ ๊ฒƒ.

๐ŸงจHystrixBadRequestException : ์ด ์˜ค๋ฅ˜๋Š” fallback์„ ์‹คํ–‰ํ•˜์ง€ ์•Š์œผ๋ฉฐ circuit open์„ ์œ„ํ•œ ํ†ต๊ณ„์—๋„ ์ง‘๊ณ„๋˜์ง€ ์•Š๋Š”๋‹ค. ์ž˜๋ชป๋œ ํŒŒ๋ผ๋ฏธํ„ฐ ์ „๋‹ฌ๊ณผ ๊ฐ™์€ method caller์˜ ์‹ค์ˆ˜์˜ ๊ฒฝ์šฐ ์ด ์˜ˆ์™ธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๋งŒ์•ฝ ๋‹ค๋ฅธ ์˜ˆ์™ธ๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค๋ฉด circuit breaker ํ†ต๊ณ„์— ์ง‘๊ณ„๋˜์–ด circuit open์ด ๋˜๊ฑฐ๋‚˜ fallback์ด ์‹คํ–‰๋˜์–ด ๊ฐœ๋ฐœ ๊ณผ์ •์— ์˜ค๋ฅ˜๋ฅผ ์ธ์ง€ํ• ์ง€ ๋ชป ํ•  ์ˆ˜ ์žˆ๋‹ค.

Timeout

hystrix์—์„œ๋Š” circuit breaker ๋‹จ์œ„๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

metrics.rollingStats.timeInMilliseconds - Default 1์ดˆ

๋ณดํ†ต์€ 1์ดˆ ๋ฏธ๋งŒ์œผ๋กœ ์‘๋‹ต์ด ์™€์•ผ ํ•˜์ง€๋งŒ, ui๋กœ์ง์ด ๋ณต์žกํ•˜๊ฑฐ๋‚˜ ๋“ฑ์˜ ์ด์œ ๋กœ ์กฐ๊ธˆ ๋” ๋Š˜๋ ค๋„ ์ข‹๋‹ค.

Isolation

์ตœ๋Œ€ ๊ฐœ์ˆ˜ ์ดˆ๊ณผ ์‹œ semaphore rejection(fallback) ๋ฐœ์ƒํ•œ๋‹ค.

๋‘ ๊ฐ€์ง€ isolation ๋ฐฉ์‹์„ ๋‹จ์œ„ ๋ณ„๋กœ ์ง€์ • ๊ฐ€๋Šฅ

semaphore

circuit breaker 1๊ฐœ๋‹น 1๊ฐœ์˜ semaphore ์ƒ์„ฑํ•˜๊ณ , command๋ฅผ ํ˜ธ์ถœํ•œ caller Thread์—์„œ fallback ๋ฉ”์†Œ๋“œ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค. ๐Ÿงจtimeout์ด ์ œ ์‹œ๊ฐ„์— ๋ฐœ์ƒํ•˜์ง€ ๋ชปํ•œ๋‹ค๋Š” ๋‹จ์ ์ด.. ์ด๊ฒƒ์€ ์Šค๋ž˜๋“œ๋กœ ํ•ด๊ฒฐ ๊ฐ€๋Šฅ

thread(default)

circuit breaker ๋ณ„๋กœ ์‚ฌ์šฉํ•  thread pool ์ง€์ •(ThreadPoolKey)

command๋ฅผ ํ˜ธ์ถœํ•œ thread๊ฐ€ ์•„๋‹Œ, thread pool์—์„œ fallback ๋ฉ”์†Œ๋“œ ์‹คํ–‰.


๐Ÿ“ŒRibbon

netflix๊ฐ€ ๋งŒ๋“  software load balancer๋ฅผ ๋‚ด์žฅํ•œ RPC library

-Client Load Balancer with HTTP Client

API์ฝœ๋Ÿฌ๋“ค์— ์ž๋™์œผ๋กœ ribbon client๊ฐ€ ๋ถ™๊ฒŒ ๋˜๋ฉด, ์ธํ”„๋ผ์˜ ๋„์›€ ์—†์ด๋„ ๋‹ค์ˆ˜์˜ ์„œ๋ฒ„ ๋ชฉ๋ก์„ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ•˜์ง€๋งŒ ์Šคํ”„๋ง ํด๋ผ์šฐ๋“œ์—์„œ๋Š” ribbon ํด๋ผ์ด์–ธํŠธ๋ฅผ ์‚ฌ์šฉ์ž๊ฐ€ ์ง์ ‘ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Œ! ์Šคํ”„๋ง ํด๋ผ์šฐ๋“œ์—๋Š” http ํ†ต์‹ ์ด ํ•„์š”ํ•œ ์š”์†Œ๊ฐ€ ๋‚ด์žฅ๋˜์–ด ์žˆ์Œ. (api gateway, feign, restTemplate(@LoadBalanced))


๐Ÿ“ŒEureka

netflix๊ฐ€ ๋งŒ๋“  dynamic service discovery

-๋“ฑ๋ก: ์„œ๋ฒ„๊ฐ€ ์ž์‹ ์˜ ์„œ๋น„์Šค ์ด๋ฆ„๊ณผ IP ์ฃผ์†Œ, ํฌํŠธ๋ฅผ ๋“ฑ๋ก

-์กฐํšŒ: ์„œ๋น„์Šค ์ด๋ฆ„์„ ๊ฐ–๊ณ  ์„œ๋ฒ„ ๋ชฉ๋ก์„ ์กฐํšŒ

Ribbon๊ณผ ์—ฐ๋™ํ•ด ์„œ๋ฒ„ ๋ชฉ๋ก์„ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋‹ค.

Server ์‹œ์ž‘ ์‹œ eureka ์„œ๋ฒ„์— ์ž๋™์œผ๋กœ ์ž์‹ ์˜ ์ƒํƒœ ๋“ฑ๋ก

์ฃผ๊ธฐ์  heartbeat์œผ๋กœ eureka server์— ์ž์‹ ์ด ์‚ด์•„์žˆ์Œ์„ ์•Œ๋ฆผ

server ์ข…๋ฃŒ ์‹œ eureka ์„œ๋ฒ„์— ์ž์‹ ์˜ ์ƒํƒœ ๋ณ€๊ฒฝ ํ˜น์€ ์ž์‹ ์˜ ๋ชฉ๋ก ์‚ญ์ œ

eureka ์ƒ์— ๋“ฑ๋ก๋œ ์ด๋ฆ„์€ “spring.application.name

Ribbon + Eureka in Spring cloud?

ํ•˜๋‚˜์˜ ์„œ๋ฒ„์—๋Š” eureka client ์™€ ribbon client๊ฐ€ ํ•จ๊ป˜ ์„ค์ •๋˜๋ฉด spring cloud๋Š” ๋‹ค์Œ์˜ ribbon bean์„ ๋Œ€์ฒด (์„œ๋ฒ„์˜ ๋ชฉ๋ก์„ ์„ค์ •์œผ๋กœ ๋ช…์‹œํ•˜๋Š” ๋Œ€์‹ , eureka๋ฅผ ํ†ตํ•ด์„œ look upํ•ด์˜ด)

  1. serverList<Server>→ ๋ณ€๊ฒฝ: DiscoverEnableNIWSServerList
  2. -๊ธฐ๋ณธ: ConfigurationBasedServerList
  3. IPing→ ๋ณ€๊ฒฝ: NIWSDiscoveryPing
  4. -๊ธฐ๋ณธ: DummyPing

๐ŸŽˆ API Gateway

msa ํ™˜๊ฒฝ์—์„œ api gateway์˜ ํ•„์š”์„ฑ

  1. single endpoint ์ œ๊ณต
  2. api ๊ณตํ†ต ๋กœ์ง ๊ตฌํ˜„ - logging, authentication, authorization
  3. traffic control - api quota, throttling

๐Ÿ”๋ฌธ์ œ ์ง๋ฉด!

100% ์ž์ฒด ๊ฐœ๋ฐœํ•œ api gateway๋ฅผ ๋‘๊ณ  spring cloud zuul์„ ๋„์ž…ํ•ด์•ผ ํ• ๊นŒ?

→yes!

์ด์œ  : ์„œ๋ฒ„์˜ ๋ชจ๋“  ํ˜ธ์ถœ์€ hystrix command๊ฐ€ ๊ฐ์‹ธ์„œ ํ˜ธ์ถœํ•œ๋‹ค. ๊ทธ ์•ˆ์—๋Š” ribbon client๊ฐ€ ์กด์žฌ. ๊ทธ ์•ˆ์—์„œ eureka client๋ฅผ ํ†ตํ•ด์„œ ์‹ค์ œ ์„œ๋ฒ„๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.

api gateway๋ฅผ ์‚ฌ์šฉํ•ด endpoint ๊ด€๋ฆฌ๋ฅผ ํ•˜์ง€ ์•Š์•„๋„ ๋˜๊ณ , service์— ์˜ค๋ฅ˜๊ฐ€ ๋‚˜๋„ ๋‚ด ๊ฒŒ์ดํŠธ ์›จ์ด๋Š” ์ฃฝ์ง€ ์•Š์„ ์ตœํ›„์˜ ๋ณด๋ฃจ๊ฐ€ ์ƒ๊ธด๋‹ค. circuit breaker์™€ isolation์ด ๋‚ด zuul์˜ ํ•œ ๊ตฐ์ด ์ฃฝ๋”๋ผ๋„ ๊ฒฉ๋ฆฌ ์‹œ์ผœ์ฃผ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. spring cloud zuul ์—์„œ hystrix isolation์€ semaphore์„ ๊ธฐ๋ณธ์œผ๋กœ ํ•œ๋‹ค.


๐ŸŽƒ์žฅ์•  ์‹œ๋‚˜๋ฆฌ์˜ค

hystrix, eureka, ribbon์„ ์‚ฌ์šฉํ•œ ์šฐ๋ฆฌ system์€ ์–ด๋Š ์ •๋„ resilience ํ•œ ๊ฑฐ์•ผ?


๐ŸŽˆ Spring Cloud Sleuth - Logging

spring cloud sleuth ์‚ฌ์šฉ ์‹œ application ๋กœ๊ทธ์— trace Id(uuid)๊ฐ€ ํ•จ๊ป˜ ์ถœ๋ ฅ

with Zipkin !

hystrix with turbin !

MSA๋กœ ์ „ํ–ฅํ•œ 11๋ฒˆ๊ฐ€์˜ ์‚ฌ๋ก€

๐Ÿ“ŒHystrix

netfilx๊ฐ€ ๋งŒ๋“  fault tolerance library๋กœ ์ฃผ๋กœ ์žฅ์•  ์ „ํŒŒ ๋ฐฉ์ง€์™€ resilience ๊ธฐ๋Šฅ์„ ํ•œ๋‹ค.

๐ŸŽจ์ ์šฉ ๋ฐฉ๋ฒ•

  1. Hystrix annotation ์‚ฌ์šฉ - hystrix javanic, spring cloud netfix์— ํฌํ•จ๋˜์–ด ์žˆ์Œ
@HystrixCommand
public String anyMethod() {
}
  1. Hystrix command ์ƒ์†
pulbic class SampleCommand extends HystrixCommand<String> {
@Override
protected String run() {}
}

hystrix command๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ๋ฒŒ์–ด์ง€๋Š” ์ผ

  1. ๋ฉ”์†Œ๋“œ๋ฅผ interceptํ•˜์—ฌ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค - thread isolation
  2. ๋ฉ”์†Œ๋“œ ์‹คํ–‰ ๊ฒฐ๊ณผ ์„ฑ๊ณต ํ˜น์€ ์‹คํŒจ ๋ฐœ์ƒ ์—ฌ๋ถ€๋ฅผ ์ธ์Šคํ„ด์Šค ๋‹จ์œ„๋กœ ๊ธฐ๋กํ•˜๊ณ  ํ†ต๊ณ„๋‚ธ๋‹ค. ํ†ต๊ณ„์— ๋”ฐ๋ผ circuit open ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค. - circuit breaker
  3. ์‹คํŒจํ•œ ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž๊ฐ€ ์ œ๊ณตํ•œ ๋ฉ”์†Œ๋“œ๋ฅผ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค - fallback
  4. ํŠน์ • ์‹œ๊ฐ„๋™์•ˆ ๋ฉ”์†Œ๋“œ๊ฐ€ ์ข…๋ฃŒ๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ exception์„ ๋ฐœ์ƒํ•œ๋‹ค - timeout

๐Ÿ˜ฒ๊ธฐ๋Šฅ์  ๊ด€์ ์—์„œ ๋ณธ Hystrix์˜ ์ฃผ์š” 4๊ฐ€์ง€ ๊ธฐ๋Šฅ

Circuit Breaker

hystrix.command.<commandKey>. //circuitbreaker ์„ ์–ธ 

metrics.rollingStats.timeInMilliseconds - Default 10์ดˆ
circuitBreaker.requestVolumeThreshold - Default 20๊ฐœ
circuitBreaker.errorThresholdPercentage - Default 50%
circuitBreaker.sleepWindowInMilliseconds - Default 5์ดˆ

hystrix command breaker๋Š” ํ•œ ํ”„๋กœ์„ธ์Šค ๋‚ด์—์„œ ์ฃผ์–ด์ง„ CommandKey ๋‹จ์œ„๋กœ ํ†ต๊ณ„๋ฅผ ๋‚ด๊ณ  ๋™์ž‘ํ•œ๋‹ค.

10์ดˆ ๋™์•ˆ 20๊ฐœ ์ด์ƒ์˜ ํ˜ธ์ถœ์ด ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ, 50%์ด์ƒ์˜ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด 5์ดˆ๊ฐ„ ํ˜ธ์ถœ ์ฐจ๋‹จ(circuit open)

์ผ์ • ์‹œ๊ฐ„(10์ดˆ) ๊ฒฝ๊ณผ ํ›„์— ๋‹จ ํ•œ ๊ฐœ์˜ ์š”์ฒญ์— ๋Œ€ํ•ด์„œ ํ˜ธ์ถœ์„ ํ—ˆ์šฉํ•˜๋ฉฐ(Half open), ์ด ํ˜ธ์ถœ์ด ์„ฑ๊ณตํ•˜๋ฉด → Circuit Close(ํ˜ธ์ถœ ํ—ˆ์šฉ)

Fallback

fallback์œผ๋กœ ์ง€์ •๋œ ๋ฉ”์†Œ๋“œ๋Š” ๋‹ค์Œ ๊ฒฝ์šฐ์— ์›๋ณธ ๋ฉ”์†Œ๋“œ๋ฅผ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค.

  1. circuit open
  2. any exception(HystrixBadRequestException ์ œ์™ธ)
  3. Semaphore/ ThreadPoolRejection
  4. Timeout
@HystrixCommand(commandKey = "ExtDep1", fallbackMethod="recommendFallback")
//์ถ”์ฒœ ์„œ๋ฒ„ ํ˜ธ์ถœ
public String anyMethod() {}
//๋ฏธ๋ฆฌ ์ค€๋น„๋œ ์ƒํ’ˆ ๋ชฉ๋ก
public String recommendFallback(){return "<๋ฏธ๋ฆฌ ์ค€๋น„๋œ ์ƒํ’ˆ ๋ชฉ๋ก>"}

๐Ÿงจ exception ํ„ฐ์ง€๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ์ฐพ๊ธฐ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ์Œ. ๋น„์ƒ์‹์ ์œผ๋กœ ์‘๋‹ต์ด ๋น ๋ฅด๋‹ค๋ฉด ๋ณธ ๋ฉ”์†Œ๋“œ(anyMethod)๊ฐ€ ์ œ๋Œ€๋กœ ์ž‘๋™ํ•˜๋Š”์ง€ ๋กœ๊น…ํ•ด ๋ณผ ๊ฒƒ.

๐ŸงจHystrixBadRequestException : ์ด ์˜ค๋ฅ˜๋Š” fallback์„ ์‹คํ–‰ํ•˜์ง€ ์•Š์œผ๋ฉฐ circuit open์„ ์œ„ํ•œ ํ†ต๊ณ„์—๋„ ์ง‘๊ณ„๋˜์ง€ ์•Š๋Š”๋‹ค. ์ž˜๋ชป๋œ ํŒŒ๋ผ๋ฏธํ„ฐ ์ „๋‹ฌ๊ณผ ๊ฐ™์€ method caller์˜ ์‹ค์ˆ˜์˜ ๊ฒฝ์šฐ ์ด ์˜ˆ์™ธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๋งŒ์•ฝ ๋‹ค๋ฅธ ์˜ˆ์™ธ๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค๋ฉด circuit breaker ํ†ต๊ณ„์— ์ง‘๊ณ„๋˜์–ด circuit open์ด ๋˜๊ฑฐ๋‚˜ fallback์ด ์‹คํ–‰๋˜์–ด ๊ฐœ๋ฐœ ๊ณผ์ •์— ์˜ค๋ฅ˜๋ฅผ ์ธ์ง€ํ• ์ง€ ๋ชป ํ•  ์ˆ˜ ์žˆ๋‹ค.

Timeout

hystrix์—์„œ๋Š” circuit breaker ๋‹จ์œ„๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

metrics.rollingStats.timeInMilliseconds - Default 1์ดˆ

๋ณดํ†ต์€ 1์ดˆ ๋ฏธ๋งŒ์œผ๋กœ ์‘๋‹ต์ด ์™€์•ผ ํ•˜์ง€๋งŒ, ui๋กœ์ง์ด ๋ณต์žกํ•˜๊ฑฐ๋‚˜ ๋“ฑ์˜ ์ด์œ ๋กœ ์กฐ๊ธˆ ๋” ๋Š˜๋ ค๋„ ์ข‹๋‹ค.

Isolation

์ตœ๋Œ€ ๊ฐœ์ˆ˜ ์ดˆ๊ณผ ์‹œ semaphore rejection(fallback) ๋ฐœ์ƒํ•œ๋‹ค.

๋‘ ๊ฐ€์ง€ isolation ๋ฐฉ์‹์„ ๋‹จ์œ„ ๋ณ„๋กœ ์ง€์ • ๊ฐ€๋Šฅ

semaphore

circuit breaker 1๊ฐœ๋‹น 1๊ฐœ์˜ semaphore ์ƒ์„ฑํ•˜๊ณ , command๋ฅผ ํ˜ธ์ถœํ•œ caller Thread์—์„œ fallback ๋ฉ”์†Œ๋“œ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค. ๐Ÿงจtimeout์ด ์ œ ์‹œ๊ฐ„์— ๋ฐœ์ƒํ•˜์ง€ ๋ชปํ•œ๋‹ค๋Š” ๋‹จ์ ์ด.. ์ด๊ฒƒ์€ ์Šค๋ž˜๋“œ๋กœ ํ•ด๊ฒฐ ๊ฐ€๋Šฅ

thread(default)

circuit breaker ๋ณ„๋กœ ์‚ฌ์šฉํ•  thread pool ์ง€์ •(ThreadPoolKey)

command๋ฅผ ํ˜ธ์ถœํ•œ thread๊ฐ€ ์•„๋‹Œ, thread pool์—์„œ fallback ๋ฉ”์†Œ๋“œ ์‹คํ–‰.


๐Ÿ“ŒRibbon

netflix๊ฐ€ ๋งŒ๋“  software load balancer๋ฅผ ๋‚ด์žฅํ•œ RPC library

-Client Load Balancer with HTTP Client

API์ฝœ๋Ÿฌ๋“ค์— ์ž๋™์œผ๋กœ ribbon client๊ฐ€ ๋ถ™๊ฒŒ ๋˜๋ฉด, ์ธํ”„๋ผ์˜ ๋„์›€ ์—†์ด๋„ ๋‹ค์ˆ˜์˜ ์„œ๋ฒ„ ๋ชฉ๋ก์„ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ•˜์ง€๋งŒ ์Šคํ”„๋ง ํด๋ผ์šฐ๋“œ์—์„œ๋Š” ribbon ํด๋ผ์ด์–ธํŠธ๋ฅผ ์‚ฌ์šฉ์ž๊ฐ€ ์ง์ ‘ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Œ! ์Šคํ”„๋ง ํด๋ผ์šฐ๋“œ์—๋Š” http ํ†ต์‹ ์ด ํ•„์š”ํ•œ ์š”์†Œ๊ฐ€ ๋‚ด์žฅ๋˜์–ด ์žˆ์Œ. (api gateway, feign, restTemplate(@LoadBalanced))


๐Ÿ“ŒEureka

netflix๊ฐ€ ๋งŒ๋“  dynamic service discovery

-๋“ฑ๋ก: ์„œ๋ฒ„๊ฐ€ ์ž์‹ ์˜ ์„œ๋น„์Šค ์ด๋ฆ„๊ณผ IP ์ฃผ์†Œ, ํฌํŠธ๋ฅผ ๋“ฑ๋ก

-์กฐํšŒ: ์„œ๋น„์Šค ์ด๋ฆ„์„ ๊ฐ–๊ณ  ์„œ๋ฒ„ ๋ชฉ๋ก์„ ์กฐํšŒ

Ribbon๊ณผ ์—ฐ๋™ํ•ด ์„œ๋ฒ„ ๋ชฉ๋ก์„ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋‹ค.

Server ์‹œ์ž‘ ์‹œ eureka ์„œ๋ฒ„์— ์ž๋™์œผ๋กœ ์ž์‹ ์˜ ์ƒํƒœ ๋“ฑ๋ก

์ฃผ๊ธฐ์  heartbeat์œผ๋กœ eureka server์— ์ž์‹ ์ด ์‚ด์•„์žˆ์Œ์„ ์•Œ๋ฆผ

server ์ข…๋ฃŒ ์‹œ eureka ์„œ๋ฒ„์— ์ž์‹ ์˜ ์ƒํƒœ ๋ณ€๊ฒฝ ํ˜น์€ ์ž์‹ ์˜ ๋ชฉ๋ก ์‚ญ์ œ

eureka ์ƒ์— ๋“ฑ๋ก๋œ ์ด๋ฆ„์€ “spring.application.name

Ribbon + Eureka in Spring cloud?

ํ•˜๋‚˜์˜ ์„œ๋ฒ„์—๋Š” eureka client ์™€ ribbon client๊ฐ€ ํ•จ๊ป˜ ์„ค์ •๋˜๋ฉด spring cloud๋Š” ๋‹ค์Œ์˜ ribbon bean์„ ๋Œ€์ฒด (์„œ๋ฒ„์˜ ๋ชฉ๋ก์„ ์„ค์ •์œผ๋กœ ๋ช…์‹œํ•˜๋Š” ๋Œ€์‹ , eureka๋ฅผ ํ†ตํ•ด์„œ look upํ•ด์˜ด)

  1. serverList<Server>→ ๋ณ€๊ฒฝ: DiscoverEnableNIWSServerList
  2. -๊ธฐ๋ณธ: ConfigurationBasedServerList
  3. IPing→ ๋ณ€๊ฒฝ: NIWSDiscoveryPing
  4. -๊ธฐ๋ณธ: DummyPing

๐ŸŽˆ API Gateway

msa ํ™˜๊ฒฝ์—์„œ api gateway์˜ ํ•„์š”์„ฑ

  1. single endpoint ์ œ๊ณต
  2. api ๊ณตํ†ต ๋กœ์ง ๊ตฌํ˜„ - logging, authentication, authorization
  3. traffic control - api quota, throttling

๐Ÿ”๋ฌธ์ œ ์ง๋ฉด!

100% ์ž์ฒด ๊ฐœ๋ฐœํ•œ api gateway๋ฅผ ๋‘๊ณ  spring cloud zuul์„ ๋„์ž…ํ•ด์•ผ ํ• ๊นŒ?

→yes!

์ด์œ  : ์„œ๋ฒ„์˜ ๋ชจ๋“  ํ˜ธ์ถœ์€ hystrix command๊ฐ€ ๊ฐ์‹ธ์„œ ํ˜ธ์ถœํ•œ๋‹ค. ๊ทธ ์•ˆ์—๋Š” ribbon client๊ฐ€ ์กด์žฌ. ๊ทธ ์•ˆ์—์„œ eureka client๋ฅผ ํ†ตํ•ด์„œ ์‹ค์ œ ์„œ๋ฒ„๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.

api gateway๋ฅผ ์‚ฌ์šฉํ•ด endpoint ๊ด€๋ฆฌ๋ฅผ ํ•˜์ง€ ์•Š์•„๋„ ๋˜๊ณ , service์— ์˜ค๋ฅ˜๊ฐ€ ๋‚˜๋„ ๋‚ด ๊ฒŒ์ดํŠธ ์›จ์ด๋Š” ์ฃฝ์ง€ ์•Š์„ ์ตœํ›„์˜ ๋ณด๋ฃจ๊ฐ€ ์ƒ๊ธด๋‹ค. circuit breaker์™€ isolation์ด ๋‚ด zuul์˜ ํ•œ ๊ตฐ์ด ์ฃฝ๋”๋ผ๋„ ๊ฒฉ๋ฆฌ ์‹œ์ผœ์ฃผ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. spring cloud zuul ์—์„œ hystrix isolation์€ semaphore์„ ๊ธฐ๋ณธ์œผ๋กœ ํ•œ๋‹ค.


๐ŸŽƒ์žฅ์•  ์‹œ๋‚˜๋ฆฌ์˜ค

hystrix, eureka, ribbon์„ ์‚ฌ์šฉํ•œ ์šฐ๋ฆฌ system์€ ์–ด๋Š ์ •๋„ resilience ํ•œ ๊ฑฐ์•ผ?


๐ŸŽˆ Spring Cloud Sleuth - Logging

spring cloud sleuth ์‚ฌ์šฉ ์‹œ application ๋กœ๊ทธ์— trace Id(uuid)๊ฐ€ ํ•จ๊ป˜ ์ถœ๋ ฅ

with Zipkin !

hystrix with turbin !

MSA๋กœ ์ „ํ–ฅํ•œ 11๋ฒˆ๊ฐ€์˜ ์‚ฌ๋ก€

๐Ÿ“ŒHystrix

netfilx๊ฐ€ ๋งŒ๋“  fault tolerance library๋กœ ์ฃผ๋กœ ์žฅ์•  ์ „ํŒŒ ๋ฐฉ์ง€์™€ resilience ๊ธฐ๋Šฅ์„ ํ•œ๋‹ค.

๐ŸŽจ์ ์šฉ ๋ฐฉ๋ฒ•

  1. Hystrix annotation ์‚ฌ์šฉ - hystrix javanic, spring cloud netfix์— ํฌํ•จ๋˜์–ด ์žˆ์Œ
@HystrixCommand
public String anyMethod() {
}
  1. Hystrix command ์ƒ์†
pulbic class SampleCommand extends HystrixCommand<String> {
@Override
protected String run() {}
}

hystrix command๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ๋ฒŒ์–ด์ง€๋Š” ์ผ

  1. ๋ฉ”์†Œ๋“œ๋ฅผ interceptํ•˜์—ฌ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค - thread isolation
  2. ๋ฉ”์†Œ๋“œ ์‹คํ–‰ ๊ฒฐ๊ณผ ์„ฑ๊ณต ํ˜น์€ ์‹คํŒจ ๋ฐœ์ƒ ์—ฌ๋ถ€๋ฅผ ์ธ์Šคํ„ด์Šค ๋‹จ์œ„๋กœ ๊ธฐ๋กํ•˜๊ณ  ํ†ต๊ณ„๋‚ธ๋‹ค. ํ†ต๊ณ„์— ๋”ฐ๋ผ circuit open ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค. - circuit breaker
  3. ์‹คํŒจํ•œ ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž๊ฐ€ ์ œ๊ณตํ•œ ๋ฉ”์†Œ๋“œ๋ฅผ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค - fallback
  4. ํŠน์ • ์‹œ๊ฐ„๋™์•ˆ ๋ฉ”์†Œ๋“œ๊ฐ€ ์ข…๋ฃŒ๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ exception์„ ๋ฐœ์ƒํ•œ๋‹ค - timeout

๐Ÿ˜ฒ๊ธฐ๋Šฅ์  ๊ด€์ ์—์„œ ๋ณธ Hystrix์˜ ์ฃผ์š” 4๊ฐ€์ง€ ๊ธฐ๋Šฅ

Circuit Breaker

hystrix.command.<commandKey>. //circuitbreaker ์„ ์–ธ 

metrics.rollingStats.timeInMilliseconds - Default 10์ดˆ
circuitBreaker.requestVolumeThreshold - Default 20๊ฐœ
circuitBreaker.errorThresholdPercentage - Default 50%
circuitBreaker.sleepWindowInMilliseconds - Default 5์ดˆ

hystrix command breaker๋Š” ํ•œ ํ”„๋กœ์„ธ์Šค ๋‚ด์—์„œ ์ฃผ์–ด์ง„ CommandKey ๋‹จ์œ„๋กœ ํ†ต๊ณ„๋ฅผ ๋‚ด๊ณ  ๋™์ž‘ํ•œ๋‹ค.

10์ดˆ ๋™์•ˆ 20๊ฐœ ์ด์ƒ์˜ ํ˜ธ์ถœ์ด ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ, 50%์ด์ƒ์˜ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด 5์ดˆ๊ฐ„ ํ˜ธ์ถœ ์ฐจ๋‹จ(circuit open)

์ผ์ • ์‹œ๊ฐ„(10์ดˆ) ๊ฒฝ๊ณผ ํ›„์— ๋‹จ ํ•œ ๊ฐœ์˜ ์š”์ฒญ์— ๋Œ€ํ•ด์„œ ํ˜ธ์ถœ์„ ํ—ˆ์šฉํ•˜๋ฉฐ(Half open), ์ด ํ˜ธ์ถœ์ด ์„ฑ๊ณตํ•˜๋ฉด → Circuit Close(ํ˜ธ์ถœ ํ—ˆ์šฉ)

Fallback

fallback์œผ๋กœ ์ง€์ •๋œ ๋ฉ”์†Œ๋“œ๋Š” ๋‹ค์Œ ๊ฒฝ์šฐ์— ์›๋ณธ ๋ฉ”์†Œ๋“œ๋ฅผ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค.

  1. circuit open
  2. any exception(HystrixBadRequestException ์ œ์™ธ)
  3. Semaphore/ ThreadPoolRejection
  4. Timeout
@HystrixCommand(commandKey = "ExtDep1", fallbackMethod="recommendFallback")
//์ถ”์ฒœ ์„œ๋ฒ„ ํ˜ธ์ถœ
public String anyMethod() {}
//๋ฏธ๋ฆฌ ์ค€๋น„๋œ ์ƒํ’ˆ ๋ชฉ๋ก
public String recommendFallback(){return "<๋ฏธ๋ฆฌ ์ค€๋น„๋œ ์ƒํ’ˆ ๋ชฉ๋ก>"}

๐Ÿงจ exception ํ„ฐ์ง€๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ์ฐพ๊ธฐ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ์Œ. ๋น„์ƒ์‹์ ์œผ๋กœ ์‘๋‹ต์ด ๋น ๋ฅด๋‹ค๋ฉด ๋ณธ ๋ฉ”์†Œ๋“œ(anyMethod)๊ฐ€ ์ œ๋Œ€๋กœ ์ž‘๋™ํ•˜๋Š”์ง€ ๋กœ๊น…ํ•ด ๋ณผ ๊ฒƒ.

๐ŸงจHystrixBadRequestException : ์ด ์˜ค๋ฅ˜๋Š” fallback์„ ์‹คํ–‰ํ•˜์ง€ ์•Š์œผ๋ฉฐ circuit open์„ ์œ„ํ•œ ํ†ต๊ณ„์—๋„ ์ง‘๊ณ„๋˜์ง€ ์•Š๋Š”๋‹ค. ์ž˜๋ชป๋œ ํŒŒ๋ผ๋ฏธํ„ฐ ์ „๋‹ฌ๊ณผ ๊ฐ™์€ method caller์˜ ์‹ค์ˆ˜์˜ ๊ฒฝ์šฐ ์ด ์˜ˆ์™ธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๋งŒ์•ฝ ๋‹ค๋ฅธ ์˜ˆ์™ธ๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค๋ฉด circuit breaker ํ†ต๊ณ„์— ์ง‘๊ณ„๋˜์–ด circuit open์ด ๋˜๊ฑฐ๋‚˜ fallback์ด ์‹คํ–‰๋˜์–ด ๊ฐœ๋ฐœ ๊ณผ์ •์— ์˜ค๋ฅ˜๋ฅผ ์ธ์ง€ํ• ์ง€ ๋ชป ํ•  ์ˆ˜ ์žˆ๋‹ค.

Timeout

hystrix์—์„œ๋Š” circuit breaker ๋‹จ์œ„๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

metrics.rollingStats.timeInMilliseconds - Default 1์ดˆ

๋ณดํ†ต์€ 1์ดˆ ๋ฏธ๋งŒ์œผ๋กœ ์‘๋‹ต์ด ์™€์•ผ ํ•˜์ง€๋งŒ, ui๋กœ์ง์ด ๋ณต์žกํ•˜๊ฑฐ๋‚˜ ๋“ฑ์˜ ์ด์œ ๋กœ ์กฐ๊ธˆ ๋” ๋Š˜๋ ค๋„ ์ข‹๋‹ค.

Isolation

์ตœ๋Œ€ ๊ฐœ์ˆ˜ ์ดˆ๊ณผ ์‹œ semaphore rejection(fallback) ๋ฐœ์ƒํ•œ๋‹ค.

๋‘ ๊ฐ€์ง€ isolation ๋ฐฉ์‹์„ ๋‹จ์œ„ ๋ณ„๋กœ ์ง€์ • ๊ฐ€๋Šฅ

semaphore

circuit breaker 1๊ฐœ๋‹น 1๊ฐœ์˜ semaphore ์ƒ์„ฑํ•˜๊ณ , command๋ฅผ ํ˜ธ์ถœํ•œ caller Thread์—์„œ fallback ๋ฉ”์†Œ๋“œ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค. ๐Ÿงจtimeout์ด ์ œ ์‹œ๊ฐ„์— ๋ฐœ์ƒํ•˜์ง€ ๋ชปํ•œ๋‹ค๋Š” ๋‹จ์ ์ด.. ์ด๊ฒƒ์€ ์Šค๋ž˜๋“œ๋กœ ํ•ด๊ฒฐ ๊ฐ€๋Šฅ

thread(default)

circuit breaker ๋ณ„๋กœ ์‚ฌ์šฉํ•  thread pool ์ง€์ •(ThreadPoolKey)

command๋ฅผ ํ˜ธ์ถœํ•œ thread๊ฐ€ ์•„๋‹Œ, thread pool์—์„œ fallback ๋ฉ”์†Œ๋“œ ์‹คํ–‰.


๐Ÿ“ŒRibbon

netflix๊ฐ€ ๋งŒ๋“  software load balancer๋ฅผ ๋‚ด์žฅํ•œ RPC library

-Client Load Balancer with HTTP Client

API์ฝœ๋Ÿฌ๋“ค์— ์ž๋™์œผ๋กœ ribbon client๊ฐ€ ๋ถ™๊ฒŒ ๋˜๋ฉด, ์ธํ”„๋ผ์˜ ๋„์›€ ์—†์ด๋„ ๋‹ค์ˆ˜์˜ ์„œ๋ฒ„ ๋ชฉ๋ก์„ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ•˜์ง€๋งŒ ์Šคํ”„๋ง ํด๋ผ์šฐ๋“œ์—์„œ๋Š” ribbon ํด๋ผ์ด์–ธํŠธ๋ฅผ ์‚ฌ์šฉ์ž๊ฐ€ ์ง์ ‘ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Œ! ์Šคํ”„๋ง ํด๋ผ์šฐ๋“œ์—๋Š” http ํ†ต์‹ ์ด ํ•„์š”ํ•œ ์š”์†Œ๊ฐ€ ๋‚ด์žฅ๋˜์–ด ์žˆ์Œ. (api gateway, feign, restTemplate(@LoadBalanced))


๐Ÿ“ŒEureka

netflix๊ฐ€ ๋งŒ๋“  dynamic service discovery

-๋“ฑ๋ก: ์„œ๋ฒ„๊ฐ€ ์ž์‹ ์˜ ์„œ๋น„์Šค ์ด๋ฆ„๊ณผ IP ์ฃผ์†Œ, ํฌํŠธ๋ฅผ ๋“ฑ๋ก

-์กฐํšŒ: ์„œ๋น„์Šค ์ด๋ฆ„์„ ๊ฐ–๊ณ  ์„œ๋ฒ„ ๋ชฉ๋ก์„ ์กฐํšŒ

Ribbon๊ณผ ์—ฐ๋™ํ•ด ์„œ๋ฒ„ ๋ชฉ๋ก์„ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋‹ค.

Server ์‹œ์ž‘ ์‹œ eureka ์„œ๋ฒ„์— ์ž๋™์œผ๋กœ ์ž์‹ ์˜ ์ƒํƒœ ๋“ฑ๋ก

์ฃผ๊ธฐ์  heartbeat์œผ๋กœ eureka server์— ์ž์‹ ์ด ์‚ด์•„์žˆ์Œ์„ ์•Œ๋ฆผ

server ์ข…๋ฃŒ ์‹œ eureka ์„œ๋ฒ„์— ์ž์‹ ์˜ ์ƒํƒœ ๋ณ€๊ฒฝ ํ˜น์€ ์ž์‹ ์˜ ๋ชฉ๋ก ์‚ญ์ œ

eureka ์ƒ์— ๋“ฑ๋ก๋œ ์ด๋ฆ„์€ “spring.application.name

Ribbon + Eureka in Spring cloud?

ํ•˜๋‚˜์˜ ์„œ๋ฒ„์—๋Š” eureka client ์™€ ribbon client๊ฐ€ ํ•จ๊ป˜ ์„ค์ •๋˜๋ฉด spring cloud๋Š” ๋‹ค์Œ์˜ ribbon bean์„ ๋Œ€์ฒด (์„œ๋ฒ„์˜ ๋ชฉ๋ก์„ ์„ค์ •์œผ๋กœ ๋ช…์‹œํ•˜๋Š” ๋Œ€์‹ , eureka๋ฅผ ํ†ตํ•ด์„œ look upํ•ด์˜ด)

  1. serverList<Server>→ ๋ณ€๊ฒฝ: DiscoverEnableNIWSServerList
  2. -๊ธฐ๋ณธ: ConfigurationBasedServerList
  3. IPing→ ๋ณ€๊ฒฝ: NIWSDiscoveryPing
  4. -๊ธฐ๋ณธ: DummyPing

๐ŸŽˆ API Gateway

msa ํ™˜๊ฒฝ์—์„œ api gateway์˜ ํ•„์š”์„ฑ

  1. single endpoint ์ œ๊ณต
  2. api ๊ณตํ†ต ๋กœ์ง ๊ตฌํ˜„ - logging, authentication, authorization
  3. traffic control - api quota, throttling

๐Ÿ”๋ฌธ์ œ ์ง๋ฉด!

100% ์ž์ฒด ๊ฐœ๋ฐœํ•œ api gateway๋ฅผ ๋‘๊ณ  spring cloud zuul์„ ๋„์ž…ํ•ด์•ผ ํ• ๊นŒ?

→yes!

์ด์œ  : ์„œ๋ฒ„์˜ ๋ชจ๋“  ํ˜ธ์ถœ์€ hystrix command๊ฐ€ ๊ฐ์‹ธ์„œ ํ˜ธ์ถœํ•œ๋‹ค. ๊ทธ ์•ˆ์—๋Š” ribbon client๊ฐ€ ์กด์žฌ. ๊ทธ ์•ˆ์—์„œ eureka client๋ฅผ ํ†ตํ•ด์„œ ์‹ค์ œ ์„œ๋ฒ„๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.

api gateway๋ฅผ ์‚ฌ์šฉํ•ด endpoint ๊ด€๋ฆฌ๋ฅผ ํ•˜์ง€ ์•Š์•„๋„ ๋˜๊ณ , service์— ์˜ค๋ฅ˜๊ฐ€ ๋‚˜๋„ ๋‚ด ๊ฒŒ์ดํŠธ ์›จ์ด๋Š” ์ฃฝ์ง€ ์•Š์„ ์ตœํ›„์˜ ๋ณด๋ฃจ๊ฐ€ ์ƒ๊ธด๋‹ค. circuit breaker์™€ isolation์ด ๋‚ด zuul์˜ ํ•œ ๊ตฐ์ด ์ฃฝ๋”๋ผ๋„ ๊ฒฉ๋ฆฌ ์‹œ์ผœ์ฃผ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. spring cloud zuul ์—์„œ hystrix isolation์€ semaphore์„ ๊ธฐ๋ณธ์œผ๋กœ ํ•œ๋‹ค.


๐ŸŽƒ์žฅ์•  ์‹œ๋‚˜๋ฆฌ์˜ค

hystrix, eureka, ribbon์„ ์‚ฌ์šฉํ•œ ์šฐ๋ฆฌ system์€ ์–ด๋Š ์ •๋„ resilience ํ•œ ๊ฑฐ์•ผ?


๐ŸŽˆ Spring Cloud Sleuth - Logging

spring cloud sleuth ์‚ฌ์šฉ ์‹œ application ๋กœ๊ทธ์— trace Id(uuid)๊ฐ€ ํ•จ๊ป˜ ์ถœ๋ ฅ

with Zipkin !

hystrix with turbin !

MSA๋กœ ์ „ํ–ฅํ•œ 11๋ฒˆ๊ฐ€์˜ ์‚ฌ๋ก€

๐Ÿ“ŒHystrix

netfilx๊ฐ€ ๋งŒ๋“  fault tolerance library๋กœ ์ฃผ๋กœ ์žฅ์•  ์ „ํŒŒ ๋ฐฉ์ง€์™€ resilience ๊ธฐ๋Šฅ์„ ํ•œ๋‹ค.

๐ŸŽจ์ ์šฉ ๋ฐฉ๋ฒ•

  1. Hystrix annotation ์‚ฌ์šฉ - hystrix javanic, spring cloud netfix์— ํฌํ•จ๋˜์–ด ์žˆ์Œ
@HystrixCommand
public String anyMethod() {
}
  1. Hystrix command ์ƒ์†
pulbic class SampleCommand extends HystrixCommand<String> {
@Override
protected String run() {}
}

hystrix command๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ๋ฒŒ์–ด์ง€๋Š” ์ผ

  1. ๋ฉ”์†Œ๋“œ๋ฅผ interceptํ•˜์—ฌ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค - thread isolation
  2. ๋ฉ”์†Œ๋“œ ์‹คํ–‰ ๊ฒฐ๊ณผ ์„ฑ๊ณต ํ˜น์€ ์‹คํŒจ ๋ฐœ์ƒ ์—ฌ๋ถ€๋ฅผ ์ธ์Šคํ„ด์Šค ๋‹จ์œ„๋กœ ๊ธฐ๋กํ•˜๊ณ  ํ†ต๊ณ„๋‚ธ๋‹ค. ํ†ต๊ณ„์— ๋”ฐ๋ผ circuit open ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค. - circuit breaker
  3. ์‹คํŒจํ•œ ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž๊ฐ€ ์ œ๊ณตํ•œ ๋ฉ”์†Œ๋“œ๋ฅผ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค - fallback
  4. ํŠน์ • ์‹œ๊ฐ„๋™์•ˆ ๋ฉ”์†Œ๋“œ๊ฐ€ ์ข…๋ฃŒ๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ exception์„ ๋ฐœ์ƒํ•œ๋‹ค - timeout

๐Ÿ˜ฒ๊ธฐ๋Šฅ์  ๊ด€์ ์—์„œ ๋ณธ Hystrix์˜ ์ฃผ์š” 4๊ฐ€์ง€ ๊ธฐ๋Šฅ

Circuit Breaker

hystrix.command.<commandKey>. //circuitbreaker ์„ ์–ธ 

metrics.rollingStats.timeInMilliseconds - Default 10์ดˆ
circuitBreaker.requestVolumeThreshold - Default 20๊ฐœ
circuitBreaker.errorThresholdPercentage - Default 50%
circuitBreaker.sleepWindowInMilliseconds - Default 5์ดˆ

hystrix command breaker๋Š” ํ•œ ํ”„๋กœ์„ธ์Šค ๋‚ด์—์„œ ์ฃผ์–ด์ง„ CommandKey ๋‹จ์œ„๋กœ ํ†ต๊ณ„๋ฅผ ๋‚ด๊ณ  ๋™์ž‘ํ•œ๋‹ค.

10์ดˆ ๋™์•ˆ 20๊ฐœ ์ด์ƒ์˜ ํ˜ธ์ถœ์ด ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ, 50%์ด์ƒ์˜ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด 5์ดˆ๊ฐ„ ํ˜ธ์ถœ ์ฐจ๋‹จ(circuit open)

์ผ์ • ์‹œ๊ฐ„(10์ดˆ) ๊ฒฝ๊ณผ ํ›„์— ๋‹จ ํ•œ ๊ฐœ์˜ ์š”์ฒญ์— ๋Œ€ํ•ด์„œ ํ˜ธ์ถœ์„ ํ—ˆ์šฉํ•˜๋ฉฐ(Half open), ์ด ํ˜ธ์ถœ์ด ์„ฑ๊ณตํ•˜๋ฉด → Circuit Close(ํ˜ธ์ถœ ํ—ˆ์šฉ)

Fallback

fallback์œผ๋กœ ์ง€์ •๋œ ๋ฉ”์†Œ๋“œ๋Š” ๋‹ค์Œ ๊ฒฝ์šฐ์— ์›๋ณธ ๋ฉ”์†Œ๋“œ๋ฅผ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค.

  1. circuit open
  2. any exception(HystrixBadRequestException ์ œ์™ธ)
  3. Semaphore/ ThreadPoolRejection
  4. Timeout
@HystrixCommand(commandKey = "ExtDep1", fallbackMethod="recommendFallback")
//์ถ”์ฒœ ์„œ๋ฒ„ ํ˜ธ์ถœ
public String anyMethod() {}
//๋ฏธ๋ฆฌ ์ค€๋น„๋œ ์ƒํ’ˆ ๋ชฉ๋ก
public String recommendFallback(){return "<๋ฏธ๋ฆฌ ์ค€๋น„๋œ ์ƒํ’ˆ ๋ชฉ๋ก>"}

๐Ÿงจ exception ํ„ฐ์ง€๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ์ฐพ๊ธฐ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ์Œ. ๋น„์ƒ์‹์ ์œผ๋กœ ์‘๋‹ต์ด ๋น ๋ฅด๋‹ค๋ฉด ๋ณธ ๋ฉ”์†Œ๋“œ(anyMethod)๊ฐ€ ์ œ๋Œ€๋กœ ์ž‘๋™ํ•˜๋Š”์ง€ ๋กœ๊น…ํ•ด ๋ณผ ๊ฒƒ.

๐ŸงจHystrixBadRequestException : ์ด ์˜ค๋ฅ˜๋Š” fallback์„ ์‹คํ–‰ํ•˜์ง€ ์•Š์œผ๋ฉฐ circuit open์„ ์œ„ํ•œ ํ†ต๊ณ„์—๋„ ์ง‘๊ณ„๋˜์ง€ ์•Š๋Š”๋‹ค. ์ž˜๋ชป๋œ ํŒŒ๋ผ๋ฏธํ„ฐ ์ „๋‹ฌ๊ณผ ๊ฐ™์€ method caller์˜ ์‹ค์ˆ˜์˜ ๊ฒฝ์šฐ ์ด ์˜ˆ์™ธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๋งŒ์•ฝ ๋‹ค๋ฅธ ์˜ˆ์™ธ๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค๋ฉด circuit breaker ํ†ต๊ณ„์— ์ง‘๊ณ„๋˜์–ด circuit open์ด ๋˜๊ฑฐ๋‚˜ fallback์ด ์‹คํ–‰๋˜์–ด ๊ฐœ๋ฐœ ๊ณผ์ •์— ์˜ค๋ฅ˜๋ฅผ ์ธ์ง€ํ• ์ง€ ๋ชป ํ•  ์ˆ˜ ์žˆ๋‹ค.

Timeout

hystrix์—์„œ๋Š” circuit breaker ๋‹จ์œ„๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

metrics.rollingStats.timeInMilliseconds - Default 1์ดˆ

๋ณดํ†ต์€ 1์ดˆ ๋ฏธ๋งŒ์œผ๋กœ ์‘๋‹ต์ด ์™€์•ผ ํ•˜์ง€๋งŒ, ui๋กœ์ง์ด ๋ณต์žกํ•˜๊ฑฐ๋‚˜ ๋“ฑ์˜ ์ด์œ ๋กœ ์กฐ๊ธˆ ๋” ๋Š˜๋ ค๋„ ์ข‹๋‹ค.

Isolation

์ตœ๋Œ€ ๊ฐœ์ˆ˜ ์ดˆ๊ณผ ์‹œ semaphore rejection(fallback) ๋ฐœ์ƒํ•œ๋‹ค.

๋‘ ๊ฐ€์ง€ isolation ๋ฐฉ์‹์„ ๋‹จ์œ„ ๋ณ„๋กœ ์ง€์ • ๊ฐ€๋Šฅ

semaphore

circuit breaker 1๊ฐœ๋‹น 1๊ฐœ์˜ semaphore ์ƒ์„ฑํ•˜๊ณ , command๋ฅผ ํ˜ธ์ถœํ•œ caller Thread์—์„œ fallback ๋ฉ”์†Œ๋“œ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค. ๐Ÿงจtimeout์ด ์ œ ์‹œ๊ฐ„์— ๋ฐœ์ƒํ•˜์ง€ ๋ชปํ•œ๋‹ค๋Š” ๋‹จ์ ์ด.. ์ด๊ฒƒ์€ ์Šค๋ž˜๋“œ๋กœ ํ•ด๊ฒฐ ๊ฐ€๋Šฅ

thread(default)

circuit breaker ๋ณ„๋กœ ์‚ฌ์šฉํ•  thread pool ์ง€์ •(ThreadPoolKey)

command๋ฅผ ํ˜ธ์ถœํ•œ thread๊ฐ€ ์•„๋‹Œ, thread pool์—์„œ fallback ๋ฉ”์†Œ๋“œ ์‹คํ–‰.


๐Ÿ“ŒRibbon

netflix๊ฐ€ ๋งŒ๋“  software load balancer๋ฅผ ๋‚ด์žฅํ•œ RPC library

-Client Load Balancer with HTTP Client

API์ฝœ๋Ÿฌ๋“ค์— ์ž๋™์œผ๋กœ ribbon client๊ฐ€ ๋ถ™๊ฒŒ ๋˜๋ฉด, ์ธํ”„๋ผ์˜ ๋„์›€ ์—†์ด๋„ ๋‹ค์ˆ˜์˜ ์„œ๋ฒ„ ๋ชฉ๋ก์„ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ•˜์ง€๋งŒ ์Šคํ”„๋ง ํด๋ผ์šฐ๋“œ์—์„œ๋Š” ribbon ํด๋ผ์ด์–ธํŠธ๋ฅผ ์‚ฌ์šฉ์ž๊ฐ€ ์ง์ ‘ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Œ! ์Šคํ”„๋ง ํด๋ผ์šฐ๋“œ์—๋Š” http ํ†ต์‹ ์ด ํ•„์š”ํ•œ ์š”์†Œ๊ฐ€ ๋‚ด์žฅ๋˜์–ด ์žˆ์Œ. (api gateway, feign, restTemplate(@LoadBalanced))


๐Ÿ“ŒEureka

netflix๊ฐ€ ๋งŒ๋“  dynamic service discovery

-๋“ฑ๋ก: ์„œ๋ฒ„๊ฐ€ ์ž์‹ ์˜ ์„œ๋น„์Šค ์ด๋ฆ„๊ณผ IP ์ฃผ์†Œ, ํฌํŠธ๋ฅผ ๋“ฑ๋ก

-์กฐํšŒ: ์„œ๋น„์Šค ์ด๋ฆ„์„ ๊ฐ–๊ณ  ์„œ๋ฒ„ ๋ชฉ๋ก์„ ์กฐํšŒ

Ribbon๊ณผ ์—ฐ๋™ํ•ด ์„œ๋ฒ„ ๋ชฉ๋ก์„ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋‹ค.

Server ์‹œ์ž‘ ์‹œ eureka ์„œ๋ฒ„์— ์ž๋™์œผ๋กœ ์ž์‹ ์˜ ์ƒํƒœ ๋“ฑ๋ก

์ฃผ๊ธฐ์  heartbeat์œผ๋กœ eureka server์— ์ž์‹ ์ด ์‚ด์•„์žˆ์Œ์„ ์•Œ๋ฆผ

server ์ข…๋ฃŒ ์‹œ eureka ์„œ๋ฒ„์— ์ž์‹ ์˜ ์ƒํƒœ ๋ณ€๊ฒฝ ํ˜น์€ ์ž์‹ ์˜ ๋ชฉ๋ก ์‚ญ์ œ

eureka ์ƒ์— ๋“ฑ๋ก๋œ ์ด๋ฆ„์€ “spring.application.name

Ribbon + Eureka in Spring cloud?

ํ•˜๋‚˜์˜ ์„œ๋ฒ„์—๋Š” eureka client ์™€ ribbon client๊ฐ€ ํ•จ๊ป˜ ์„ค์ •๋˜๋ฉด spring cloud๋Š” ๋‹ค์Œ์˜ ribbon bean์„ ๋Œ€์ฒด (์„œ๋ฒ„์˜ ๋ชฉ๋ก์„ ์„ค์ •์œผ๋กœ ๋ช…์‹œํ•˜๋Š” ๋Œ€์‹ , eureka๋ฅผ ํ†ตํ•ด์„œ look upํ•ด์˜ด)

  1. serverList<Server>→ ๋ณ€๊ฒฝ: DiscoverEnableNIWSServerList
  2. -๊ธฐ๋ณธ: ConfigurationBasedServerList
  3. IPing→ ๋ณ€๊ฒฝ: NIWSDiscoveryPing
  4. -๊ธฐ๋ณธ: DummyPing

๐ŸŽˆ API Gateway

msa ํ™˜๊ฒฝ์—์„œ api gateway์˜ ํ•„์š”์„ฑ

  1. single endpoint ์ œ๊ณต
  2. api ๊ณตํ†ต ๋กœ์ง ๊ตฌํ˜„ - logging, authentication, authorization
  3. traffic control - api quota, throttling

๐Ÿ”๋ฌธ์ œ ์ง๋ฉด!

100% ์ž์ฒด ๊ฐœ๋ฐœํ•œ api gateway๋ฅผ ๋‘๊ณ  spring cloud zuul์„ ๋„์ž…ํ•ด์•ผ ํ• ๊นŒ?

→yes!

์ด์œ  : ์„œ๋ฒ„์˜ ๋ชจ๋“  ํ˜ธ์ถœ์€ hystrix command๊ฐ€ ๊ฐ์‹ธ์„œ ํ˜ธ์ถœํ•œ๋‹ค. ๊ทธ ์•ˆ์—๋Š” ribbon client๊ฐ€ ์กด์žฌ. ๊ทธ ์•ˆ์—์„œ eureka client๋ฅผ ํ†ตํ•ด์„œ ์‹ค์ œ ์„œ๋ฒ„๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.

api gateway๋ฅผ ์‚ฌ์šฉํ•ด endpoint ๊ด€๋ฆฌ๋ฅผ ํ•˜์ง€ ์•Š์•„๋„ ๋˜๊ณ , service์— ์˜ค๋ฅ˜๊ฐ€ ๋‚˜๋„ ๋‚ด ๊ฒŒ์ดํŠธ ์›จ์ด๋Š” ์ฃฝ์ง€ ์•Š์„ ์ตœํ›„์˜ ๋ณด๋ฃจ๊ฐ€ ์ƒ๊ธด๋‹ค. circuit breaker์™€ isolation์ด ๋‚ด zuul์˜ ํ•œ ๊ตฐ์ด ์ฃฝ๋”๋ผ๋„ ๊ฒฉ๋ฆฌ ์‹œ์ผœ์ฃผ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. spring cloud zuul ์—์„œ hystrix isolation์€ semaphore์„ ๊ธฐ๋ณธ์œผ๋กœ ํ•œ๋‹ค.


๐ŸŽƒ์žฅ์•  ์‹œ๋‚˜๋ฆฌ์˜ค

hystrix, eureka, ribbon์„ ์‚ฌ์šฉํ•œ ์šฐ๋ฆฌ system์€ ์–ด๋Š ์ •๋„ resilience ํ•œ ๊ฑฐ์•ผ?


๐ŸŽˆ Spring Cloud Sleuth - Logging

spring cloud sleuth ์‚ฌ์šฉ ์‹œ application ๋กœ๊ทธ์— trace Id(uuid)๊ฐ€ ํ•จ๊ป˜ ์ถœ๋ ฅ

with Zipkin !

hystrix with turbin !

MSA๋กœ ์ „ํ–ฅํ•œ 11๋ฒˆ๊ฐ€์˜ ์‚ฌ๋ก€

๐Ÿ“ŒHystrix

netfilx๊ฐ€ ๋งŒ๋“  fault tolerance library๋กœ ์ฃผ๋กœ ์žฅ์•  ์ „ํŒŒ ๋ฐฉ์ง€์™€ resilience ๊ธฐ๋Šฅ์„ ํ•œ๋‹ค.

๐ŸŽจ์ ์šฉ ๋ฐฉ๋ฒ•

  1. Hystrix annotation ์‚ฌ์šฉ - hystrix javanic, spring cloud netfix์— ํฌํ•จ๋˜์–ด ์žˆ์Œ
@HystrixCommand
public String anyMethod() {
}
  1. Hystrix command ์ƒ์†
pulbic class SampleCommand extends HystrixCommand<String> {
@Override
protected String run() {}
}

hystrix command๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ๋ฒŒ์–ด์ง€๋Š” ์ผ

  1. ๋ฉ”์†Œ๋“œ๋ฅผ interceptํ•˜์—ฌ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค - thread isolation
  2. ๋ฉ”์†Œ๋“œ ์‹คํ–‰ ๊ฒฐ๊ณผ ์„ฑ๊ณต ํ˜น์€ ์‹คํŒจ ๋ฐœ์ƒ ์—ฌ๋ถ€๋ฅผ ์ธ์Šคํ„ด์Šค ๋‹จ์œ„๋กœ ๊ธฐ๋กํ•˜๊ณ  ํ†ต๊ณ„๋‚ธ๋‹ค. ํ†ต๊ณ„์— ๋”ฐ๋ผ circuit open ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค. - circuit breaker
  3. ์‹คํŒจํ•œ ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž๊ฐ€ ์ œ๊ณตํ•œ ๋ฉ”์†Œ๋“œ๋ฅผ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค - fallback
  4. ํŠน์ • ์‹œ๊ฐ„๋™์•ˆ ๋ฉ”์†Œ๋“œ๊ฐ€ ์ข…๋ฃŒ๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ exception์„ ๋ฐœ์ƒํ•œ๋‹ค - timeout

๐Ÿ˜ฒ๊ธฐ๋Šฅ์  ๊ด€์ ์—์„œ ๋ณธ Hystrix์˜ ์ฃผ์š” 4๊ฐ€์ง€ ๊ธฐ๋Šฅ

Circuit Breaker

hystrix.command.<commandKey>. //circuitbreaker ์„ ์–ธ 

metrics.rollingStats.timeInMilliseconds - Default 10์ดˆ
circuitBreaker.requestVolumeThreshold - Default 20๊ฐœ
circuitBreaker.errorThresholdPercentage - Default 50%
circuitBreaker.sleepWindowInMilliseconds - Default 5์ดˆ

hystrix command breaker๋Š” ํ•œ ํ”„๋กœ์„ธ์Šค ๋‚ด์—์„œ ์ฃผ์–ด์ง„ CommandKey ๋‹จ์œ„๋กœ ํ†ต๊ณ„๋ฅผ ๋‚ด๊ณ  ๋™์ž‘ํ•œ๋‹ค.

10์ดˆ ๋™์•ˆ 20๊ฐœ ์ด์ƒ์˜ ํ˜ธ์ถœ์ด ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ, 50%์ด์ƒ์˜ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด 5์ดˆ๊ฐ„ ํ˜ธ์ถœ ์ฐจ๋‹จ(circuit open)

์ผ์ • ์‹œ๊ฐ„(10์ดˆ) ๊ฒฝ๊ณผ ํ›„์— ๋‹จ ํ•œ ๊ฐœ์˜ ์š”์ฒญ์— ๋Œ€ํ•ด์„œ ํ˜ธ์ถœ์„ ํ—ˆ์šฉํ•˜๋ฉฐ(Half open), ์ด ํ˜ธ์ถœ์ด ์„ฑ๊ณตํ•˜๋ฉด → Circuit Close(ํ˜ธ์ถœ ํ—ˆ์šฉ)

Fallback

fallback์œผ๋กœ ์ง€์ •๋œ ๋ฉ”์†Œ๋“œ๋Š” ๋‹ค์Œ ๊ฒฝ์šฐ์— ์›๋ณธ ๋ฉ”์†Œ๋“œ๋ฅผ ๋Œ€์‹  ์‹คํ–‰ํ•œ๋‹ค.

  1. circuit open
  2. any exception(HystrixBadRequestException ์ œ์™ธ)
  3. Semaphore/ ThreadPoolRejection
  4. Timeout
@HystrixCommand(commandKey = "ExtDep1", fallbackMethod="recommendFallback")
//์ถ”์ฒœ ์„œ๋ฒ„ ํ˜ธ์ถœ
public String anyMethod() {}
//๋ฏธ๋ฆฌ ์ค€๋น„๋œ ์ƒํ’ˆ ๋ชฉ๋ก
public String recommendFallback(){return "<๋ฏธ๋ฆฌ ์ค€๋น„๋œ ์ƒํ’ˆ ๋ชฉ๋ก>"}

๐Ÿงจ exception ํ„ฐ์ง€๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ์ฐพ๊ธฐ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ์Œ. ๋น„์ƒ์‹์ ์œผ๋กœ ์‘๋‹ต์ด ๋น ๋ฅด๋‹ค๋ฉด ๋ณธ ๋ฉ”์†Œ๋“œ(anyMethod)๊ฐ€ ์ œ๋Œ€๋กœ ์ž‘๋™ํ•˜๋Š”์ง€ ๋กœ๊น…ํ•ด ๋ณผ ๊ฒƒ.

๐ŸงจHystrixBadRequestException : ์ด ์˜ค๋ฅ˜๋Š” fallback์„ ์‹คํ–‰ํ•˜์ง€ ์•Š์œผ๋ฉฐ circuit open์„ ์œ„ํ•œ ํ†ต๊ณ„์—๋„ ์ง‘๊ณ„๋˜์ง€ ์•Š๋Š”๋‹ค. ์ž˜๋ชป๋œ ํŒŒ๋ผ๋ฏธํ„ฐ ์ „๋‹ฌ๊ณผ ๊ฐ™์€ method caller์˜ ์‹ค์ˆ˜์˜ ๊ฒฝ์šฐ ์ด ์˜ˆ์™ธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๋งŒ์•ฝ ๋‹ค๋ฅธ ์˜ˆ์™ธ๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค๋ฉด circuit breaker ํ†ต๊ณ„์— ์ง‘๊ณ„๋˜์–ด circuit open์ด ๋˜๊ฑฐ๋‚˜ fallback์ด ์‹คํ–‰๋˜์–ด ๊ฐœ๋ฐœ ๊ณผ์ •์— ์˜ค๋ฅ˜๋ฅผ ์ธ์ง€ํ• ์ง€ ๋ชป ํ•  ์ˆ˜ ์žˆ๋‹ค.

Timeout

hystrix์—์„œ๋Š” circuit breaker ๋‹จ์œ„๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

metrics.rollingStats.timeInMilliseconds - Default 1์ดˆ

๋ณดํ†ต์€ 1์ดˆ ๋ฏธ๋งŒ์œผ๋กœ ์‘๋‹ต์ด ์™€์•ผ ํ•˜์ง€๋งŒ, ui๋กœ์ง์ด ๋ณต์žกํ•˜๊ฑฐ๋‚˜ ๋“ฑ์˜ ์ด์œ ๋กœ ์กฐ๊ธˆ ๋” ๋Š˜๋ ค๋„ ์ข‹๋‹ค.

Isolation

์ตœ๋Œ€ ๊ฐœ์ˆ˜ ์ดˆ๊ณผ ์‹œ semaphore rejection(fallback) ๋ฐœ์ƒํ•œ๋‹ค.

๋‘ ๊ฐ€์ง€ isolation ๋ฐฉ์‹์„ ๋‹จ์œ„ ๋ณ„๋กœ ์ง€์ • ๊ฐ€๋Šฅ

semaphore

circuit breaker 1๊ฐœ๋‹น 1๊ฐœ์˜ semaphore ์ƒ์„ฑํ•˜๊ณ , command๋ฅผ ํ˜ธ์ถœํ•œ caller Thread์—์„œ fallback ๋ฉ”์†Œ๋“œ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค. ๐Ÿงจtimeout์ด ์ œ ์‹œ๊ฐ„์— ๋ฐœ์ƒํ•˜์ง€ ๋ชปํ•œ๋‹ค๋Š” ๋‹จ์ ์ด.. ์ด๊ฒƒ์€ ์Šค๋ž˜๋“œ๋กœ ํ•ด๊ฒฐ ๊ฐ€๋Šฅ

thread(default)

circuit breaker ๋ณ„๋กœ ์‚ฌ์šฉํ•  thread pool ์ง€์ •(ThreadPoolKey)

command๋ฅผ ํ˜ธ์ถœํ•œ thread๊ฐ€ ์•„๋‹Œ, thread pool์—์„œ fallback ๋ฉ”์†Œ๋“œ ์‹คํ–‰.


๐Ÿ“ŒRibbon

netflix๊ฐ€ ๋งŒ๋“  software load balancer๋ฅผ ๋‚ด์žฅํ•œ RPC library

-Client Load Balancer with HTTP Client

API์ฝœ๋Ÿฌ๋“ค์— ์ž๋™์œผ๋กœ ribbon client๊ฐ€ ๋ถ™๊ฒŒ ๋˜๋ฉด, ์ธํ”„๋ผ์˜ ๋„์›€ ์—†์ด๋„ ๋‹ค์ˆ˜์˜ ์„œ๋ฒ„ ๋ชฉ๋ก์„ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ•˜์ง€๋งŒ ์Šคํ”„๋ง ํด๋ผ์šฐ๋“œ์—์„œ๋Š” ribbon ํด๋ผ์ด์–ธํŠธ๋ฅผ ์‚ฌ์šฉ์ž๊ฐ€ ์ง์ ‘ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Œ! ์Šคํ”„๋ง ํด๋ผ์šฐ๋“œ์—๋Š” http ํ†ต์‹ ์ด ํ•„์š”ํ•œ ์š”์†Œ๊ฐ€ ๋‚ด์žฅ๋˜์–ด ์žˆ์Œ. (api gateway, feign, restTemplate(@LoadBalanced))


๐Ÿ“ŒEureka

netflix๊ฐ€ ๋งŒ๋“  dynamic service discovery

-๋“ฑ๋ก: ์„œ๋ฒ„๊ฐ€ ์ž์‹ ์˜ ์„œ๋น„์Šค ์ด๋ฆ„๊ณผ IP ์ฃผ์†Œ, ํฌํŠธ๋ฅผ ๋“ฑ๋ก

-์กฐํšŒ: ์„œ๋น„์Šค ์ด๋ฆ„์„ ๊ฐ–๊ณ  ์„œ๋ฒ„ ๋ชฉ๋ก์„ ์กฐํšŒ

Ribbon๊ณผ ์—ฐ๋™ํ•ด ์„œ๋ฒ„ ๋ชฉ๋ก์„ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋‹ค.

Server ์‹œ์ž‘ ์‹œ eureka ์„œ๋ฒ„์— ์ž๋™์œผ๋กœ ์ž์‹ ์˜ ์ƒํƒœ ๋“ฑ๋ก

์ฃผ๊ธฐ์  heartbeat์œผ๋กœ eureka server์— ์ž์‹ ์ด ์‚ด์•„์žˆ์Œ์„ ์•Œ๋ฆผ

server ์ข…๋ฃŒ ์‹œ eureka ์„œ๋ฒ„์— ์ž์‹ ์˜ ์ƒํƒœ ๋ณ€๊ฒฝ ํ˜น์€ ์ž์‹ ์˜ ๋ชฉ๋ก ์‚ญ์ œ

eureka ์ƒ์— ๋“ฑ๋ก๋œ ์ด๋ฆ„์€ “spring.application.name

Ribbon + Eureka in Spring cloud?

ํ•˜๋‚˜์˜ ์„œ๋ฒ„์—๋Š” eureka client ์™€ ribbon client๊ฐ€ ํ•จ๊ป˜ ์„ค์ •๋˜๋ฉด spring cloud๋Š” ๋‹ค์Œ์˜ ribbon bean์„ ๋Œ€์ฒด (์„œ๋ฒ„์˜ ๋ชฉ๋ก์„ ์„ค์ •์œผ๋กœ ๋ช…์‹œํ•˜๋Š” ๋Œ€์‹ , eureka๋ฅผ ํ†ตํ•ด์„œ look upํ•ด์˜ด)

  1. serverList<Server>→ ๋ณ€๊ฒฝ: DiscoverEnableNIWSServerList
  2. -๊ธฐ๋ณธ: ConfigurationBasedServerList
  3. IPing→ ๋ณ€๊ฒฝ: NIWSDiscoveryPing
  4. -๊ธฐ๋ณธ: DummyPing

๐ŸŽˆ API Gateway

msa ํ™˜๊ฒฝ์—์„œ api gateway์˜ ํ•„์š”์„ฑ

  1. single endpoint ์ œ๊ณต
  2. api ๊ณตํ†ต ๋กœ์ง ๊ตฌํ˜„ - logging, authentication, authorization
  3. traffic control - api quota, throttling

๐Ÿ”๋ฌธ์ œ ์ง๋ฉด!

100% ์ž์ฒด ๊ฐœ๋ฐœํ•œ api gateway๋ฅผ ๋‘๊ณ  spring cloud zuul์„ ๋„์ž…ํ•ด์•ผ ํ• ๊นŒ?

→yes!

์ด์œ  : ์„œ๋ฒ„์˜ ๋ชจ๋“  ํ˜ธ์ถœ์€ hystrix command๊ฐ€ ๊ฐ์‹ธ์„œ ํ˜ธ์ถœํ•œ๋‹ค. ๊ทธ ์•ˆ์—๋Š” ribbon client๊ฐ€ ์กด์žฌ. ๊ทธ ์•ˆ์—์„œ eureka client๋ฅผ ํ†ตํ•ด์„œ ์‹ค์ œ ์„œ๋ฒ„๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.

api gateway๋ฅผ ์‚ฌ์šฉํ•ด endpoint ๊ด€๋ฆฌ๋ฅผ ํ•˜์ง€ ์•Š์•„๋„ ๋˜๊ณ , service์— ์˜ค๋ฅ˜๊ฐ€ ๋‚˜๋„ ๋‚ด ๊ฒŒ์ดํŠธ ์›จ์ด๋Š” ์ฃฝ์ง€ ์•Š์„ ์ตœํ›„์˜ ๋ณด๋ฃจ๊ฐ€ ์ƒ๊ธด๋‹ค. circuit breaker์™€ isolation์ด ๋‚ด zuul์˜ ํ•œ ๊ตฐ์ด ์ฃฝ๋”๋ผ๋„ ๊ฒฉ๋ฆฌ ์‹œ์ผœ์ฃผ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. spring cloud zuul ์—์„œ hystrix isolation์€ semaphore์„ ๊ธฐ๋ณธ์œผ๋กœ ํ•œ๋‹ค.


๐ŸŽƒ์žฅ์•  ์‹œ๋‚˜๋ฆฌ์˜ค

hystrix, eureka, ribbon์„ ์‚ฌ์šฉํ•œ ์šฐ๋ฆฌ system์€ ์–ด๋Š ์ •๋„ resilience ํ•œ ๊ฑฐ์•ผ?


๐ŸŽˆ Spring Cloud Sleuth - Logging

spring cloud sleuth ์‚ฌ์šฉ ์‹œ application ๋กœ๊ทธ์— trace Id(uuid)๊ฐ€ ํ•จ๊ป˜ ์ถœ๋ ฅ

with Zipkin !

hystrix with turbin !