Slide 1

Slide 1 text

MONOLITH TO REACTIVE MICROSERVICES

Slide 2

Slide 2 text

s.id/jvm3slide2

Slide 3

Slide 3 text

MONOLITH TO REACTIVE MICROSERVICES EKO KURNIAWAN KHANNEDY ▸ Principal Software Development Engineer at Blibli.com ▸ Part of Research and Development Team at Blibli.com ▸ Code Java almost 10 years, but sometimes code Scala and Go-Lang.

Slide 4

Slide 4 text

THIS MATERIAL IS BASED ON OUR EXPERIENCE AT BLIBLI.COM

Slide 5

Slide 5 text

MONOLITH TO REACTIVE MICROSERVICES AGENDA ▸ Blibli.com ▸ Before : Monolith ▸ After : Microservices ▸ Future : Reactive

Slide 6

Slide 6 text

BLIBLI.COM MONOLITH TO REACTIVE MICROSERVICES

Slide 7

Slide 7 text

MONOLITH TO REACTIVE MICROSERVICES BLIBLI.COM ▸ The first online mall in Indonesia (since 2011). ▸ A subsidiary of Djarum Group. ▸ More than 500 employees. ▸ https://www.youtube.com/watch?v=ymvL5n2MxSc #DSTOUR16

Slide 8

Slide 8 text

MONOLITH TO REACTIVE MICROSERVICES BLIBLI.COM TECH ▸ More than 150 engineers. ▸ More than 80 microservices. ▸ More than 400 nodes in production. ▸ Almost all microservices build using JVM ▸ Spring is our favorite framework (90% microservices).

Slide 9

Slide 9 text

MONOLITH TO REACTIVE MICROSERVICES THIS PAGE NOT SERVED BY SINGLE APP

Slide 10

Slide 10 text

MONOLITH TO REACTIVE MICROSERVICES THIS PAGE NOT SERVED BY SINGLE APP CART
 SERVICE

Slide 11

Slide 11 text

MONOLITH TO REACTIVE MICROSERVICES THIS PAGE NOT SERVED BY SINGLE APP AUTH
 SERVICE CART
 SERVICE

Slide 12

Slide 12 text

MONOLITH TO REACTIVE MICROSERVICES THIS PAGE NOT SERVED BY SINGLE APP SEARCH
 SERVICE AUTH
 SERVICE CART
 SERVICE

Slide 13

Slide 13 text

MONOLITH TO REACTIVE MICROSERVICES THIS PAGE NOT SERVED BY SINGLE APP SEARCH
 SERVICE AUTH
 SERVICE PROMO
 SERVICE CART
 SERVICE

Slide 14

Slide 14 text

MONOLITH TO REACTIVE MICROSERVICES THIS PAGE NOT SERVED BY SINGLE APP SEARCH
 SERVICE AUTH
 SERVICE PROMO
 SERVICE CATEGORY
 SERVICE CART
 SERVICE

Slide 15

Slide 15 text

MONOLITH TO REACTIVE MICROSERVICES THIS PAGE NOT SERVED BY SINGLE APP SEARCH
 SERVICE AUTH
 SERVICE PROMO
 SERVICE CATEGORY
 SERVICE PULSA
 SERVICE CART
 SERVICE

Slide 16

Slide 16 text

MONOLITH TO REACTIVE MICROSERVICES THIS PAGE NOT SERVED BY SINGLE APP SEARCH
 SERVICE AUTH
 SERVICE PROMO
 SERVICE CATEGORY
 SERVICE PULSA
 SERVICE TRAVEL
 SERVICE CART
 SERVICE

Slide 17

Slide 17 text

MONOLITH TO REACTIVE MICROSERVICES JVM MEETUP #2 - MICROSERVICES (SPEAKER : ENDY MUHARDIN) https://www.youtube.com/watch?v=-pgvQScDohw

Slide 18

Slide 18 text

BEFORE MONOLITH TO REACTIVE MICROSERVICES

Slide 19

Slide 19 text

MONOLITH

Slide 20

Slide 20 text

MONOLITH TO REACTIVE MICROSERVICES BLIBLI.COM HISTORY MONOLITH 2011

Slide 21

Slide 21 text

MONOLITH TO REACTIVE MICROSERVICES MONOLITH PROBLEM ▸ The large monolithic code base intimidates developers. ▸ Overloaded IDE. ▸ Overloaded web container. ▸ Scaling the application can be difficult. ▸ Requires a long-term commitment to a technology stack.

Slide 22

Slide 22 text

AFTER MONOLITH TO REACTIVE MICROSERVICES

Slide 23

Slide 23 text

MICROSERVICES

Slide 24

Slide 24 text

MONOLITH TO REACTIVE MICROSERVICES BLIBLI.COM HISTORY MICROSERVICES 2016

Slide 25

Slide 25 text

MONOLITH TO REACTIVE MICROSERVICES MICROSERVICES LOAD BALANCER INTERNET FRONTEND SERVER FRONTEND SERVER FRONTEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER THIRD PARTY DATABASE DATABASE

Slide 26

Slide 26 text

MONOLITH TO REACTIVE MICROSERVICES MICROSERVICES LOAD BALANCER INTERNET FRONTEND SERVER FRONTEND SERVER FRONTEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER THIRD PARTY DATABASE DATABASE LET’S SAY LATENCY GOES UP HERE

Slide 27

Slide 27 text

MONOLITH TO REACTIVE MICROSERVICES MICROSERVICES LOAD BALANCER INTERNET FRONTEND SERVER FRONTEND SERVER FRONTEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER THIRD PARTY DATABASE DATABASE THREAD BLOCKED HERE

Slide 28

Slide 28 text

MONOLITH TO REACTIVE MICROSERVICES MICROSERVICES LOAD BALANCER INTERNET FRONTEND SERVER FRONTEND SERVER FRONTEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER THIRD PARTY DATABASE DATABASE LATENCY GOES UP HERE

Slide 29

Slide 29 text

MONOLITH TO REACTIVE MICROSERVICES MICROSERVICES LOAD BALANCER INTERNET FRONTEND SERVER FRONTEND SERVER FRONTEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER THIRD PARTY DATABASE DATABASE THREAD BLOCKED HERE

Slide 30

Slide 30 text

MONOLITH TO REACTIVE MICROSERVICES MICROSERVICES LOAD BALANCER INTERNET FRONTEND SERVER FRONTEND SERVER FRONTEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER THIRD PARTY DATABASE DATABASE AND HERE

Slide 31

Slide 31 text

MONOLITH TO REACTIVE MICROSERVICES MICROSERVICES LOAD BALANCER INTERNET FRONTEND SERVER FRONTEND SERVER FRONTEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER THIRD PARTY DATABASE DATABASE HERE TOO

Slide 32

Slide 32 text

MONOLITH TO REACTIVE MICROSERVICES MICROSERVICES LOAD BALANCER INTERNET FRONTEND SERVER FRONTEND SERVER FRONTEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER THIRD PARTY DATABASE DATABASE AND THERE

Slide 33

Slide 33 text

MONOLITH TO REACTIVE MICROSERVICES MICROSERVICES LOAD BALANCER INTERNET FRONTEND SERVER FRONTEND SERVER FRONTEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER BACKEND SERVER THIRD PARTY DATABASE DATABASE AND THERE AND DOWN!

Slide 34

Slide 34 text

MICROSERVICES IS JUST A DISTRIBUTED MONOLITH

Slide 35

Slide 35 text

MICROSERVICES IS JUST A DISTRIBUTED MONOLITH IF NOT REACTIVE

Slide 36

Slide 36 text

MONOLITH TO REACTIVE MICROSERVICES MICROSERVICES PROBLEM ▸ Response time increase because too many communication with other systems. ▸ Network failures is your best friend ▸ Microservices mean you will have farms, not pets. ▸ Don’t trust other services

Slide 37

Slide 37 text

FUTURE MONOLITH TO REACTIVE MICROSERVICES

Slide 38

Slide 38 text

GO REACTIVE

Slide 39

Slide 39 text

MONOLITH TO REACTIVE MICROSERVICES BLIBLI.COM TODAY MICROSERVICES 2017 REACTIVE

Slide 40

Slide 40 text

MONOLITH TO REACTIVE MICROSERVICES REACTIVE SYSTEM

Slide 41

Slide 41 text

MONOLITH TO REACTIVE MICROSERVICES REACTIVE ON BLIBLI ▸ Asynchronous ▸ Non-blocking ▸ Location transparency ▸ Fault Tolerance ▸ Back-pressure ▸ Message-Driven

Slide 42

Slide 42 text

MONOLITH TO REACTIVE MICROSERVICES ASYNCHRONOUS

Slide 43

Slide 43 text

MONOLITH TO REACTIVE MICROSERVICES MICROSERVICES

Slide 44

Slide 44 text

MONOLITH TO REACTIVE MICROSERVICES MICROSERVICES MICROSERVICES

Slide 45

Slide 45 text

MONOLITH TO REACTIVE MICROSERVICES MICROSERVICES MICROSERVICES EDGE SERVICE / 
 API GATEWAY

Slide 46

Slide 46 text

MONOLITH TO REACTIVE MICROSERVICES START FROM EDGE SERVICE / API GATEWAY

Slide 47

Slide 47 text

MONOLITH TO REACTIVE MICROSERVICES EDGE SERVICE EDGE
 SERVICE / API
 GATEWAY ANDROID ORDER
 SERVICE MEMBER
 SERVICE AUTH
 SERVICE CART
 SERVICE WISHLIST
 SERVICE … WEB RISK
 SERVICE LOGISTIC
 SERVICE PAYMENT
 SERVICE

Slide 48

Slide 48 text

MONOLITH TO REACTIVE MICROSERVICES CLIENT NETWORK LATENCY EDGE
 SERVICE / API
 GATEWAY

Slide 49

Slide 49 text

MONOLITH TO REACTIVE MICROSERVICES SERVER NETWORK LATENCY EDGE
 SERVICE / API
 GATEWAY

Slide 50

Slide 50 text

MONOLITH TO REACTIVE MICROSERVICES RXJAVA Single member = memberClient.findById(userId) Single order = orderClient.findByOrderId(orderId) Single payment = paymentClient.findByOrderId(orderId) return Single.zip(member, order, response, (a, b, c) -> { return Response.of(a,b,c) })

Slide 51

Slide 51 text

MONOLITH TO REACTIVE MICROSERVICES NON-BLOCKING

Slide 52

Slide 52 text

MONOLITH TO REACTIVE MICROSERVICES TOMCAT THREADPOOL ▸ minThread (default is 25) ▸ maxThread (default is 200) ▸ maxQueueSize (default is Integer.MAX_VALUE)

Slide 53

Slide 53 text

MONOLITH TO REACTIVE MICROSERVICES NON BLOCKING JVM ▸ Use Netty ▸ Use Servlet 3 Async Support

Slide 54

Slide 54 text

MONOLITH TO REACTIVE MICROSERVICES SPRING MVC + RXJAVA @RequestMapping(“/action”) public Single action(@Valid Request request){ service.action(request).map(result -> { Response.from(result); }) }

Slide 55

Slide 55 text

MONOLITH TO REACTIVE MICROSERVICES LOCATION TRANSPARENCY

Slide 56

Slide 56 text

MONOLITH TO REACTIVE MICROSERVICES PETS VS FARMS

Slide 57

Slide 57 text

MONOLITH TO REACTIVE MICROSERVICES SERVER SIDE LOAD BALANCER AUTH SERVICE AUTH SERVICE MEMBER SERVICE MEMBER SERVICE ORDER SERVICE ORDER SERVICE LOAD
 BALANCER LOAD
 BALANCER LOAD
 BALANCER EDGE SERVICE

Slide 58

Slide 58 text

MONOLITH TO REACTIVE MICROSERVICES CLIENT SIDE LOAD BALANCER

Slide 59

Slide 59 text

MONOLITH TO REACTIVE MICROSERVICES CLIENT SIDE LOAD BALANCER AUTH SERVICE AUTH SERVICE MEMBER SERVICE MEMBER SERVICE ORDER SERVICE ORDER SERVICE SERVICE
 REGISTRY EDGE SERVICE EDGE SERVICE CART SERVICE CART SERVICE

Slide 60

Slide 60 text

MONOLITH TO REACTIVE MICROSERVICES SPRING CLOUD + FEIGN + CONSUL @FeignClient(name=“authFeign”, serviceId=“authService”) public class AuthFeign{ @RequestMapping(value = “/users/_login”, method=RequestMethod.POST) Single login(@RequestBody LoginRequest request); }

Slide 61

Slide 61 text

MONOLITH TO REACTIVE MICROSERVICES FAULT TOLERANCE

Slide 62

Slide 62 text

MONOLITH TO REACTIVE MICROSERVICES FAILURE IS YOUR BEST FRIEND ▸ Network Timeout ▸ Http Internal Server Error ▸ Exception

Slide 63

Slide 63 text

MONOLITH TO REACTIVE MICROSERVICES USER DETAIL UI

Slide 64

Slide 64 text

MONOLITH TO REACTIVE MICROSERVICES USER DETAILS API RESPONSE { “email” : “[email protected]”, “firstName” : “Eko Kurniawan”, “lastName” : “Khannedy”, “wishlistCount” : 100, “carts” : […], “…” }

Slide 65

Slide 65 text

MONOLITH TO REACTIVE MICROSERVICES USER DETAILS BACKEND Single member = memberFeign.findById(userId) Single count = wishlistFeign.count(userId) Single> carts = cartFeign.getCurrentCarts(userId) return Single.zip(member, count, carts, (a, b, c) -> { return Response.of(a,b,c) })

Slide 66

Slide 66 text

MONOLITH TO REACTIVE MICROSERVICES WISHLIST FEIGN @FeignClient(name=“wishlistFeign”, serviceId=“wishlistService”, fallback=WishlistFeignFallback.class) public class WishlistFeign{ @RequestMapping(value = “/items/_count”, method=RequestMethod.GET) Single count(@RequestParam String userId); }

Slide 67

Slide 67 text

MONOLITH TO REACTIVE MICROSERVICES WISHLIST FEIGN FALLBACK (POWERED BY HYSTRIX) public class WishlistFeignFallback implements WishlistFeign{ public Single count(String userId){ return Single.just(0); } }

Slide 68

Slide 68 text

MONOLITH TO REACTIVE MICROSERVICES BACK-PRESSURE

Slide 69

Slide 69 text

MONOLITH TO REACTIVE MICROSERVICES BACK-PRESSURE DILEMA CLIENT SERVER 10 ops / sec 1 ops / sec

Slide 70

Slide 70 text

MONOLITH TO REACTIVE MICROSERVICES BACK-PRESSURE DILEMA CLIENT SERVER 1 ops / sec 10 ops / sec

Slide 71

Slide 71 text

MONOLITH TO REACTIVE MICROSERVICES BACK-PRESSURE DILEMA CLIENT SERVER 1 ops / sec 10 ops / sec MAILBOX / QUEUE

Slide 72

Slide 72 text

MONOLITH TO REACTIVE MICROSERVICES HYSTRIX THREADPOOL CONFIGURATION hystrix.threadpool.default.coreSize = 10 hystrix.threadpool.default.maximumSize = 20 hystrix.threadpool.default.maxQueueSize = 100

Slide 73

Slide 73 text

MONOLITH TO REACTIVE MICROSERVICES BACK-PRESSURE WITH FEIGN + HYSTRIX CLIENT SERVER 1 ops / sec 10 ops / sec MAILBOX / QUEUE SIZE = 100 FALLBACK

Slide 74

Slide 74 text

MONOLITH TO REACTIVE MICROSERVICES PROMO FEIGN FALLBACK (POWERED BY HYSTRIX) public class PromoFeignFallback implements PromoFeign{ public Single redeem(@RequestParam String voucher){ return Single.just(Boolean.FALSE); } }

Slide 75

Slide 75 text

MONOLITH TO REACTIVE MICROSERVICES MESSAGE-DRIVEN

Slide 76

Slide 76 text

MONOLITH TO REACTIVE MICROSERVICES TRADITIONAL SYSTEM ORDER
 SERVICE RISK
 SERVICE LOGISTIC
 SERVICE PAYMENT
 SERVICE EDGE
 SERVICE CART
 SERVICE

Slide 77

Slide 77 text

MONOLITH TO REACTIVE MICROSERVICES TRADITIONAL SYSTEM ORDER
 SERVICE RISK
 SERVICE LOGISTIC
 SERVICE PAYMENT
 SERVICE EDGE
 SERVICE CART
 SERVICE PURCHASE
 ORDER

Slide 78

Slide 78 text

MONOLITH TO REACTIVE MICROSERVICES TRADITIONAL SYSTEM ORDER
 SERVICE RISK
 SERVICE LOGISTIC
 SERVICE PAYMENT
 SERVICE EDGE
 SERVICE CART
 SERVICE PURCHASE
 ORDER MOVE
 CART

Slide 79

Slide 79 text

MONOLITH TO REACTIVE MICROSERVICES TRADITIONAL SYSTEM ORDER
 SERVICE RISK
 SERVICE LOGISTIC
 SERVICE PAYMENT
 SERVICE EDGE
 SERVICE CART
 SERVICE PURCHASE
 ORDER MOVE
 CART INSERT
 ORDER

Slide 80

Slide 80 text

MONOLITH TO REACTIVE MICROSERVICES TRADITIONAL SYSTEM ORDER
 SERVICE RISK
 SERVICE LOGISTIC
 SERVICE PAYMENT
 SERVICE EDGE
 SERVICE CART
 SERVICE PURCHASE
 ORDER MOVE
 CART INSERT
 ORDER CONFIRM
 PAYMENT

Slide 81

Slide 81 text

MONOLITH TO REACTIVE MICROSERVICES TRADITIONAL SYSTEM ORDER
 SERVICE RISK
 SERVICE LOGISTIC
 SERVICE PAYMENT
 SERVICE EDGE
 SERVICE CART
 SERVICE PURCHASE
 ORDER MOVE
 CART INSERT
 ORDER CALCULATE
 RISK SCORE CONFIRM
 PAYMENT

Slide 82

Slide 82 text

MONOLITH TO REACTIVE MICROSERVICES TRADITIONAL SYSTEM ORDER
 SERVICE RISK
 SERVICE LOGISTIC
 SERVICE PAYMENT
 SERVICE EDGE
 SERVICE CART
 SERVICE PURCHASE
 ORDER MOVE
 CART INSERT
 ORDER CALCULATE
 RISK SCORE CREATE
 AWB CONFIRM
 PAYMENT

Slide 83

Slide 83 text

MONOLITH TO REACTIVE MICROSERVICES TRADITIONAL SYSTEM ORDER
 SERVICE RISK
 SERVICE LOGISTIC
 SERVICE PAYMENT
 SERVICE EDGE
 SERVICE CART
 SERVICE PURCHASE
 ORDER MOVE
 CART INSERT
 ORDER CALCULATE
 RISK SCORE CREATE
 AWB CONFIRM
 PAYMENT ERROR ERROR

Slide 84

Slide 84 text

MONOLITH TO REACTIVE MICROSERVICES MOVE LONG RUNNING TASK TO MESSAGE DRIVEN

Slide 85

Slide 85 text

MONOLITH TO REACTIVE MICROSERVICES MESSAGE-DRIVEN SYSTEM ORDER
 SERVICE RISK
 SERVICE LOGISTIC
 SERVICE PAYMENT
 SERVICE EDGE
 SERVICE CART
 SERVICE PURCHASE
 ORDER INSERT
 ORDER MESSAGE BROKER RABBIT MQ / KAFKA STOCK
 SERVICE

Slide 86

Slide 86 text

MONOLITH TO REACTIVE MICROSERVICES IN BLIBLI.COM ORDER
 SERVICE RISK
 SERVICE EDGE
 SERVICE RABBIT MQ STOCK
 SERVICE KAFKA ANALYTIC
 SERVICE RECOMMENDATION
 SERVICE TRANSACTIONAL USER ACTIVITY

Slide 87

Slide 87 text

MONOLITH TO REACTIVE MICROSERVICES ONE MORE THING

Slide 88

Slide 88 text

MONOLITH TO REACTIVE MICROSERVICES TIMEOUT

Slide 89

Slide 89 text

MONOLITH TO REACTIVE MICROSERVICES RIBBON & HYSTRIX TIMEOUT CONFIGURATION hystrix.command.default.execution.timeout.enabled=true hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000 authService.ribbon.ConnectTimeout=2000 authService.ribbon.ReadTimeout=2000

Slide 90

Slide 90 text

THANKS

Slide 91

Slide 91 text

MONOLITH TO REACTIVE MICROSERVICES REFERENCES ▸ https://medium.com/netflix-techblog/embracing-the-differences-inside-the-netflix-api-redesign-15fd8b3dc49d ▸ https://medium.com/netflix-techblog/announcing-zuul-edge-service-in-the-cloud-ab3af5be08ee ▸ http://www.reactivemanifesto.org/ ▸ http://microservices.io/ ▸ https://www.nginx.com/blog/service-discovery-in-a-microservices-architecture/ ▸ http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html ▸ https://www.slideshare.net/jboner/without-resilience-nothing-else-matters-56053062 ▸ https://www.slideshare.net/jboner/go-reactive-42084559 ▸ https://articles.microservices.com/monolithic-vs-microservices-architecture-5c4848858f59