SlideShare une entreprise Scribd logo
1  sur  30
Télécharger pour lire hors ligne
2017年の
LINEのマイクロサービスを
⽀えるSpring
Masahiro Ide, LINE Corporation
@imasahiro
https://github.com/imasahiro
Self Intro
l Masahiro Ide
l Server side engineer at LINE
l Mainly worked on スタンプ/着せかえ ショップ
l Contribute to Armeria - Asynchronous RPC/REST library
l https://github.com/line/armeria
• Where is Spring used at LINE?
• Useful/Customized Spring features
• Monitoring
Agenda
LINE
LINE System
l LINE has hundreds of applications
l Recent apps are Java/Spring applications
l Mainly communicates with Thrift, and REST
l Uses same in-house deployment, monitoring system
今⽇お話しするLINEのシステム
lスタンプショップ
スタンプショップ
l Spring-boot 1.5.8, Spring-MVC
l Mostly Asynchronous Http/2 Thrift/REST service
l Java8, RxJava2, (Completable|Listenable)Future
l Storage
l Redis, MySQL, Mongo, ElasticSearch
l Monitoring
l Micrometer, Dropwizard Metrics, Prometheus, Zipkin
Sticker server Mongo
MySQL
ElasticSearch
Redis
LINE Client
Theme server Search server
STORE Server
スタンプショップ 構成
スタンプショップ
l Spring-boot 1.5.8, Spring-MVC
l Mostly Asynchronous Http/2 Thrift/REST service
l Java8, RxJava2, (Completable|Listenable)Future
l Storage
l Redis, MySQL, Mongo, ElasticSearch
l Monitoring
l Micrometer, Dropwizard Metrics, Prometheus, Zipkin
l Easy to setup
l Have many integrations with other libraries
l Mybatis, Thymeleaf, Tomcat, etc.
Why spring, why spring-boot?
@SpringBootApplication
public class SampleApp {
@Configuration
class MvcConf extends WebMvcConfigurerAdapter {…}
public static void main(String[] args) {
SpringApplication.run(SampleApp.class, args);
}
}
Simple & Useful Spring features
1. Spring cache abstraction
1. (Spring) AOP
2. Dependency management
1. Spring Cache Abstraction
l SpringにおけるCacheの抽象化
l Can choose cache implementation
l Redis, Caffeine, Guava, etc.
l …But need to use carefully on async service
@Cacheable(cacheNames = "listCache")
List<Item> selectByLang(String lang) {
return sqlSession.selectList(…);
}
Async support in cache abstraction
lNaive (and wrong) solution
l This just caches a Future…
l But donʼt cache value in Future
l See https://jira.spring.io/browse/SPR-12967
@Cacheable(cacheNames = "listCache")
CompletableFuture<List<Item>> selectByLang(String lang) {
return CompletableFuture.supplyAsync(
() -> sqlSession.selectList(…), executor);
}
Async support in cache abstraction
lMade similar cache abstraction
l with Caffeine AsyncLoadingCache and
Lettuce (Async redis client)
@AsyncCacheable(cacheNames = "listCache")
CompletableFuture<List<Item>> selectByLang(String lang) {
return CompletableFuture.supplyAsync(
() -> sqlSession.selectList(…), executor);
}
Simple & Useful Spring features
1. Spring cache abstraction
1. (Spring) AOP
2. Dependency management
2. (Spring) AOP
lAOP - Aspect Oriented Programming
l Use case: logging, perf instrumentation
@Loggable @GetMapping(“/”)
ModelAndView home(…) {…}
@Around("@annotation(Loggable)")
public Object logging(ProceedingJoinPoint pjp) {
Timer timer = newTimer()
try {
return pjp.proceed();
} finally {
long latency = timer.stop();
logger.info(“request path: {}, args:{}, latency:{}”, …, latency));
}
}
Client side MySQL sharding using AOP
ApplicationApplication
MySQL Slave
MySQL Master
Shard01
MySQL Slave
MySQL Master
Shard01
MySQL Slave
MySQL Master
Shard01
@Shardable
List<Item> selectListByUserId(int id) {…}
List<DataSource> dataSources = …;
@Around("@annotation(Shardable)")
Object sharding(ProceedingJoinPoint pjp) {
int id = getArguments(pjp)[0];
source = dataSrouces.get(id % 12);
useDataSource(source);
return pjp.proceed();
}
3. Dependency management
lBOM and Dependency management plugin
lSpringがlibrary versionを管理してくれる
dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:Brussels-SR5'
}
dependencies {
dependencySet(group: 'com.linecorp.armeria', version: '0.55.0') {
entry 'armeria-tomcat-shaded’
entry 'armeria-thrift0.9-shaded'
}
dependency 'biz.paluch.redis:lettuce:4.4.1.Final’
…
}}
スタンプショップ
l Spring-boot 1.5.8, Spring-MVC
l Mostly Asynchronous Http/2 Thrift/REST service
l Java8, RxJava2, (Completable|Listenable)Future
l Storage
l Redis, MySQL, Mongo, ElasticSearch
l Monitoring
l Micrometer, Dropwizard Metrics, Prometheus, Zipkin
How to make a service asynchronous?
l元々はTomcat+Spring MVC or thrift+DBなシステム
@Repository public class ShopStorage {
List<Item> selectByLang(String lang) {
return sqlSession.selectList(
“shop.selectByLang”, lang);
}}
@Controller public class ShopController {
@ResponseBody List<Item> home() {
return storage.getList();
}}
How to make a service asynchronous?
lSync accessを1つずつAsyncに書き直す
@Repository public class ShopStorage {
List<Item> selectByLang(String lang) {
return sqlSession.selectList(
“shop.selectByLang”, lang);
}}
@Controller public class ShopController {
@ResponseBody List<Item> home() {
return storage.getList();
}}
@Repository public class AsyncShopStorage {
CompletableFuture<List<Item>>
selectByLang(String lang) {
return CompletableFuture.supplyAsync(
() -> sqlSession.selectList(
“shop.selectByLang”, lang),
executor);
}}
@Controller public class AsyncShopController {
@ResponseBody
DeferredResult<List<Item>> home() {
result = new DeferredResult<>();
storage.getList()
.thenApply(result::setResult);
return result;
}}
• Where is Spring used at LINE?
• Useful/Customized Spring features
• Monitoring
Agenda
How to observe our services?
lLog
l その瞬間に何が起こったかを確認する
lMetric
l 現在起きている現象のトレンドを確認する
lTrace
l システム間で何が何が起きているかを確認する
How to observe our services?
lLog
l Slf4j + Kibana
lMetric
l Micormeter, Prometheus, Dropwizard metrics
l Grafana
lTrace
l Zipkin
l io.zipkin.brave:brave-instrumentation-mysql
l io.zipkin.brave:brave-instrumentation-spring-webmvc
l And elasticsearch, mongo, redis integrations, etc.
Micrometer
l Supports multiple monitoring tools
l Dropwizard Metrics, Prometheus, etc.
l Will be provide as a Spring Boot 2.0 metrics collection
l Already used in production servers
l Found some concurrency issues but now looks stable
l https://github.com/micrometer-metrics/micrometer/issues/139
l https://github.com/micrometer-metrics/micrometer/issues/172
l https://github.com/micrometer-metrics/micrometer/issues/208
Prometheus
lSimple TSDB, Pull型
lSupports querying, alerting
Application
# HELP armeria_client_response_duration_seconds
# TYPE armeria_client_response_duration_seconds summary
armeria_client_response_duration_seconds{method="sendMessage",
service=”Service",quantile="0.5",} 8.194E-4
armeria_client_response_duration_seconds{method="sendMessage",
service=”Service",quantile="0.75",} 9.494E-4
armeria_client_response_duration_seconds{method="sendMessage",
service=”Service",quantile="0.90",} 9.994E-4
…
/internal/metrics
Node exporterPrometheus
pull ApplicationNode exporter
Micrometer+Prometheus+Grafana
Zipkin
Put all together
lArmeria - Spring, micrometer, zipkin integration
@Bean
ThriftServiceRegistrationBean service(MyService.AsyncIface myService,
Tracing tracing) {
return new ThriftServiceRegistrationBean()
.setPath("/thrift/")
.setService(
THttpService.of(shopCapabilityService)
.decorate(LoggingService.newDecorator())
.decorate(MetricCollectingService.newDecorator(
MeterIdFunction.ofDefault("LineShopService")))
.decorate(HttpTracingService.newDecorator(tracing))));
}
Thank you

Contenu connexe

Tendances

JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
haruki ueno
 

Tendances (20)

Spring Boot 1.3 News #渋谷Java
Spring Boot 1.3 News #渋谷JavaSpring Boot 1.3 News #渋谷Java
Spring Boot 1.3 News #渋谷Java
 
Composable and streamable Play apps
Composable and streamable Play appsComposable and streamable Play apps
Composable and streamable Play apps
 
Gruntwork Executive Summary
Gruntwork Executive SummaryGruntwork Executive Summary
Gruntwork Executive Summary
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
BOSH / CF Deployment in modern ways #cf_tokyo
BOSH / CF Deployment in modern ways #cf_tokyoBOSH / CF Deployment in modern ways #cf_tokyo
BOSH / CF Deployment in modern ways #cf_tokyo
 
Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)
 
手把手教你如何串接 Log 到各種網路服務
手把手教你如何串接 Log 到各種網路服務手把手教你如何串接 Log 到各種網路服務
手把手教你如何串接 Log 到各種網路服務
 
The Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeThe Past Year in Spring for Apache Geode
The Past Year in Spring for Apache Geode
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and Friends
 
Django Rest Framework - tips & trick
Django Rest Framework - tips & trick Django Rest Framework - tips & trick
Django Rest Framework - tips & trick
 
Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Spring boot入門ハンズオン第二回
Spring boot入門ハンズオン第二回Spring boot入門ハンズオン第二回
Spring boot入門ハンズオン第二回
 
Building an API with Django and Django REST Framework
Building an API with Django and Django REST FrameworkBuilding an API with Django and Django REST Framework
Building an API with Django and Django REST Framework
 
the Spring 4 update
the Spring 4 updatethe Spring 4 update
the Spring 4 update
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
 
Combining Django REST framework & Elasticsearch
Combining Django REST framework & ElasticsearchCombining Django REST framework & Elasticsearch
Combining Django REST framework & Elasticsearch
 
DAST в CI/CD, Ольга Свиридова
DAST в CI/CD, Ольга СвиридоваDAST в CI/CD, Ольга Свиридова
DAST в CI/CD, Ольга Свиридова
 
JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
 

Similaire à 2017年のLINEのマイクロサービスを支えるSpring

Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIs
NLJUG
 

Similaire à 2017年のLINEのマイクロサービスを支えるSpring (20)

Lambda Architecture Using SQL
Lambda Architecture Using SQLLambda Architecture Using SQL
Lambda Architecture Using SQL
 
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...
Choisir entre une API  RPC, SOAP, REST, GraphQL?  
Et si le problème était ai...Choisir entre une API  RPC, SOAP, REST, GraphQL?  
Et si le problème était ai...
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...
 
The magic behind your Lyft ride prices: A case study on machine learning and ...
The magic behind your Lyft ride prices: A case study on machine learning and ...The magic behind your Lyft ride prices: A case study on machine learning and ...
The magic behind your Lyft ride prices: A case study on machine learning and ...
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
 
Jena University Talk 2016.03.09 -- SQL at Zalando Technology
Jena University Talk 2016.03.09 -- SQL at Zalando TechnologyJena University Talk 2016.03.09 -- SQL at Zalando Technology
Jena University Talk 2016.03.09 -- SQL at Zalando Technology
 
Motion Django Meetup
Motion Django MeetupMotion Django Meetup
Motion Django Meetup
 
re:Invent Deep Dive on Lambda Layers and Runtime API
re:Invent Deep Dive on Lambda Layers and Runtime APIre:Invent Deep Dive on Lambda Layers and Runtime API
re:Invent Deep Dive on Lambda Layers and Runtime API
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 
Rapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and PythonRapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and Python
 
Web program-peformance-optimization
Web program-peformance-optimizationWeb program-peformance-optimization
Web program-peformance-optimization
 
Visualizing Big Data in Realtime
Visualizing Big Data in RealtimeVisualizing Big Data in Realtime
Visualizing Big Data in Realtime
 
Cloud native programming model comparison
Cloud native programming model comparisonCloud native programming model comparison
Cloud native programming model comparison
 
Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIs
 
Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)
 
Legacy java ee meet lambda
Legacy java ee  meet lambdaLegacy java ee  meet lambda
Legacy java ee meet lambda
 
Monitoring Spark Applications
Monitoring Spark ApplicationsMonitoring Spark Applications
Monitoring Spark Applications
 
Reactive Java Programming: A new Asynchronous Database Access API by Kuassi M...
Reactive Java Programming: A new Asynchronous Database Access API by Kuassi M...Reactive Java Programming: A new Asynchronous Database Access API by Kuassi M...
Reactive Java Programming: A new Asynchronous Database Access API by Kuassi M...
 
Sinatra and JSONQuery Web Service
Sinatra and JSONQuery Web ServiceSinatra and JSONQuery Web Service
Sinatra and JSONQuery Web Service
 
Stream Processing use cases and applications with Apache Apex by Thomas Weise
Stream Processing use cases and applications with Apache Apex by Thomas WeiseStream Processing use cases and applications with Apache Apex by Thomas Weise
Stream Processing use cases and applications with Apache Apex by Thomas Weise
 
Building Serverless applications with Python
Building Serverless applications with PythonBuilding Serverless applications with Python
Building Serverless applications with Python
 

Plus de LINE Corporation

Plus de LINE Corporation (20)

JJUG CCC 2018 Fall 懇親会LT
JJUG CCC 2018 Fall 懇親会LTJJUG CCC 2018 Fall 懇親会LT
JJUG CCC 2018 Fall 懇親会LT
 
Reduce dependency on Rx with Kotlin Coroutines
Reduce dependency on Rx with Kotlin CoroutinesReduce dependency on Rx with Kotlin Coroutines
Reduce dependency on Rx with Kotlin Coroutines
 
Kotlin/NativeでAndroidのNativeメソッドを実装してみた
Kotlin/NativeでAndroidのNativeメソッドを実装してみたKotlin/NativeでAndroidのNativeメソッドを実装してみた
Kotlin/NativeでAndroidのNativeメソッドを実装してみた
 
Use Kotlin scripts and Clova SDK to build your Clova extension
Use Kotlin scripts and Clova SDK to build your Clova extensionUse Kotlin scripts and Clova SDK to build your Clova extension
Use Kotlin scripts and Clova SDK to build your Clova extension
 
The Magic of LINE 購物 Testing
The Magic of LINE 購物 TestingThe Magic of LINE 購物 Testing
The Magic of LINE 購物 Testing
 
GA Test Automation
GA Test AutomationGA Test Automation
GA Test Automation
 
UI Automation Test with JUnit5
UI Automation Test with JUnit5UI Automation Test with JUnit5
UI Automation Test with JUnit5
 
Feature Detection for UI Testing
Feature Detection for UI TestingFeature Detection for UI Testing
Feature Detection for UI Testing
 
LINE 新星計劃介紹與新創團隊分享
LINE 新星計劃介紹與新創團隊分享LINE 新星計劃介紹與新創團隊分享
LINE 新星計劃介紹與新創團隊分享
 
​LINE 技術合作夥伴與應用分享
​LINE 技術合作夥伴與應用分享​LINE 技術合作夥伴與應用分享
​LINE 技術合作夥伴與應用分享
 
LINE 開發者社群經營與技術推廣
LINE 開發者社群經營與技術推廣LINE 開發者社群經營與技術推廣
LINE 開發者社群經營與技術推廣
 
日本開發者大會短講分享
日本開發者大會短講分享日本開發者大會短講分享
日本開發者大會短講分享
 
LINE Chatbot - 活動報名報到設計分享
LINE Chatbot - 活動報名報到設計分享LINE Chatbot - 活動報名報到設計分享
LINE Chatbot - 活動報名報到設計分享
 
在 LINE 私有雲中使用 Managed Kubernetes
在 LINE 私有雲中使用 Managed Kubernetes在 LINE 私有雲中使用 Managed Kubernetes
在 LINE 私有雲中使用 Managed Kubernetes
 
LINE TODAY高效率的敏捷測試開發技巧
LINE TODAY高效率的敏捷測試開發技巧LINE TODAY高效率的敏捷測試開發技巧
LINE TODAY高效率的敏捷測試開發技巧
 
LINE 區塊鏈平台及代幣經濟 - LINK Chain及LINK介紹
LINE 區塊鏈平台及代幣經濟 - LINK Chain及LINK介紹LINE 區塊鏈平台及代幣經濟 - LINK Chain及LINK介紹
LINE 區塊鏈平台及代幣經濟 - LINK Chain及LINK介紹
 
LINE Things - LINE IoT平台新技術分享
LINE Things - LINE IoT平台新技術分享LINE Things - LINE IoT平台新技術分享
LINE Things - LINE IoT平台新技術分享
 
LINE Pay - 一卡通支付新體驗
LINE Pay - 一卡通支付新體驗LINE Pay - 一卡通支付新體驗
LINE Pay - 一卡通支付新體驗
 
LINE Platform API Update - 打造一個更好的Chatbot服務
LINE Platform API Update - 打造一個更好的Chatbot服務LINE Platform API Update - 打造一個更好的Chatbot服務
LINE Platform API Update - 打造一個更好的Chatbot服務
 
Keynote - ​LINE 的技術策略佈局與跨國產品開發
Keynote - ​LINE 的技術策略佈局與跨國產品開發Keynote - ​LINE 的技術策略佈局與跨國產品開發
Keynote - ​LINE 的技術策略佈局與跨國產品開發
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

2017年のLINEのマイクロサービスを支えるSpring

  • 2. @imasahiro https://github.com/imasahiro Self Intro l Masahiro Ide l Server side engineer at LINE l Mainly worked on スタンプ/着せかえ ショップ l Contribute to Armeria - Asynchronous RPC/REST library l https://github.com/line/armeria
  • 3. • Where is Spring used at LINE? • Useful/Customized Spring features • Monitoring Agenda
  • 5. LINE System l LINE has hundreds of applications l Recent apps are Java/Spring applications l Mainly communicates with Thrift, and REST l Uses same in-house deployment, monitoring system
  • 7. スタンプショップ l Spring-boot 1.5.8, Spring-MVC l Mostly Asynchronous Http/2 Thrift/REST service l Java8, RxJava2, (Completable|Listenable)Future l Storage l Redis, MySQL, Mongo, ElasticSearch l Monitoring l Micrometer, Dropwizard Metrics, Prometheus, Zipkin
  • 8. Sticker server Mongo MySQL ElasticSearch Redis LINE Client Theme server Search server STORE Server スタンプショップ 構成
  • 9. スタンプショップ l Spring-boot 1.5.8, Spring-MVC l Mostly Asynchronous Http/2 Thrift/REST service l Java8, RxJava2, (Completable|Listenable)Future l Storage l Redis, MySQL, Mongo, ElasticSearch l Monitoring l Micrometer, Dropwizard Metrics, Prometheus, Zipkin
  • 10. l Easy to setup l Have many integrations with other libraries l Mybatis, Thymeleaf, Tomcat, etc. Why spring, why spring-boot? @SpringBootApplication public class SampleApp { @Configuration class MvcConf extends WebMvcConfigurerAdapter {…} public static void main(String[] args) { SpringApplication.run(SampleApp.class, args); } }
  • 11. Simple & Useful Spring features 1. Spring cache abstraction 1. (Spring) AOP 2. Dependency management
  • 12. 1. Spring Cache Abstraction l SpringにおけるCacheの抽象化 l Can choose cache implementation l Redis, Caffeine, Guava, etc. l …But need to use carefully on async service @Cacheable(cacheNames = "listCache") List<Item> selectByLang(String lang) { return sqlSession.selectList(…); }
  • 13. Async support in cache abstraction lNaive (and wrong) solution l This just caches a Future… l But donʼt cache value in Future l See https://jira.spring.io/browse/SPR-12967 @Cacheable(cacheNames = "listCache") CompletableFuture<List<Item>> selectByLang(String lang) { return CompletableFuture.supplyAsync( () -> sqlSession.selectList(…), executor); }
  • 14. Async support in cache abstraction lMade similar cache abstraction l with Caffeine AsyncLoadingCache and Lettuce (Async redis client) @AsyncCacheable(cacheNames = "listCache") CompletableFuture<List<Item>> selectByLang(String lang) { return CompletableFuture.supplyAsync( () -> sqlSession.selectList(…), executor); }
  • 15. Simple & Useful Spring features 1. Spring cache abstraction 1. (Spring) AOP 2. Dependency management
  • 16. 2. (Spring) AOP lAOP - Aspect Oriented Programming l Use case: logging, perf instrumentation @Loggable @GetMapping(“/”) ModelAndView home(…) {…} @Around("@annotation(Loggable)") public Object logging(ProceedingJoinPoint pjp) { Timer timer = newTimer() try { return pjp.proceed(); } finally { long latency = timer.stop(); logger.info(“request path: {}, args:{}, latency:{}”, …, latency)); } }
  • 17. Client side MySQL sharding using AOP ApplicationApplication MySQL Slave MySQL Master Shard01 MySQL Slave MySQL Master Shard01 MySQL Slave MySQL Master Shard01 @Shardable List<Item> selectListByUserId(int id) {…} List<DataSource> dataSources = …; @Around("@annotation(Shardable)") Object sharding(ProceedingJoinPoint pjp) { int id = getArguments(pjp)[0]; source = dataSrouces.get(id % 12); useDataSource(source); return pjp.proceed(); }
  • 18. 3. Dependency management lBOM and Dependency management plugin lSpringがlibrary versionを管理してくれる dependencyManagement { imports { mavenBom 'io.spring.platform:platform-bom:Brussels-SR5' } dependencies { dependencySet(group: 'com.linecorp.armeria', version: '0.55.0') { entry 'armeria-tomcat-shaded’ entry 'armeria-thrift0.9-shaded' } dependency 'biz.paluch.redis:lettuce:4.4.1.Final’ … }}
  • 19. スタンプショップ l Spring-boot 1.5.8, Spring-MVC l Mostly Asynchronous Http/2 Thrift/REST service l Java8, RxJava2, (Completable|Listenable)Future l Storage l Redis, MySQL, Mongo, ElasticSearch l Monitoring l Micrometer, Dropwizard Metrics, Prometheus, Zipkin
  • 20. How to make a service asynchronous? l元々はTomcat+Spring MVC or thrift+DBなシステム @Repository public class ShopStorage { List<Item> selectByLang(String lang) { return sqlSession.selectList( “shop.selectByLang”, lang); }} @Controller public class ShopController { @ResponseBody List<Item> home() { return storage.getList(); }}
  • 21. How to make a service asynchronous? lSync accessを1つずつAsyncに書き直す @Repository public class ShopStorage { List<Item> selectByLang(String lang) { return sqlSession.selectList( “shop.selectByLang”, lang); }} @Controller public class ShopController { @ResponseBody List<Item> home() { return storage.getList(); }} @Repository public class AsyncShopStorage { CompletableFuture<List<Item>> selectByLang(String lang) { return CompletableFuture.supplyAsync( () -> sqlSession.selectList( “shop.selectByLang”, lang), executor); }} @Controller public class AsyncShopController { @ResponseBody DeferredResult<List<Item>> home() { result = new DeferredResult<>(); storage.getList() .thenApply(result::setResult); return result; }}
  • 22. • Where is Spring used at LINE? • Useful/Customized Spring features • Monitoring Agenda
  • 23. How to observe our services? lLog l その瞬間に何が起こったかを確認する lMetric l 現在起きている現象のトレンドを確認する lTrace l システム間で何が何が起きているかを確認する
  • 24. How to observe our services? lLog l Slf4j + Kibana lMetric l Micormeter, Prometheus, Dropwizard metrics l Grafana lTrace l Zipkin l io.zipkin.brave:brave-instrumentation-mysql l io.zipkin.brave:brave-instrumentation-spring-webmvc l And elasticsearch, mongo, redis integrations, etc.
  • 25. Micrometer l Supports multiple monitoring tools l Dropwizard Metrics, Prometheus, etc. l Will be provide as a Spring Boot 2.0 metrics collection l Already used in production servers l Found some concurrency issues but now looks stable l https://github.com/micrometer-metrics/micrometer/issues/139 l https://github.com/micrometer-metrics/micrometer/issues/172 l https://github.com/micrometer-metrics/micrometer/issues/208
  • 26. Prometheus lSimple TSDB, Pull型 lSupports querying, alerting Application # HELP armeria_client_response_duration_seconds # TYPE armeria_client_response_duration_seconds summary armeria_client_response_duration_seconds{method="sendMessage", service=”Service",quantile="0.5",} 8.194E-4 armeria_client_response_duration_seconds{method="sendMessage", service=”Service",quantile="0.75",} 9.494E-4 armeria_client_response_duration_seconds{method="sendMessage", service=”Service",quantile="0.90",} 9.994E-4 … /internal/metrics Node exporterPrometheus pull ApplicationNode exporter
  • 29. Put all together lArmeria - Spring, micrometer, zipkin integration @Bean ThriftServiceRegistrationBean service(MyService.AsyncIface myService, Tracing tracing) { return new ThriftServiceRegistrationBean() .setPath("/thrift/") .setService( THttpService.of(shopCapabilityService) .decorate(LoggingService.newDecorator()) .decorate(MetricCollectingService.newDecorator( MeterIdFunction.ofDefault("LineShopService"))) .decorate(HttpTracingService.newDecorator(tracing)))); }