Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Monolith to Reactive Microservices

Monolith to Reactive Microservices

Monolith to Reactive Microservices

Eko Kurniawan Khannedy

May 16, 2017
Tweet

More Decks by Eko Kurniawan Khannedy

Other Decks in Technology

Transcript

  1. 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.
  2. MONOLITH TO REACTIVE MICROSERVICES AGENDA ▸ Blibli.com ▸ Before :

    Monolith ▸ After : Microservices ▸ Future : Reactive
  3. 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
  4. 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).
  5. MONOLITH TO REACTIVE MICROSERVICES THIS PAGE NOT SERVED BY SINGLE

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

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

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

    APP SEARCH
 SERVICE AUTH
 SERVICE PROMO
 SERVICE CATEGORY
 SERVICE PULSA
 SERVICE CART
 SERVICE
  9. 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
  10. MONOLITH TO REACTIVE MICROSERVICES JVM MEETUP #2 - MICROSERVICES (SPEAKER

    : ENDY MUHARDIN) https://www.youtube.com/watch?v=-pgvQScDohw
  11. 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.
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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!
  21. 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
  22. MONOLITH TO REACTIVE MICROSERVICES REACTIVE ON BLIBLI ▸ Asynchronous ▸

    Non-blocking ▸ Location transparency ▸ Fault Tolerance ▸ Back-pressure ▸ Message-Driven
  23. 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
  24. MONOLITH TO REACTIVE MICROSERVICES RXJAVA Single<Member> member = memberClient.findById(userId) Single<Order>

    order = orderClient.findByOrderId(orderId) Single<Payment> payment = paymentClient.findByOrderId(orderId) return Single.zip(member, order, response, (a, b, c) -> { return Response.of(a,b,c) })
  25. MONOLITH TO REACTIVE MICROSERVICES TOMCAT THREADPOOL ▸ minThread (default is

    25) ▸ maxThread (default is 200) ▸ maxQueueSize (default is Integer.MAX_VALUE)
  26. MONOLITH TO REACTIVE MICROSERVICES SPRING MVC + RXJAVA @RequestMapping(“/action”) public

    Single<Response> action(@Valid Request request){ service.action(request).map(result -> { Response.from(result); }) }
  27. 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
  28. 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
  29. MONOLITH TO REACTIVE MICROSERVICES SPRING CLOUD + FEIGN + CONSUL

    @FeignClient(name=“authFeign”, serviceId=“authService”) public class AuthFeign{ @RequestMapping(value = “/users/_login”, method=RequestMethod.POST) Single<Response> login(@RequestBody LoginRequest request); }
  30. MONOLITH TO REACTIVE MICROSERVICES FAILURE IS YOUR BEST FRIEND ▸

    Network Timeout ▸ Http Internal Server Error ▸ Exception
  31. MONOLITH TO REACTIVE MICROSERVICES USER DETAILS API RESPONSE { “email”

    : “[email protected]”, “firstName” : “Eko Kurniawan”, “lastName” : “Khannedy”, “wishlistCount” : 100, “carts” : […], “…” }
  32. MONOLITH TO REACTIVE MICROSERVICES USER DETAILS BACKEND Single<Member> member =

    memberFeign.findById(userId) Single<Integer> count = wishlistFeign.count(userId) Single<List<Item>> carts = cartFeign.getCurrentCarts(userId) return Single.zip(member, count, carts, (a, b, c) -> { return Response.of(a,b,c) })
  33. 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<Integer> count(@RequestParam String userId); }
  34. MONOLITH TO REACTIVE MICROSERVICES WISHLIST FEIGN FALLBACK (POWERED BY HYSTRIX)

    public class WishlistFeignFallback implements WishlistFeign{ public Single<Integer> count(String userId){ return Single.just(0); } }
  35. MONOLITH TO REACTIVE MICROSERVICES HYSTRIX THREADPOOL CONFIGURATION hystrix.threadpool.default.coreSize = 10

    hystrix.threadpool.default.maximumSize = 20 hystrix.threadpool.default.maxQueueSize = 100
  36. MONOLITH TO REACTIVE MICROSERVICES BACK-PRESSURE WITH FEIGN + HYSTRIX CLIENT

    SERVER 1 ops / sec 10 ops / sec MAILBOX / QUEUE SIZE = 100 FALLBACK
  37. MONOLITH TO REACTIVE MICROSERVICES PROMO FEIGN FALLBACK (POWERED BY HYSTRIX)

    public class PromoFeignFallback implements PromoFeign{ public Single<Boolean> redeem(@RequestParam String voucher){ return Single.just(Boolean.FALSE); } }
  38. MONOLITH TO REACTIVE MICROSERVICES TRADITIONAL SYSTEM ORDER
 SERVICE RISK
 SERVICE

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

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

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

    LOGISTIC
 SERVICE PAYMENT
 SERVICE EDGE
 SERVICE CART
 SERVICE PURCHASE
 ORDER MOVE
 CART INSERT
 ORDER
  42. 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
  43. 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
  44. 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
  45. 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
  46. 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
  47. 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
  48. 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
  49. 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