Comparison with monolith and microservices - TheOpenCloudEngine/uEngine-cloud GitHub Wiki

Comparison with monolith and microservices

์ด๋ฒˆ ํŽ˜์ด์ง€๋Š” monolith ๋กœ ๊ตฌ์„ฑ๋˜์–ด์žˆ๋˜ Public Education Example ํŽ˜์ด์ง€๋ฅผ microservices ๋กœ ๋ณ€ํ™˜์„ ํ•˜๋Š” ์ž‘์—…์„ ํ†ตํ•˜์—ฌ monolith์™€ microservices๋ฅผ ๋น„๊ตํ•œ๋‹ค.
Public Education Example ์—์„œ๋Š” monolith ๊ตฌ์กฐ๋กœ ํ•˜๋‚˜์˜ ํ”„๋กœ์ ํŠธ์—์„œ ๊ฐ ์„œ๋น„์Šค ๊ฐ„์˜ ํ†ต์‹ ์„ URL๋งํฌ๋กœ relationํ•˜๋Š” ๋ชจ์Šต์„ ๋ณด์—ฌ์ฃผ์—ˆ๋Š”๋ฐ, microservices ๊ตฌ์กฐ์—์„œ๋Š” ์„œ๋น„์Šค ๋ณ„๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ๋‚˜๋ˆŒ ๊ฒƒ์ด๋‹ค. ๊ทธ๋ฆฌ๊ณ , ๋™์ผ URL๋กœ relationํ•˜๋Š” ๋ชจ์Šต์„ ๋ณด์—ฌ์ฃผ๊ธฐ ์œ„ํ•˜์—ฌ API GateWay์™€ Resistry Service๊ฐ€ ํ•„์š”ํ•˜๋‹ค.

https://github.com/uengine-oss ์œผ๋กœ ๋“ค์–ด๊ฐ€์„œ
https://github.com/uengine-oss/msa-tutorial-class-management-msa ๋ฅผ git clone ํ•œ๋‹ค

$ git clone https://github.com/uengine-oss/msa-tutorial-class-management-msa.git
$ cd msa-tutorial-class-management-msa

ํ•ด๋‹น ํ”„๋กœ์ ํŠธ๋ฅผ ๋‹ค์šด๋ฐ›๊ณ  intellij๋กœ ์—ด์—ˆ์„๋•Œ, ์•„๋ž˜์™€ ๊ฐ™์ด ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ๊ฐ€ ๋‚˜์˜จ๋‹ค.

  • 1๊ฐœ์˜ shared-model ํ”„๋กœ์ ํŠธ์™€
  • 5๊ฐœ์˜ domain
  • 2๊ฐœ์˜ general services
    ๋กœ ๊ตฌ์„ฑ์ด ๋˜์–ด์žˆ๋‹ค

shared-model์ด ํ•„์š”ํ•œ ์ด์œ ๋Š” ์„œ๋กœ ๋‹ค๋ฅธ ์„œ๋น„์Šค์—์„œ ๊ณตํ†ต์œผ๋กœ ์“ฐ์ด๋Š” ๊ฐ์ฒด๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ๊ธฐ์— ํ•ด๋‹น ๊ฐ์ฒด๋ฅผ ๊ณตํ†ต์œผ๋กœ ๊ด€๋ฆฌํ•˜์—ฌ ์ฃผ๊ธฐ ์œ„ํ•˜์—ฌ ํ•„์š”ํ•˜๋‹ค.
์˜ˆ๋ฅผ ๋“ค๋ฉด, customer๊ฐ€ clazz์˜ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๊ณ  ์‹ถ์„๋•Œ customer ์„œ๋น„์Šค์—์„œ clazz์˜ ์ •๋ณด๋ฅผ ๋‚ด๋ถ€์— ๊ตฌํ˜„์„ ํ•ด๋†“์„์ˆ˜๋„ ์žˆ์ง€๋งŒ, ๊ณต์šฉ์œผ๋กœ ๊ด€๋ฆฌํ•˜์—ฌ ๊ฐ์ฒด ๋ชจํ˜•์ด ๋ฐ”๋€Œ๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ ํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ”„๋กœ์ ํŠธ Buildํ•˜๊ธฐ

ํ•ด๋‹น ํ”„๋กœ์ ํŠธ๋ฅผ Buildํ•˜์—ฌ ์ •์ƒ์ ์œผ๋กœ ๋Œ์•„๊ฐ€๋Š”์ง€ ํ™•์ธ ํ•ด ๋ณธ๋‹ค.

$ mvn clean package

[INFO] Shared Model 1.0.0-SNAPSHOT ........................ SUCCESS [  1.287 s]
[INFO] Course Sub-domain 1.0.0-SNAPSHOT ................... SUCCESS [  1.600 s]
[INFO] Class Sub-domain 1.0.0-SNAPSHOT .................... SUCCESS [  0.701 s]
[INFO] Subject Matter Experts Sub-domain 1.0.0-SNAPSHOT ... SUCCESS [  0.623 s]
[INFO] Customer Sub-domain 1.0.0-SNAPSHOT ................. FAILURE [  0.293 s]
[INFO] Shared Calendar Service 1.0.0-SNAPSHOT ............. SKIPPED
[INFO] zuul-proxy-server 0.0.1-SNAPSHOT ................... SKIPPED
[INFO] eureka-registry-server 1.0-SNAPSHOT ................ SKIPPED
[INFO] hello-class MSA-version ............................ SKIPPED

์œ„์™€ ๊ฐ™์ด Customer ํ”„๋กœ์ ํŠธ๋ฅผ Build๋ฅผ ํ•˜๋Š” ์‹œ์ ์— ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
์ด๋Š” Customer ์„œ๋น„์Šค ์•ˆ์—์„œ Clazz๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ, ํ•ด๋‹น ํด๋ ˆ์Šค๋ฅผ ์ฐพ์ง€ ๋ชปํ•œ๋‹ค๋Š” ์—๋Ÿฌ์ด๋‹ค.
์ด ์—๋Ÿฌ๋ฅผ ํ•ด๊ฒฐํ•˜๊ณ ์ž Customer ์„œ๋น„์Šค์˜ dependency์— shared-model ์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์ฃผ์ž.

ํ”„๋กœ์ ํŠธ ๊ตฌ๋™ํ•˜๊ธฐ 1

registry service ๊ตฌ๋™

์˜ˆ์ œ ํ”„๋กœ์ ํŠธ ๋“ค์€ spring-boot ์œ„์—์„œ ๊ธฐ๋™์„ ํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  microservice ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•˜์—ฌ microservice๋ฅผ ์ž˜ ๊ตฌํ˜„ํ•ด ๋†“์€
spring-cloud library๋ฅผ ์‚ฌ์šฉํ•˜์˜€๋‹ค.
๊ทธ ์ค‘์— registry service ๋Š” spring-cloud library์˜ eureka๋ฅผ ์‚ฌ์šฉํ•˜์˜€๊ณ , ํ•ด๋‹น ์„œ๋น„์Šค๋Š” ๋งŽ์€ ์ˆ˜์˜ ์„œ๋น„์Šค๋“ค๊ฐ„์˜ ์•ค๋“œํฌ์ธํŠธ๋ฅผ ์ฐพ๊ณ , ์„œ๋น„์Šค์˜ ์ƒํƒœ๋ฅผ ์–ด๋”˜๊ฐ€์— ๋“ฑ๋กํ•˜๋Š” ๊ธฐ๋Šฅ์„ ํ•œ๋‹ค. registry service๋ฅผ ๊ตฌ๋™ํ•˜๊ธฐ ์œ„ํ•˜์—ฌ mvn spring-boot:run์„ ์‹คํ–‰ํ•˜๊ณ , ๋ธŒ๋ผ์šฐ์ €์—์„œ http://localhost:8761/ ๋กœ ์ ‘๊ทผํ•˜์—ฌ ํ™•์ธํ•œ๋‹ค.

์•„์ง ์˜ฌ๋ผ์˜จ instance๊ฐ€ ์—†๋Š” ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.

clazz, course service ๊ตฌ๋™

์ด์ œ ๋‘๊ฐœ์˜ microservice ๋ฅผ ๊ตฌ๋™ ์‹œํ‚ฌ ๊ฒƒ์ด๋‹ค. ์—ญ์‹œ๋‚˜ ํ”„๋กœ์ ํŠธ ๊ตฌ๋™์€ mvn spring-boot:run ์„ ์‹คํ–‰ ํ•  ํ…Œ์ง€๋งŒ
์„œ๋กœ ๋‹ค๋ฅธ port๋กœ ๊ตฌ๋™์„ ์‹œ์ผœ์„œ ๊ฐ ์„œ๋น„์Šค๊ฐ„์˜ URL relation์„ ํ™•์ธ ํ•  ๊ฒƒ์ด๋‹ค.
ํ˜„์žฌ๋Š” ๋ชจ๋‘ 8080 ์œผ๋กœ ์„ค์ •์ด ๋˜์–ด์žˆ๋‹ค.

๊ฐ ํ”„๋กœ์ ํŠธ์˜ application.ymlํŒŒ์ผ์„ ์—ด์–ด์„œ server.port ๋ถ€๋ถ„์„ ์„œ๋กœ ๋‹ค๋ฅธ ํฌํŠธ๋กœ ์„ค์ •ํ•œ๋‹ค.

mvn spring-boot:run -Dserver.port=8081 ์œผ๋กœ ๊ตฌ๋™ํ•ด๋„ ๋œ๋‹ค.

spring:
  profiles: local

server:
  port: 8081
  servletPath: /
  • clazz 8081
  • course 8082

์ด์ œ brower์˜ http://localhost:8761/ ๋กœ ์ ‘๊ทผํ•˜์—ฌ ๋‘๊ฐœ์˜ ์„œ๋น„์Šค๊ฐ€ ๊ตฌ๋™ ๋œ ๊ฒƒ์„ ํ™•์ธ ํ•œ๋‹ค.

ํ”„๋กœ์ ํŠธ ๊ตฌ๋™ํ•˜๊ธฐ 2

์ด์ œ Public Education Example ์˜ Sample project ๊ตฌ๋™ํ•˜๊ธฐ ์™€ ๊ฐ™์€ ์ž‘์—…์„ ํ•ด ๋ณผ ๊ฒƒ์ด๋‹ค.
์ฐจ์ด์ ์€ ์ด์ „์—๋Š” ๋ชจ๋‘ ๊ฐ™์€ url์ธ localhost:8080 ์œผ๋กœ ํ˜ธ์ถœ์„ ํ•˜์˜€๋‹ค๋ฉด, ์ด๋ฒˆ์—๋Š” ์„œ๋กœ ๋‹ค๋ฅธ port๋กœ ํ˜ธ์ถœ์„ ํ•  ๊ฒƒ์ด๋‹ค

console์ฐฝ์„ ์—ด์–ด์„œ ๊ฐ ์„œ๋น„์Šค์˜ profile์„ ํ™•์ธํ•œ๋‹ค.

$ http http://localhost:8081/
$ http http://localhost:8082/

๊ณผ์ •(course)๋“ฑ๋ก

## ๊ณผ์ •๋“ฑ๋ก
$ http localhost:8082/courses title="software modeling lecture" duration=5 maxEnrollment=5 minEnrollment=1 
$ http PATCH "http://localhost:8082/courses/1" description="MSA ๊ต์šฑ๊ณผ์ •์ž…๋‹ˆ๋‹ค"

{
    "_links": {
        "course": {
            "href": "http://localhost:8082/courses/1"
        },
        "self": {
            "href": "http://localhost:8082/courses/1"
        }
    },
    "clazzes": [],
    "courseId": 1,
    "description": "MSA ๊ต์šฑ๊ณผ์ •์ž…๋‹ˆ๋‹ค",
    "duration": 5,
    "maxEnrollment": 5,
    "minEnrollment": 1,
    "title": "software modeling lecture",
    "unitPrice": null
}

๊ฐ•์˜(clazz) ๋“ฑ๋ก

## ํด๋ž˜์Šค 1 ๋“ฑ๋ก 
## "http://localhost:8082/courses/1" ์ด๊ฒƒ์ด ๋ฌธ์ž์—ด์ฒ˜๋Ÿผ ๋„˜์–ด๊ฐ€์ง€๋งŒ HATEOAS์—์„œ๋Š” ๋ฌธ์ž์—ด์ด ์•„๋‹ˆ๊ณ , ๋ฆฌ์†Œ์Šค๋ฅผ ์ง€์นญํ•˜๋Š” ์˜๋ฏธ๋ฅผ ๊ฐ€์ง„๋‹ค
$ http localhost:8081/clazzes course="http://localhost:8082/courses/1"

{
    "_links": {
        "clazz": {
            "href": "http://localhost:8081/clazzes/1"
        },
        "clazzDays": {
            "href": "http://localhost:8081/clazzes/1/clazzDays"
        },
        "course": {
            "href": "http://localhost:8081/courses/1"
        },
        "instructor": {
            "href": "http://localhost:8081/instructors/"
        },
        "self": {
            "href": "http://localhost:8081/clazzes/1"
        }
    },
...

proxy service ๊ตฌ๋™

์œ„์™€ ๊ฐ™์ด ์„œ๋กœ ๋‹ค๋ฅธ port๋กœ ๊ตฌ๋™ํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ๋„ฃ๊ณ  ๋นผ๋Š” ๊ฒƒ์ด ๊ฐ€๋Šฅํ•˜์ง€๋งŒ, ์‹ค์ œ ์šด์˜์„ ํ•˜๊ฑฐ๋‚˜, ํ˜ธ์ถœ์ด ๋งŽ์•„ ์งˆ ๊ฒฝ์šฐ์—๋Š” url๊ณผ port๊ฐ€ ์—‰ํ‚ฌ์ˆ˜๊ฐ€ ์žˆ๋‹ค.
์ด๋•Œ ํ•„์š”ํ•œ ๊ฒƒ์ด zuul proxy์ด๋‹ค. URL์„ ํ•˜๋‚˜์ธ ๊ฒƒ์ฒ˜๋Ÿผ ๋ฌถ์–ด ์ฃผ๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. ๋ณดํ†ต API Gateway๋ผ๊ณ ๋„ ๋ถˆ๋ฆฌ์šด๋‹ค. 8080 ์œผ๋กœ ๋„์šด ํ›„, localhost:8082/courses , localhost:8081/clazzes ๋กœ ํ˜ธ์ถœํ•œ URL์„ localhost:8080/clazzes ์œผ๋กœ ํ˜ธ์ถœ ํ•˜์—ฌ ๋ณด๊ฒ ๋‹ค.

proxy service ํ”„๋กœ์ ํŠธ๋กœ ์ด๋™ํ•˜์—ฌ mvn spring-boot:run ์œผ๋กœ ์‹คํ–‰ ํ•˜๊ณ ,
brower์˜ http://localhost:8761/ ๋กœ ์ ‘๊ทผํ•˜์—ฌ 'ZUUL-ROUTER' ์„œ๋น„์Šค๊ฐ€ ์‹คํ–‰ ๋œ ๊ฒƒ์„ ํ™•์ธํ•œ๋‹ค.

## ๊ณผ์ •๋“ฑ๋ก
$ http localhost:8080/courses title="software modeling lecture2" duration=3 maxEnrollment=5 minEnrollment=1
$ http PATCH "http://localhost:8080/courses/2" description="MSA2๊ต์šฑ๊ณผ์ •์ž…๋‹ˆ๋‹ค"

## ํด๋ž˜์Šค 2 ๋“ฑ๋ก 
$ http localhost:8080/clazzes course="http://localhost:8080/courses/2"

โš ๏ธ **GitHub.com Fallback** โš ๏ธ