마이크로서비스아키텍처로 개발하기 안재우 Platform Architecture 팀 SK Planet
About me SK 플래닛 Platform Architecture 팀 전 NCSOFT 인프라플랫폼팀 전닷넷엑스퍼트수석컨설턴트
오늘얘기할내용은 마이크로서비스아키텍처란? 장단점은? 무엇이필요하고, 어떤점을고려해야하는지? 우리는어떻게하고있는지?
전통적인 Web App 아키텍처 WAR Browser/ Client UI A Service A Repository Database A WAS
이중화 / 로드밸런싱 WAR UI Database Browser/ Client Load balancer A Service A A Repository WAS WAS
기능추가 WAR UI Database Browser/ Client Load balancer A Service B Service A B A Repository B Repository WAS WAS
시스템연계 / 통합 WAR UI Database Browser/ Client Load balancer A Service B Service A B A Repository B Repository WAS WAS D System C System
시스템연계 / 통합 WAR UI Database Browser/ Client Load balancer A Service B Service A B A Repository B Repository WAS WAS G System E System D System C System F System
문제점 코드가너무커져서유지보수하기힘들어요. 시스템을분리하고싶어요. DB 를분리하고싶어요. 연계시스템이변경된대요. 연계시스템이장애나서우리서비스도장애예요. 사소한수정인데도전체배포를하고, QA 를거쳐야해요. 새로운걸추가하는건상관없는데, 기존로직 / 데이터를변경하면무슨문제가생길지몰라요. 저희도새로운버전 / 기술을써보고싶은데
가면갈수록 뭔가바꾸는게두려워진다. 개발자들이구닥다리기술의족쇄에서벗어나지못하고, 기술격차는계속벌어진다. 모든것은 차세대 가해결해야줄것이다. ( 정말?)
나랑상관없는상상속단어들 Domain Driven Design Continuous Delivery On-demand Virtualization Elastic, Scalable, Resilience Polyglot Programming Infrastructure Automation Agile Development Reusability Self-government Team
마이크로서비스아키텍처의배경 Domain Driven Design Continuous Delivery On-demand Virtualization Elastic, Scalable, Resilience Polyglot Programming Infrastructure Automation Agile Development Reusability Self-government Team
Scale Cube
Y 축확장 WAR UI Database A Service B Service A B A Repository B Repository WAS
Y 축확장 WAR A Service A Repository Database A UI WAS WAR B Service B Repository Database B WAS
Y 축확장 + X 축 /Z 축확장 WAR A Service A Repository Database Database A A UI A UI WAS WAS B UI B UI WAR B Service Database B1 B Repository WAS WAS Database B2
마이크로서비스란? 작고 (small) API 로다른서비스와연계하며 (communicate with APIs) 자율적이며 (autonomous) 한가지일을잘하는데초점을맞춘서비스 (focused on doing one thing well)
장점 Technology Heterogeneity Resilience Scaling Ease of Deployment Organizational Alignment Composability Replaceability
단점 Complexity Multiple Database & Transaction Management Complicated Test Require Automation for Deploy/Operation Hard to develop features span multiple services
이거 SOA 얘기아니에요? 비슷하지만, 달라요. SOA 는개념상으로는잘못되지않았어요. 다만방식이잘못되었을뿐이죠. SOAP Protocol WS-* Vendor-Driven ESB 가모든걸다해결해줄거라는잘못된믿음 ( 그렇게선전했던나쁜 XX)
MSA 는 Vendor Driven -> Service Company Driven 오픈테크놀로지기반 SOAP/XML vs. REST/JSON 스펙먼저 가아닌 현실에서검증된 Practice 들 의모음 Agile 개념과의결합 Cloud 환경의활용
마이크로서비스모델링 Domain Driven Design Bounded Context Contract-First(API-First) Design Decomposed database Event-Driven Architecture
모델링 / 구현 Tip API 를먼저정의하라. API 를 REST API Maturity Level 2 이상이되도록강제화하라. API 문서를유지하라 ( 예 : Swagger) ORM 을활용하라 DB 에너무의존하지마라 도메인내부에서만의미있는값을외부에노출하는것을지양하라 마이크로서비스가별다른설정없이바로기동가능하게하라 ( 예 : Java 의경우, Spring Boot + Embedded WAS 활용 )
클라이언트 - 서비스간통합 Client A (Web) LB LB Security Logging Version Security Logging Version MS-A MS-A MS-A MS-B Client B (App) LB Security Logging Version MS-A MS-C LB Security Logging Version MS-A MS-D
클라이언트 - 서비스간통합 Client A (Web) MS-A MS-A Security Logging Version API Gateway MS-A MS-B Client B (App) MS-A MS-C MS-A MS-D
클라이언트 - 서비스간통합 Client A (Web) LB Security Logging Security Version Logging Version API Gateway API Gateway MS-A MS-A MS-A MS-B Client B (App) LB Security Logging Security Version Logging Version API Gateway API Gateway MS-A MS-C MS-A MS-D
서비스간통신 Service A HTTP Request/Response Service B Publish Event Event (Message) Broker Subscribe Event Service C Service D
Service Discovery Client/API Gateway LB LB Security Logging Version Security Logging Version MS-A MS-A MS-A MS-B Security Client/API Gateway HA Proxy HA Proxy Service Registry Logging Version Security Logging Version MS-A MS-A MS-A MS-B
Blue/Green Deployment http://martinfowler.com/bliki/bluegreendeployment.html
MSA 를선택한이유 Frontend/Backend 분리 회사의 Engineer Tech Tree 와동기화 코드양이커지고, 중복코드가발생 코드의양을줄여서누구나쉽게파악하도록 팀전체의 Project Working Group 별 Product 시스템간연계증대 API 기반의 Contract 관리를강제화 새로운기술에대한도입욕구 Micro-Service 단위로구현에자율성부여 (Polyglot) 재사용성향상및지속적인발전 회사인프라의뒷받침 Micro-Service 단위의재사용, 자유로운리팩토링 On-Premise Cloud, CI 와연계된배포자동화 (Jarvis), 향후 Docker 와같은 Container 기술과연계
어떻게개발하나요? UserStory 검토 Contract/API 설계 Frontend 개발 Backend 개발 Mock/Unit Test Unit Test API 연동 Load Test Frontend 개발자 UserStory 종료 Backend 개발자
Contract/API 의설계 / 공유
Contract/API 의설계 / 공유 API Workspace Product Product API API API Consumer (stakeholder) Review / Share draft spec Explore & Test APIs dev draft release Design APIs API Provider Publish/Change APIs API Consumer (public)
진짜 Polyglot 을하나요? 기존시스템들의 Frontend 기존시스템들의 Backend Web Application Presentation JSP Sitemesh JQuery Controller Business Java 1.6 Tomcat 6 Spring 3.x + XML Conf. Spring MVC MyBatis Maven MySQL Data Access
네, 합니다. Java 1.7 / Tomcat 7 Spring 4.x + Java Conf. MySQL Frontend Spring Data JPA HTML Angular.js Java 1.8 / Embedded Tomcat Spring Boot Redis CSS Bootstrap Grunt Bower Spring Data JPA Node.js Express PlanetSpace (File Storage) Less Karma Groovy RabbitMQ 향후실험 (?) 후보들 Vert.x Go ASP.NET 5 Others ZooKeeper Other
개발환경의문제 개발하다보면, 여러개의마이크로서비스들을구동시켜야하는경우가많다. 마이크로서비스마다설정 / 기동방식이상이한경우, 다소괴롭다. 구동된마이크로서비스들을위한 API Gateway 를빠르게설정하기 git clone/pull 하는것도일이다.
Whitebase Developer s Machine remote machine MS-F Instance Whitebase git clone jar/js (file system) jar/js (file system) Artifact repository wget jar/js (file system) HA Proxy HA Proxy Docker Image Registry Local docker remote docker MS-A Instance MS-B Instance MS-C Instance MS-D Instance MS-E Instance
Whitebase URL-based Router + Proxy Authentication Routing Versioning Logging Composition
MSA 로진행하며얻은것 팀원들이다루는기술범위가크게확장 최신기술의도입 / 실험에부담이없음 팀원간의경험공유활성화 API 디자인능력향상 향후변화 / 확장에대해서도아키텍처적변화없이대응이가능 높은재활용성 / 조합지원 향후사내 / 대외오픈소스화가가능할듯한솔루션들
MSA 로진행시의단점 초기개발시에는개발시간이많이소요됨 MSA 로원활하게개발하기위한기반구성요소와인프라준비가필요함 기존개발방식이편하다고주장하는사람들로부터의저항 서비스간연계시협의가필요 여러서비스에걸치는기능의경우, 주체가애매한경우가생김
제언 갑자기한번에 MSA 로넘어가는것은쉽지않은작업입니다. 기존시스템에서분할이가능한항목을하나씩분할해가거나, 신규개발되는기능을하나씩마이크로서비스로분리하여추가해가는것이좋습니다. MSA 는만능이아니며, 조직문화 ( 점진적발전, 구성원들의 Skill-up 에대한관심과투자 ) 가뒷받침해줘야합니다. 조직문화가선행되지않으면차라리시도하지않는것이좋습니다.
질문 / 피드백 var you = {}; if (you.like you.dislike you.suggest you.request) { var id = "jaewoo.ahn"; var domain = "sk.com"; mail.send(string.format("{0}@{1}", id, domain )); }