Transcript
Page 1: Building Micro-Services with Scala

© 2014 VMware Inc. All rights reserved.

Building Micro-Services with ScalaLior Shapsa, Yardena MeymannSeptember 22, 2014

Page 2: Building Micro-Services with Scala

Traditional Architecture

Page 3: Building Micro-Services with Scala

Traditional Architecture

Page 4: Building Micro-Services with Scala

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

Micro Services

Page 7: Building Micro-Services with Scala

What are micro-services?

A set of narrowly focused,

Page 8: Building Micro-Services with Scala

What are micro-services?

A set of narrowly focused, independently deployable services,

Page 9: Building Micro-Services with Scala

What are micro-services?

A set of narrowly focused, independently deployable services,talking via uniform interfaces

Page 10: Building Micro-Services with Scala

What are micro-services?

A set of narrowly focused, independently deployable services,talking via uniform interfaces

Page 11: Building Micro-Services with Scala

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

Micro-services

DEPLOYING A CHANGE IS LOW RISK

Page 13: Building Micro-Services with Scala

#NonBlocking

Page 14: Building Micro-Services with Scala

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

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

Threaded servers

Service A Service B Service N

Page 17: Building Micro-Services with Scala

Threaded servers

Thread Thread Thread

Service A Service B Service N

Page 18: Building Micro-Services with Scala

Threaded servers

Thread Thread ThreadThread Thread Thread

Service A Service B Service N

Page 19: Building Micro-Services with Scala

Threaded servers

Thread Thread ThreadThread Thread ThreadThread Thread Thread

Service A Service B Service N

Page 20: Building Micro-Services with Scala

ThreadThreadThread

ThreadThreadThread

ThreadThread

ThreadThread

ThreadThreadThreadThreadThread

Threaded servers

Thread Thread Thread

Service A Service B Service N

Page 21: Building Micro-Services with Scala

ThreadThreadThread

ThreadThreadThread

ThreadThread

ThreadThread

ThreadThreadThreadThreadThread

Threaded servers

Thread Thread Thread

Service A Service B Service N

Page 22: Building Micro-Services with Scala

#NonBlocking – Evented servers

Thread Thread Thread

Service A Service B Service N

callback callback

Page 23: Building Micro-Services with Scala

#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

#NonBlocking – Play example

Page 25: Building Micro-Services with Scala

#AKKA

Page 26: Building Micro-Services with Scala

Backend

Pre-process Analyze

Page 27: Building Micro-Services with Scala

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

#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

#Containers

Page 30: Building Micro-Services with Scala

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

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

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

Price Engine Service

Page 34: Building Micro-Services with Scala

#Containers - DockerFile

Page 35: Building Micro-Services with Scala

#Containers – Using SBT

Page 36: Building Micro-Services with Scala

#Containers – Using SBT

• Using Sequences to optimize– Reduce build time

– Smaller Containers

Page 37: Building Micro-Services with Scala

#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

#AKKA

Summary

#NonBlocking

#Containers

Page 39: Building Micro-Services with Scala
Page 40: Building Micro-Services with Scala

Q&A

Page 41: Building Micro-Services with Scala

Visit Our Booth

Page 42: Building Micro-Services with Scala

Thank You!

Lior Shapsa

[email protected]

Twitter: @liorshapsa

Yardena Meymann

[email protected]

Twitter: @ymeymann

http://vmware.jobs


Top Related