ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · •...
Transcript of ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · •...
![Page 1: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/1.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/2.jpg)
![Page 3: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/3.jpg)
![Page 4: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/4.jpg)
IN THE BEGINNING
![Page 5: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/5.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/6.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/7.jpg)
TRANSITION TO MICROSERVICES
![Page 8: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/8.jpg)
![Page 9: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/9.jpg)
PRACTICES ENABLING MICROSERVICES
![Page 10: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/10.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/11.jpg)
SBT
![Page 12: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/12.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/13.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/14.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/15.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/16.jpg)
CONFIGURATION
![Page 17: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/17.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/18.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/19.jpg)
TESTING
![Page 20: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/20.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/21.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/22.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/23.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/24.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/25.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/26.jpg)
• 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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/27.jpg)
UI TESTING
![Page 28: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/28.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/29.jpg)
@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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/30.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/31.jpg)
@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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/32.jpg)
CONTINUOUS DELIVERY
![Page 33: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/33.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/34.jpg)
![Page 35: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/35.jpg)
THE FUN STUFF
![Page 36: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/36.jpg)
![Page 37: ENABLING MICROSERVICE ARCHITECTURES WITH SCALAcufp.org/2013/slides/scaldeferri.pdf · • Unexpected Performance Impacts. TRANSITION TO MICROSERVICES. PRACTICES ENABLING MICROSERVICES.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/37.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/38.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/39.jpg)
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.](https://reader034.fdocuments.net/reader034/viewer/2022042219/5ec5de875d4ab761be6fd275/html5/thumbnails/40.jpg)