enabling microservice architectures with scalacufp.org/2013/slides/scaldeferri.pdf · •...

41
ENABLING MICROSERVICE ARCHITECTURES WITH SCALA Kevin Scaldeferri Gilt Groupe Sept 22, 2013

Upload: others

Post on 20-May-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

ENABLING MICROSERVICE ARCHITECTURES WITH

SCALA

Kevin ScaldeferriGilt Groupe

Sept 22, 2013

Page 2: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES
Page 3: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES
Page 4: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

IN THE BEGINNING

Page 5: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

ONE (REALLY) BIG RAILS APP

• ~1000 models and controllers

• ~ 200k lines of Ruby

• ~ 50k lines of PostgreSQL stored procedures

Page 6: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

PROBLEMS WITH MONOLITHIC DESIGN

• Unclear Ownership

• Complex Dependencies

• Lengthy Test Cycles

• Unexpected Performance Impacts

Page 7: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

TRANSITION TO MICROSERVICES

Page 8: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES
Page 9: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

PRACTICES ENABLING MICROSERVICES

Page 10: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

SBT (Build)

Configuration

Testing

Continuous Delivery

Cool Stuff

Page 11: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

SBT

Page 12: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

GILT-SBT-BUILD

•One big SBT plugin pulling in all other plugins

• Lots of custom behavior and standard configuration

• Super simple config for individual services

Page 13: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

gilt.GiltProject.jarSettings

name  :=  "lib-­‐jenkins"

libraryDependencies  ++=  Seq(    "net.databinder"  %%  "dispatch-­‐core"  %  "0.8.8",    "net.databinder"  %%  "dispatch-­‐http"  %  "0.8.8")

Page 14: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

object  Build  extends  ClientServerCoreProject  {    val  name  =  "svc-­‐persistent-­‐session"

   val  coreDeps  =  ...    val  serverDeps  =  ...    val  clientDeps  =  ...}

Page 15: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

PLUGIN PROVIDES

•Nexus config

• Testing & Coverage Libraries

• RPMs

• Standard Run Scripts

•NewRelic Support

• Release Emails

• SemVer Analysis

•Dependency Heuristics

• Integration Builds

• Continuous Delivery hooks

• Auto-Upgrading

• ... and more....

Page 16: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

CONFIGURATION

Page 17: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

SHARED TYPE-SAFE CONFIG

• Common configuration in Zookeeper

•Override with local files or system properties

•Mapped into strongly-typed classes

• JSR-303 (Hibernate) Validation

Page 18: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

case  class  MetricsConfiguration(    @(NotEmpty  @field)  graphiteHost:  String,

   @(Range(min=1024,max=65535)  @field)    graphitePort:  Int}

Page 19: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

TESTING

Page 20: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

CHALLENGES OF TESTING MICRO-SERVICES

• Functional tests are extremely valuable but difficult or impractical to set up

• Unit tests are easy to run, but require complicated mocking and are fragile and unreliable

Page 21: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

SOLUTION

A testing framework which lets one test be both a unit test and a functional test

Page 22: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

CAKE PATTERN

• A pattern for dependency injection and more

• Enables type-safe and scalable composition

• Uses Scala’s self-types and multiple trait inheritance

Page 23: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

trait  ConfigurableClientFactory  {    self:  Configuration  =>

   lazy  val  instance:  Client  =  ...}

object  ClientFactory    extends  ConfigurableClientFactory    with  GiltConfiguration

Page 24: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

trait  TestClients  {    lazy  val  testClient:  Client  =          (          new  ConfigurableClientFactory          with  TestingConfiguration        ).instance}

Page 25: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

abstract  class  ClientTest  extends  TestNGSuite        with  TestClients{    //  Add  your  tests  here}

@Functionalclass  FunctionalClientTest    extends  ClientTest  with  FunctionalTest

@Captureclass  CaptureClientTest    extends  ClientTest  with  CaptureTest

@Mockclass  MockClientTest    extends  ClientTest  with  MockTest

Page 26: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

• SBT configurations filter based on annotations

• sbt  functional:test

• Runs normally against services

• sbt  capture:test

• Like functional but records the results in files

• sbt  test:test

Page 27: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

UI TESTING

Page 28: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

SELENIUM:TEST

• sbt  selenium:test

• Built on ScalaTest Selenium DSL

• Automated browser testing with reusable components

•Makes heavy use of the Scala type system

Page 29: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

@Seleniumclass  Example  extends  FlatSpecTestBasewith  Matchers  with  ConfigurableBrowser  with  LoggedInTestUserwith  OnProductDetailPagewith  AvailableToPurchaseItemwith  InMenswith  CloseBrowserAfterAllTests  {

   "A  size  chart"  should  "be  available"  in  {      //  test  goes  here    }}

Page 30: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

trait  LoggedInTestUser  extends  BeforeAndAfterAll  {    self:  Suite  with  WebBrowser  =>

   override  protected  def  beforeAll()  {        super.beforeAll()        delete  all  cookies

       login(user,  pass).foreach(msg  =>  fail(msg))    }}

Page 31: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

@Seleniumclass  Example  extends  FlatSpecTestBasewith  Matchers  with  ConfigurableBrowser  with  LoggedInTestUserwith  OnProductDetailPagewith  AvailableToPurchaseItemwith  InMenswith  CloseBrowserAfterAllTests  {

   "A  size  chart"  should  "be  available"  in  {      //  test  goes  here    }}

Page 32: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

CONTINUOUS DELIVERY

Page 33: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

IONCANNON

• Fully automated testing & deployment

• sbt  release triggers deployment to a staging environment mirroring production

• Automated tests run

• Promote to production or rollback

Page 34: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES
Page 35: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

THE FUN STUFF

Page 36: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES
Page 37: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

LIVE INVENTORY UPDATES

• Creates excitement and urgency for shoppers

• Simple event-driven Play application

• Uses websockets and Akka actors

Page 38: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

InventoryMaster

Browser inout UserConn

RegisterSkus

Browser inout UserConn

RegisterSkus

SkuUpdate

SkuUpdateBrowser in

out UserConnRegisterSkus

SkuUpdate

SkuUpdate

SkuUpdate

SkuUpdate

Page 39: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES

FREEFALL SALES

• Essentially a Dutch auction

• Similar Web Sockets & Actors implementation

Page 40: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES