Building Micro-Services with Scala 
Lior Shapsa, Yardena Meymann 
September 22, 2014 
© 2014 VMware Inc. All rights reserved.
Traditional Architecture
Traditional Architecture
Problems with Monoliths 
• Size 
• Integration (Conway’s law) 
• Modules Change at Different Rates 
• Dependencies Collisions 
• Scalability requirements of modules 
FEAR OF CHANGE 
FEAR OF INNOVATION
Micro Services
Thought Leaders 
Netflix, Amazon, 
LinkedIn, Google, 
ThoughtWorks, Gilt, 
… 
Fred George 
Martin Fowler 
Kit Colbert 
Ben Fathi 
Stefan Tilkov 
VMware
What are micro-services? 
A set of narrowly focused,
What are micro-services? 
A set of narrowly focused, 
independently deployable services,
What are micro-services? 
A set of narrowly focused, 
independently deployable services, 
talking via uniform interfaces
What are micro-services? 
A set of narrowly focused, 
independently deployable services, 
talking via uniform interfaces
Micro-services 
• Each running in its own process 
• Communicating with lightweight 
mechanisms, often an HTTP 
resource API 
• Built around business capabilities 
• Independently deployable 
– fully automated deployment 
• May be in a different programming language and use 
different data storage technologies.
Micro-services 
DEPLOYING A CHANGE IS LOW RISK
#NonBlocking
Threaded vs. Evented Servers 
• Monolithic 
– Most modules communicate in-process 
• Micro-services 
– communicate remotely, often over the network 
– need to support cheap, lightweight remote communication 
• Threaded servers use thread per connection 
• Evented servers use non-blocking IO and callbacks 
– Netty 
– Node.js 
– Play 
– Spray
services vs. seconds 
http://www.eecs.berkeley.edu/~rcs/research/interactive_latency.html 
https://www.youtube.com/watch?v=1-vcErOPofQ
Threaded servers 
Service A Service B Service N
Threaded servers 
Service A Service B Service N 
Thread Thread Thread
Threaded servers 
Service A Service B Service N 
Thread Thread Thread 
Thread Thread Thread
Threaded servers 
Service A Service B Service N 
Thread Thread Thread 
Thread Thread Thread 
Thread Thread Thread
Thread 
Service A Service B Service N 
Thread 
Thread 
Threaded servers 
Thread 
Thread 
Thread 
Thread 
Thread 
Thread 
Thread 
Thread 
Thread 
Thread 
Thread 
Thread 
Thread Thread Thread
Thread 
Service A Service B Service N 
Thread 
Thread 
Threaded servers 
Thread 
Thread 
Thread 
Thread 
Thread 
Thread 
Thread 
Thread 
Thread 
Thread 
Thread 
Thread 
Thread Thread Thread
#NonBlocking – Evented servers 
Service A Service B Service N 
Thread Thread Thread 
callback callback
#NonBlocking – Play/Spray 
• Based on Akka using Netty 
– Non-blocking programming much easier 
• Easy deployment 
– Embedded Server 
• Rich JSON and HTTP support 
• Plugins 
– Secure Social 
– Caching 
– …. 
• SCALA!
#NonBlocking – Play example 
…
#AKKA
Backend 
Pre-process Analyze
Spray 
Node 
Dispatch 
Crawling 
library 
Netty 
Price Engine 
Head 
Actor 
… 
Pages 
Level1 Level1 
Level2 
… 
Level2 
File 
writer 
Head 
Actor 
… 
k/v 
Node 
Akka Cluster 
curl http://AkkaCluster/site_dot_com?op=start
#AKKA 
• Based on the Actor Model 
– http://www.reversim.com/2014/04/summit-2014-scale-up-your-thinking.html 
• Resilience 
• Location Transparency 
– Cluster sharding 
– Cluster clients 
• Load Balancing 
• Message Queue Integration
#Containers
What is ? 
• Dockers are like lightweight VM for a single process 
– Self contained 
– No hypervisor 
– Shared kernel, but Isolated and content agnostic 
– No lib conflict 
– No OS boot time 
– Distributing a change is easy, using δ 
• A Clean, Safe, Isolated and Portable Micro Service
Docker File 
• Docker Image is Built From a DockerFile 
• Consists of Descriptive Set of Instructions 
– Start from a base image 
– Run and command 
– Add a file or directory 
– Create an environment variable 
– What process to run on launch
SBT 
• Assemble “Dockerized” micro services 
• We started with sbt-native-packager 
– Poor Docker functionality 
• We ended up with sbt-docker plugin 
– https://github.com/marcuslonnberg/sbt-docker 
– Still Using sbt-native-packager to package 
– Ends up with Docker file
Price Engine Service
#Containers - DockerFile
#Containers – Using SBT
#Containers – Using SBT 
• Using Sequences to optimize 
– Reduce build time 
– Smaller Containers
#Containers – Orchestration 
• CoreOS 
– Linux for massive server deployments 
– Cluster management with Fleet 
– Service discovery with etcd 
• Evaluating 
– Kubernetes 
– Flynn 
– Consul 
– Ambassadord
#AKKA 
Summary 
#NonBloc 
king 
#Containers
Lior Shapsa 
lshapsa@gmail.com 
Twitter: @liorshapsa 
Yardena Meymann 
ymeymann@gmail.com 
Twitter: @ymeymann

Building Micro-Services with Scala

  • 1.
    Building Micro-Services withScala Lior Shapsa, Yardena Meymann September 22, 2014 © 2014 VMware Inc. All rights reserved.
  • 2.
  • 3.
  • 4.
    Problems with Monoliths • Size • Integration (Conway’s law) • Modules Change at Different Rates • Dependencies Collisions • Scalability requirements of modules FEAR OF CHANGE FEAR OF INNOVATION
  • 5.
  • 6.
    Thought Leaders Netflix,Amazon, LinkedIn, Google, ThoughtWorks, Gilt, … Fred George Martin Fowler Kit Colbert Ben Fathi Stefan Tilkov VMware
  • 7.
    What are micro-services? A set of narrowly focused,
  • 8.
    What are micro-services? A set of narrowly focused, independently deployable services,
  • 9.
    What are micro-services? A set of narrowly focused, independently deployable services, talking via uniform interfaces
  • 10.
    What are micro-services? A set of narrowly focused, independently deployable services, talking via uniform interfaces
  • 11.
    Micro-services • Eachrunning in its own process • Communicating with lightweight mechanisms, often an HTTP resource API • Built around business capabilities • Independently deployable – fully automated deployment • May be in a different programming language and use different data storage technologies.
  • 12.
    Micro-services DEPLOYING ACHANGE IS LOW RISK
  • 13.
  • 14.
    Threaded vs. EventedServers • Monolithic – Most modules communicate in-process • Micro-services – communicate remotely, often over the network – need to support cheap, lightweight remote communication • Threaded servers use thread per connection • Evented servers use non-blocking IO and callbacks – Netty – Node.js – Play – Spray
  • 15.
    services vs. seconds http://www.eecs.berkeley.edu/~rcs/research/interactive_latency.html https://www.youtube.com/watch?v=1-vcErOPofQ
  • 16.
    Threaded servers ServiceA Service B Service N
  • 17.
    Threaded servers ServiceA Service B Service N Thread Thread Thread
  • 18.
    Threaded servers ServiceA Service B Service N Thread Thread Thread Thread Thread Thread
  • 19.
    Threaded servers ServiceA Service B Service N Thread Thread Thread Thread Thread Thread Thread Thread Thread
  • 20.
    Thread Service AService B Service N Thread Thread Threaded servers Thread Thread Thread Thread Thread Thread Thread Thread Thread Thread Thread Thread Thread Thread Thread
  • 21.
    Thread Service AService B Service N Thread Thread Threaded servers Thread Thread Thread Thread Thread Thread Thread Thread Thread Thread Thread Thread Thread Thread Thread
  • 22.
    #NonBlocking – Eventedservers Service A Service B Service N Thread Thread Thread callback callback
  • 23.
    #NonBlocking – Play/Spray • Based on Akka using Netty – Non-blocking programming much easier • Easy deployment – Embedded Server • Rich JSON and HTTP support • Plugins – Secure Social – Caching – …. • SCALA!
  • 24.
  • 25.
  • 26.
  • 27.
    Spray Node Dispatch Crawling library Netty Price Engine Head Actor … Pages Level1 Level1 Level2 … Level2 File writer Head Actor … k/v Node Akka Cluster curl http://AkkaCluster/site_dot_com?op=start
  • 28.
    #AKKA • Basedon the Actor Model – http://www.reversim.com/2014/04/summit-2014-scale-up-your-thinking.html • Resilience • Location Transparency – Cluster sharding – Cluster clients • Load Balancing • Message Queue Integration
  • 29.
  • 30.
    What is ? • Dockers are like lightweight VM for a single process – Self contained – No hypervisor – Shared kernel, but Isolated and content agnostic – No lib conflict – No OS boot time – Distributing a change is easy, using δ • A Clean, Safe, Isolated and Portable Micro Service
  • 31.
    Docker File •Docker Image is Built From a DockerFile • Consists of Descriptive Set of Instructions – Start from a base image – Run and command – Add a file or directory – Create an environment variable – What process to run on launch
  • 32.
    SBT • Assemble“Dockerized” micro services • We started with sbt-native-packager – Poor Docker functionality • We ended up with sbt-docker plugin – https://github.com/marcuslonnberg/sbt-docker – Still Using sbt-native-packager to package – Ends up with Docker file
  • 33.
  • 34.
  • 35.
  • 36.
    #Containers – UsingSBT • Using Sequences to optimize – Reduce build time – Smaller Containers
  • 37.
    #Containers – Orchestration • CoreOS – Linux for massive server deployments – Cluster management with Fleet – Service discovery with etcd • Evaluating – Kubernetes – Flynn – Consul – Ambassadord
  • 38.
    #AKKA Summary #NonBloc king #Containers
  • 42.
    Lior Shapsa lshapsa@gmail.com Twitter: @liorshapsa Yardena Meymann ymeymann@gmail.com Twitter: @ymeymann

Editor's Notes

  • #29 Messaging – Kafka Resilience - Handles Failures with Supervision
  • #38 We write unit files that tells the CoreOS fleet scheduler how to deploy our Docker containers. We will use the etcd key-value store to communicate between our application containers.
  • #40 Logs Monitoring
  • #41 Logs Monitoring
  • #42 Logs Monitoring