Building microservices with Scala, functional domain models and Spring Boot (#Devnexus)
Building Micro-Services with Scala
-
Upload
yardena-meymann -
Category
Technology
-
view
3.381 -
download
0
description
Transcript of Building Micro-Services with Scala
![Page 1: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/1.jpg)
© 2014 VMware Inc. All rights reserved.
Building Micro-Services with ScalaLior Shapsa, Yardena MeymannSeptember 22, 2014
![Page 2: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/2.jpg)
Traditional Architecture
![Page 3: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/3.jpg)
Traditional Architecture
![Page 4: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/4.jpg)
Problems with Monoliths
• Size
• Integration (Conway’s law)
• Modules Change at Di erent Ratesff• Dependencies Collisions
• Scalability requirements of modules
FEAR OF CHANGE
FEAR OF INNOVATION
![Page 5: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/5.jpg)
Micro Services
![Page 6: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/6.jpg)
Thought Leaders
Netflix, Amazon, LinkedIn, Google,
ThoughtWorks, Gilt, …
Kit Colbert
Ben Fathi
Martin Fowler
Stefan Tilkov
Fred George
VMware
![Page 7: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/7.jpg)
What are micro-services?
A set of narrowly focused,
![Page 8: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/8.jpg)
What are micro-services?
A set of narrowly focused, independently deployable services,
![Page 9: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/9.jpg)
What are micro-services?
A set of narrowly focused, independently deployable services,talking via uniform interfaces
![Page 10: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/10.jpg)
What are micro-services?
A set of narrowly focused, independently deployable services,talking via uniform interfaces
![Page 11: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/11.jpg)
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.
![Page 12: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/12.jpg)
Micro-services
DEPLOYING A CHANGE IS LOW RISK
![Page 13: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/13.jpg)
#NonBlocking
![Page 14: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/14.jpg)
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
![Page 15: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/15.jpg)
services vs. seconds
https://www.youtube.com/watch?v=1-vcErOPofQ
http://www.eecs.berkeley.edu/~rcs/research/interactive_latency.html
![Page 16: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/16.jpg)
Threaded servers
Service A Service B Service N
![Page 17: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/17.jpg)
Threaded servers
Thread Thread Thread
Service A Service B Service N
![Page 18: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/18.jpg)
Threaded servers
Thread Thread ThreadThread Thread Thread
Service A Service B Service N
![Page 19: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/19.jpg)
Threaded servers
Thread Thread ThreadThread Thread ThreadThread Thread Thread
Service A Service B Service N
![Page 20: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/20.jpg)
ThreadThreadThread
ThreadThreadThread
ThreadThread
ThreadThread
ThreadThreadThreadThreadThread
Threaded servers
Thread Thread Thread
Service A Service B Service N
![Page 21: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/21.jpg)
ThreadThreadThread
ThreadThreadThread
ThreadThread
ThreadThread
ThreadThreadThreadThreadThread
Threaded servers
Thread Thread Thread
Service A Service B Service N
![Page 22: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/22.jpg)
#NonBlocking – Evented servers
Thread Thread Thread
Service A Service B Service N
callback callback
![Page 23: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/23.jpg)
#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!
![Page 24: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/24.jpg)
#NonBlocking – Play example
…
![Page 25: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/25.jpg)
#AKKA
![Page 26: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/26.jpg)
Backend
Pre-process Analyze
![Page 27: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/27.jpg)
Node
Dispatch
Crawling library
Netty
Price Engine
Head Actor
…
Pages
Level1 Level1
Level2
…
Level2
File writer
Head Actor
…
k/vk/v
NodeAkka Cluster
curl http://AkkaCluster/site_dot_com?op=start
Spray
![Page 28: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/28.jpg)
#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
![Page 29: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/29.jpg)
#Containers
![Page 30: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/30.jpg)
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
![Page 31: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/31.jpg)
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
![Page 32: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/32.jpg)
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
![Page 33: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/33.jpg)
Price Engine Service
![Page 34: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/34.jpg)
#Containers - DockerFile
![Page 35: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/35.jpg)
#Containers – Using SBT
![Page 36: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/36.jpg)
#Containers – Using SBT
• Using Sequences to optimize– Reduce build time
– Smaller Containers
![Page 37: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/37.jpg)
#Containers – Orchestration
• CoreOS – Linux for massive server deployments
– Cluster management with Fleet
– Service discovery with etcd
• Evaluating– Kubernetes
– Flynn
– Consul
– Ambassadord
![Page 38: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/38.jpg)
#AKKA
Summary
#NonBlocking
#Containers
![Page 39: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/39.jpg)
![Page 40: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/40.jpg)
Q&A
![Page 41: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/41.jpg)
Visit Our Booth
![Page 42: Building Micro-Services with Scala](https://reader035.fdocuments.us/reader035/viewer/2022062707/5584e6c3d8b42a82618b45d0/html5/thumbnails/42.jpg)
Thank You!
Lior Shapsa
Twitter: @liorshapsa
Yardena Meymann
Twitter: @ymeymann
http://vmware.jobs