Building Micro-Services with Scala

Post on 20-Jun-2015

3.381 views 0 download

Tags:

description

"Microservices" is one of the hottest buzzwords and, as usual, everyone wants them, but few know how to build them. In this talk we will offer our interpretation of microservice architecture, and show how we are implementing these ideas: using Scala, Akka, sbt and Docker, we modularized Akka applications, Spark jobs and Play servers. In the talk we will discuss design trade-offs and challenges that we faced in the process, and how we have overcome them. The focus is not on particular features of Scala language or a library, but on building modern applications using the Typesafe stack and other open-source tools.

Transcript of Building Micro-Services with Scala

© 2014 VMware Inc. All rights reserved.

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

Traditional Architecture

Traditional Architecture

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

Micro Services

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

https://www.youtube.com/watch?v=1-vcErOPofQ

http://www.eecs.berkeley.edu/~rcs/research/interactive_latency.html

Threaded servers

Service A Service B Service N

Threaded servers

Thread Thread Thread

Service A Service B Service N

Threaded servers

Thread Thread ThreadThread Thread Thread

Service A Service B Service N

Threaded servers

Thread Thread ThreadThread Thread ThreadThread Thread Thread

Service A Service B Service N

ThreadThreadThread

ThreadThreadThread

ThreadThread

ThreadThread

ThreadThreadThreadThreadThread

Threaded servers

Thread Thread Thread

Service A Service B Service N

ThreadThreadThread

ThreadThreadThread

ThreadThread

ThreadThread

ThreadThreadThreadThreadThread

Threaded servers

Thread Thread Thread

Service A Service B Service N

#NonBlocking – Evented servers

Thread Thread Thread

Service A Service B Service N

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

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

#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

#NonBlocking

#Containers

Q&A

Visit Our Booth

Thank You!

Lior Shapsa

lshapsa@gmail.com

Twitter: @liorshapsa

Yardena Meymann

ymeymann@gmail.com

Twitter: @ymeymann

http://vmware.jobs