ENABLING MICROSERVICE ARCHITECTURES WITH SCALA Kevin Scaldeferri - - PowerPoint PPT Presentation

enabling microservice architectures with scala
SMART_READER_LITE
LIVE PREVIEW

ENABLING MICROSERVICE ARCHITECTURES WITH SCALA Kevin Scaldeferri - - PowerPoint PPT Presentation

ENABLING MICROSERVICE ARCHITECTURES WITH SCALA Kevin Scaldeferri Gilt Groupe Sept 22, 2013 IN THE BEGINNING ONE (REALLY) BIG RAILS APP ~1000 models and controllers ~ 200k lines of Ruby ~ 50k lines of PostgreSQL stored procedures


slide-1
SLIDE 1

ENABLING MICROSERVICE ARCHITECTURES WITH SCALA

Kevin Scaldeferri Gilt Groupe Sept 22, 2013

slide-2
SLIDE 2
slide-3
SLIDE 3
slide-4
SLIDE 4

IN THE BEGINNING

slide-5
SLIDE 5

ONE (REALLY) BIG RAILS APP

  • ~1000 models and controllers
  • ~ 200k lines of Ruby
  • ~ 50k lines of PostgreSQL stored procedures
slide-6
SLIDE 6

PROBLEMS WITH MONOLITHIC DESIGN

  • Unclear Ownership
  • Complex Dependencies
  • Lengthy Test Cycles
  • Unexpected Performance Impacts
slide-7
SLIDE 7

TRANSITION TO MICROSERVICES

slide-8
SLIDE 8
slide-9
SLIDE 9

PRACTICES ENABLING MICROSERVICES

slide-10
SLIDE 10

SBT (Build) Configuration Testing Continuous Delivery

Cool Stuff

slide-11
SLIDE 11

SBT

slide-12
SLIDE 12

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
slide-13
SLIDE 13

gilt.GiltProject.jarSettings name ¡:= ¡"lib-­‑jenkins" libraryDependencies ¡++= ¡Seq( ¡ ¡"net.databinder" ¡%% ¡"dispatch-­‑core" ¡% ¡"0.8.8", ¡ ¡"net.databinder" ¡%% ¡"dispatch-­‑http" ¡% ¡"0.8.8" )

slide-14
SLIDE 14
  • bject ¡Build ¡extends ¡ClientServerCoreProject ¡{

¡ ¡val ¡name ¡= ¡"svc-­‑persistent-­‑session" ¡ ¡val ¡coreDeps ¡= ¡... ¡ ¡val ¡serverDeps ¡= ¡... ¡ ¡val ¡clientDeps ¡= ¡... }

slide-15
SLIDE 15

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....
slide-16
SLIDE 16

CONFIGURATION

slide-17
SLIDE 17

SHARED TYPE-SAFE CONFIG

  • Common configuration in Zookeeper
  • Override with local files or system properties
  • Mapped into strongly-typed classes
  • JSR-303 (Hibernate) Validation
slide-18
SLIDE 18

case ¡class ¡MetricsConfiguration( ¡ ¡@(NotEmpty ¡@field) ¡graphiteHost: ¡String, ¡ ¡@(Range(min=1024,max=65535) ¡@field) ¡ ¡graphitePort: ¡Int }

slide-19
SLIDE 19

TESTING

slide-20
SLIDE 20

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

slide-21
SLIDE 21

SOLUTION

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

slide-22
SLIDE 22

CAKE PATTERN

  • A pattern for dependency injection and more
  • Enables type-safe and scalable composition
  • Uses Scala’s self-types and multiple trait inheritance
slide-23
SLIDE 23

trait ¡ConfigurableClientFactory ¡{ ¡ ¡self: ¡Configuration ¡=> ¡ ¡lazy ¡val ¡instance: ¡Client ¡= ¡... }

  • bject ¡ClientFactory

¡ ¡extends ¡ConfigurableClientFactory ¡ ¡with ¡GiltConfiguration

slide-24
SLIDE 24

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

slide-25
SLIDE 25

abstract ¡class ¡ClientTest ¡extends ¡TestNGSuite ¡ ¡ ¡ ¡with ¡TestClients { ¡ ¡// ¡Add ¡your ¡tests ¡here } @Functional class ¡FunctionalClientTest ¡ ¡extends ¡ClientTest ¡with ¡FunctionalTest @Capture class ¡CaptureClientTest ¡ ¡extends ¡ClientTest ¡with ¡CaptureTest @Mock class ¡MockClientTest ¡ ¡extends ¡ClientTest ¡with ¡MockTest

slide-26
SLIDE 26
  • 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
slide-27
SLIDE 27

UI TESTING

slide-28
SLIDE 28

SELENIUM:TEST

  • sbt ¡selenium:test
  • Built on ScalaTest Selenium DSL
  • Automated browser testing with reusable components
  • Makes heavy use of the Scala type system
slide-29
SLIDE 29

@Selenium class ¡Example ¡extends ¡FlatSpecTestBase with ¡Matchers ¡with ¡ConfigurableBrowser ¡ with ¡LoggedInTestUser with ¡OnProductDetailPage with ¡AvailableToPurchaseItem with ¡InMens with ¡CloseBrowserAfterAllTests ¡{ ¡ ¡"A ¡size ¡chart" ¡should ¡"be ¡available" ¡in ¡{ ¡ ¡ ¡// ¡test ¡goes ¡here ¡ ¡} }

slide-30
SLIDE 30

trait ¡LoggedInTestUser ¡extends ¡BeforeAndAfterAll ¡ { ¡ ¡self: ¡Suite ¡with ¡WebBrowser ¡=> ¡ ¡override ¡protected ¡def ¡beforeAll() ¡{ ¡ ¡ ¡ ¡super.beforeAll() ¡ ¡ ¡ ¡delete ¡all ¡cookies ¡ ¡ ¡ ¡login(user, ¡pass).foreach(msg ¡=> ¡fail(msg)) ¡ ¡} }

slide-31
SLIDE 31

@Selenium class ¡Example ¡extends ¡FlatSpecTestBase with ¡Matchers ¡with ¡ConfigurableBrowser ¡ with ¡LoggedInTestUser with ¡OnProductDetailPage with ¡AvailableToPurchaseItem with ¡InMens with ¡CloseBrowserAfterAllTests ¡{ ¡ ¡"A ¡size ¡chart" ¡should ¡"be ¡available" ¡in ¡{ ¡ ¡ ¡// ¡test ¡goes ¡here ¡ ¡} }

slide-32
SLIDE 32

CONTINUOUS DELIVERY

slide-33
SLIDE 33

IONCANNON

  • Fully automated testing & deployment
  • sbt ¡release triggers deployment to a staging environment

mirroring production

  • Automated tests run
  • Promote to production or rollback
slide-34
SLIDE 34
slide-35
SLIDE 35

THE FUN STUFF

slide-36
SLIDE 36
slide-37
SLIDE 37

LIVE INVENTORY UPDATES

  • Creates excitement and urgency for shoppers
  • Simple event-driven Play application
  • Uses websockets and Akka actors
slide-38
SLIDE 38

Inventory Master

Browser

in

  • ut

UserConn

RegisterSkus

Browser

in

  • ut

UserConn

RegisterSkus SkuUpdate SkuUpdate

Browser

in

  • ut

UserConn

RegisterSkus SkuUpdate SkuUpdate SkuUpdate SkuUpdate

slide-39
SLIDE 39

FREEFALL SALES

  • Essentially a Dutch auction
  • Similar Web Sockets & Actors implementation
slide-40
SLIDE 40
slide-41
SLIDE 41

THANK YOU

@kscaldef kevin@scaldeferri.com