SlideShare a Scribd company logo
1 of 46
Download to read offline
A BLUEPRINT FOR
SCALA
MICROSERVICES
FEDERICO FEROLDI
CTO / MEASURENCE.COM
@CLOUDIFY
WHO IS THIS GUY?
20 years ago C / C++ / x86 ASM
15 years ago C / C++ / Perl / PHP
10 years ago Ruby / Perl / JS / Java
last 5 years Scala / Ruby / JS / LUA
FoundedWorkedatTechnologies
OUR GOAL
Empower developers with tools
and process to own a service
from development to production.
RATIONALE
Small team: time is scarce
Heavy use of open source
Automate al the things
Sane standards, easy override
MAIN TOPICS
Minimum Viable Service
Deployment & Discovery
Best practices
MINIMUM VIABLE SERVICE
Business Logic
REST API
Configuration
Health / Monitoring
Releasing / Versioning
Packaging
BUSINESS LOGIC = AKKA ACTORS
Sum

Service
HTTP
API
SumOp
SumRes
“ask” pattern
BUSINESS LOGIC = AKKA ACTORS
object SumService {
def props = Props(classOf[SumService])
!
case class SumOp(a: Int, b: Int)
case class SumRes(result: Int)
}
!
class SumService extends Actor {
import SumService._
!
def receive: Receive = {
case SumOp(a, b) => sender() ! SumRes(a + b)
}
}
REST API = SPRAY.IO
Sum

Service
SPRAY
API
SumOp
SumRes
GET /v1/sum
JSON
REST API = SPRAY.IO
case class SumApiResponse(result: Int)
!
object SumProtocol extends DefaultJsonProtocol {
implicit val sumApiResponseFormat = jsonFormat1(SumApiResponse)
}
!
class SumHttpServiceV1(services: Services) {
import SumProtocol._
!
def route = path("v1" / "sum") {
get {
parameters('a.as[Int], 'b.as[Int]) { (a, b) =>
def future = (services.sumService ? SumOp(a, b)).mapTo[SumRes]
onSuccess(future) { response =>
complete(SumApiResponse(response.result))
}
}
}
}
}
API DOCS = SWAGGER
SPRAY-
SWAGGER
GET /
HTML/JSON
docs
API DOCS = SWAGGER
@Api(value = “/v1/sum", description = "Sum numbers.")
class SumHttpServiceV1(services: Services) {
…
}
API DOCS = SWAGGER
!
@ApiOperation(value = "Returns the sum”, httpMethod = “GET")
!
@ApiImplicitParams(Array(
new ApiImplicitParam(
name="a", required=true, dataType="integer", paramType=“query"
),
new ApiImplicitParam(
name="b", required=true, dataType="integer", paramType=“query"
)
))
!
@ApiResponses(Array(
new ApiResponse(
code=200, message="The sum", response=classOf[SumApiResponse]
)
))
!
def route = path("v1" / "sum") { … }
API DOCS = SWAGGER
@ApiModel(description = "Result of the sum")
case class SumApiResponse(
@(ApiModelProperty @field)(value = "The sum of a and b")
result: Int
)
REST API = SPRAY.IO + SWAGGER
CONFIG = TYPESAFE CONFIG
application.conf
development.conf
testing.conf staging.conf
production.conf
CONFIG = TYPESAFE CONFIG
akka.loglevel = "INFO"
!
metrics.carbon = "graphite.local:2003"
!
acme {
environment = "production"
!
svc-calculator {
hostname = “0.0.0.0”
port = "9999"
}
}
application.conf
CONFIG = TYPESAFE CONFIG
include "application"
production.conf
CONFIG = TYPESAFE CONFIG
include "application"

!
akka.loglevel = "DEBUG"
metrics.carbon = "localhost:2003"
!
acme {
environment = "development"
!
svc-calculator {
hostname = "127.0.0.1"
}
}
development.conf
CONFIG = TYPESAFE CONFIG
val config = ConfigFactory.defaultApplication()
$ sbt -Dconfig.resource=development.conf run
Loads application.conf by default
Loads development.conf
CONFIG = TYPESAFE CONFIG
{
mysql_username=${MYSQL_USERNAME}
mysql_password=${MYSQL_PASSWORD}
}
PRO-TIP

Don’t store passwords with source code!
Instead make use ENV vars substitution and
keep passwords in a safe place.
HEALTH = SPRAY + HAPROXY
SPRAY
GET /ping
Load
Balancer
Are you ok?
HEALTH = SPRAY + HAPROXY
def route = get {
path("ping") {
complete("pong")
}
}
PERFMON = METRICS + GRAPHITE
CODAHALE
METRICS
data points
GRAPHITE
CARBON
PERF.MON. = METRICS + GRAPHITE
object MetricsInstrumentation {
val metricRegistry = new MetricRegistry()
}
!
trait Instrumented extends InstrumentedBuilder {
val metricRegistry = MetricsInstrumentation.metricRegistry
}
!
class Actor extends Actor with Instrumented {
val meter = metrics.meter("requests")
!
def receive: Receive = {
!
case Request =>
meter.mark()
!
}
}
PERFMON = METRICS + GRAPHITE
RELEASING = SBT-RELEASE
SNAPSHOT/RELEASE artifacts
Semantic versioning
version.sbt + Git tags
publishing of artifacts
100% customizable process
interactive OR automated
PACKAGING = ASSEMBLY + DOCKER
JVM
SERVICE
(fat jar)
HTTP Requests
METRICS
“Immutable” container
Other Svc HTTP Reqs
PACKAGING = SBT-ASSEMBLY + SBT-DOCKER
docker <<= (docker dependsOn assembly)
!
dockerfile in docker := {
val artifact = (outputPath in assembly).value
val artifactTargetPath = s"/app/${artifact.name}"
new Dockerfile {
from(“acme/javabase")
expose(9999)
add(artifact, artifactTargetPath)
entryPoint("java", "-jar", artifactTargetPath)
}
}
!
imageNames in docker := Seq(
ImageName(
namespace = Some(organization.value),
repository = name.value,
tag = Some("v" + version.value)
)
)
MINIMUM VIABLE SERVICE
Business Logic = Akka
REST API = Spray + Swagger
Configuration = Typesafe Config
Health / Monitoring = Metrics
Packaging = Assembly & Docker
DEPLOYMENT & DISCOVERY
Continuous Integration
Deployment
Service Discovery
CI/DEPLOY = JENKINS + SBT + ANSIBLE
Git repo
Jenkins Jobs + sbt
Test Release Dockerize Deploy
Commit
Staging / Production
Ansible
HOSTING = MESOS/MARATHON
{
"id": "/svc-calculator",
"container": {
"type": "DOCKER",
"docker": {
"image": "docker.com/svc-calculator:1.0.0",
"network": "BRIDGE",
"portMappings": [{
"containerPort": 9999, "protocol": "tcp"
}]
}
},
"env": {"JAVA_ARGS": “-Dconfig.resource=production"},
"cpus": 1,
"mem": 1024,
"instances": 2
}
HOSTING = MESOS/MARATHON
HOSTING = MESOS/MARATHON
Dynamic port mapping
DISCOVERY = ?
mesos1
/svc-calculator /svc-calculator
mesos2
/web-app
mesos3
HOST:PORT?
DISCOVERY = BAMBOO + HAPROXY
mesos1
/svc-calculator /svc-calculator
mesos2
/web-app
mesos3
BAMBOO +
HAPROXY
BAMBOO +
HAPROXY
BAMBOO +
HAPROXY
MARATHON
http://localhost/svc-calculator
:80
:30001:30002
DEPLOYMENT & DISCOVERY
CI = Jenkins + sbt
Deploy = Ansible + Marathon
Discovery = Bamboo + HAProxy
FINAL TIPS
DRY + keep team aligned
Zero friction on new services
DRY: CUSTOM SBT PLUGIN
package com.acme.sbt.plugin
import sbt._
import Keys._
object AcmePlugin extends AutoPlugin {
lazy val acmeBuildSettings = Seq(
scalacOptions ++= Seq(
"-unchecked",
"-deprecation",
"-feature",
"-Xlint",
"-Ywarn-dead-code",
"-target:jvm-1.7"
)
)
} AcmePlugin.scala
FINAL TIP: CUSTOM SBT PLUGIN
import com.acme.sbt.plugin.AcmePlugin._
!
Seq(acmeBuildSettings:_*)
!
// custom project settings
build.sbt
ZERO FRICTION: GITER8 TEMPLATES
% g8 file://g8-svc-spray/ --name=svc-calculator 
-—servicePort=9999
!
Template applied in ./svc-calculator
!
% ls svc-calculator
build.sbt project src version.sbt
Recap
Thank you!
WE’RE HIRING! JOBS@MEASURENCE.COM

More Related Content

What's hot

A Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert FornalA Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert FornalQA or the Highway
 
Scalaz Stream: Rebirth
Scalaz Stream: RebirthScalaz Stream: Rebirth
Scalaz Stream: RebirthJohn De Goes
 
HC - The Mobile Adventure with Phonegap
HC - The Mobile Adventure with PhonegapHC - The Mobile Adventure with Phonegap
HC - The Mobile Adventure with Phonegaphockeycommunity
 
2011 07-27 ecoop innovation network
2011 07-27 ecoop innovation network2011 07-27 ecoop innovation network
2011 07-27 ecoop innovation networkruzannaChitchyan
 
Apache Aries Blog Sample
Apache Aries Blog SampleApache Aries Blog Sample
Apache Aries Blog SampleSkills Matter
 
Testing Java Code Effectively - BaselOne17
Testing Java Code Effectively - BaselOne17Testing Java Code Effectively - BaselOne17
Testing Java Code Effectively - BaselOne17Andres Almiray
 
Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010Binh Nguyen
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkBo-Yi Wu
 
Oracle APEX Performance
Oracle APEX PerformanceOracle APEX Performance
Oracle APEX PerformanceScott Wesley
 
Full-Stack Reativo com Spring WebFlux + Angular - Devs Java Girl
Full-Stack Reativo com Spring WebFlux + Angular - Devs Java GirlFull-Stack Reativo com Spring WebFlux + Angular - Devs Java Girl
Full-Stack Reativo com Spring WebFlux + Angular - Devs Java GirlLoiane Groner
 
Rest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemyRest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemyAlessandro Cucci
 
Middleware PHP - A simple micro-framework
Middleware PHP - A simple micro-frameworkMiddleware PHP - A simple micro-framework
Middleware PHP - A simple micro-frameworkCorley S.r.l.
 
Sane Sharding with Akka Cluster
Sane Sharding with Akka ClusterSane Sharding with Akka Cluster
Sane Sharding with Akka Clustermiciek
 
InterConnect: Java, Node.js and Swift - Which, Why and When
InterConnect: Java, Node.js and Swift - Which, Why and WhenInterConnect: Java, Node.js and Swift - Which, Why and When
InterConnect: Java, Node.js and Swift - Which, Why and WhenChris Bailey
 
Durable functions
Durable functionsDurable functions
Durable functions명신 김
 
Good karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with KarmaGood karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with KarmaExoLeaders.com
 
Oleksandr Tolstykh
Oleksandr TolstykhOleksandr Tolstykh
Oleksandr TolstykhCodeFest
 

What's hot (20)

A Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert FornalA Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert Fornal
 
Scalaz Stream: Rebirth
Scalaz Stream: RebirthScalaz Stream: Rebirth
Scalaz Stream: Rebirth
 
HC - The Mobile Adventure with Phonegap
HC - The Mobile Adventure with PhonegapHC - The Mobile Adventure with Phonegap
HC - The Mobile Adventure with Phonegap
 
2011 07-27 ecoop innovation network
2011 07-27 ecoop innovation network2011 07-27 ecoop innovation network
2011 07-27 ecoop innovation network
 
Apache Aries Blog Sample
Apache Aries Blog SampleApache Aries Blog Sample
Apache Aries Blog Sample
 
Testing Java Code Effectively - BaselOne17
Testing Java Code Effectively - BaselOne17Testing Java Code Effectively - BaselOne17
Testing Java Code Effectively - BaselOne17
 
Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
 
Oracle APEX Performance
Oracle APEX PerformanceOracle APEX Performance
Oracle APEX Performance
 
Full-Stack Reativo com Spring WebFlux + Angular - Devs Java Girl
Full-Stack Reativo com Spring WebFlux + Angular - Devs Java GirlFull-Stack Reativo com Spring WebFlux + Angular - Devs Java Girl
Full-Stack Reativo com Spring WebFlux + Angular - Devs Java Girl
 
Rest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemyRest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemy
 
Middleware PHP - A simple micro-framework
Middleware PHP - A simple micro-frameworkMiddleware PHP - A simple micro-framework
Middleware PHP - A simple micro-framework
 
Sane Sharding with Akka Cluster
Sane Sharding with Akka ClusterSane Sharding with Akka Cluster
Sane Sharding with Akka Cluster
 
InterConnect: Java, Node.js and Swift - Which, Why and When
InterConnect: Java, Node.js and Swift - Which, Why and WhenInterConnect: Java, Node.js and Swift - Which, Why and When
InterConnect: Java, Node.js and Swift - Which, Why and When
 
Kpi driven-java-development
Kpi driven-java-developmentKpi driven-java-development
Kpi driven-java-development
 
Durable functions
Durable functionsDurable functions
Durable functions
 
Good karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with KarmaGood karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with Karma
 
ZIO Queue
ZIO QueueZIO Queue
ZIO Queue
 
Second Level Cache in JPA Explained
Second Level Cache in JPA ExplainedSecond Level Cache in JPA Explained
Second Level Cache in JPA Explained
 
Oleksandr Tolstykh
Oleksandr TolstykhOleksandr Tolstykh
Oleksandr Tolstykh
 

Similar to Federico Feroldi - Scala microservices

Let's play with adf 3.0
Let's play with adf 3.0Let's play with adf 3.0
Let's play with adf 3.0Eugenio Romano
 
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)Amazon Web Services
 
Quick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase ServerQuick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase ServerNic Raboy
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss Andres Almiray
 
Scala45 spray test
Scala45 spray testScala45 spray test
Scala45 spray testkopiczko
 
2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...
2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...
2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...PHP Conference Argentina
 
Scala & sling
Scala & slingScala & sling
Scala & slingmichid
 
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineGoogle Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineRoman Kirillov
 
Webinar - Office 365 & PowerShell : A Match Made in Heaven
Webinar - Office 365 & PowerShell : A Match Made in HeavenWebinar - Office 365 & PowerShell : A Match Made in Heaven
Webinar - Office 365 & PowerShell : A Match Made in HeavenSébastien Levert
 
Cutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQueryCutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQueryWilliam Candillon
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationAjax Experience 2009
 
Function as a Service in private cloud
Function as a Service in private cloud Function as a Service in private cloud
Function as a Service in private cloud lightdelay
 
Data Summer Conf 2018, “Mist – Serverless proxy for Apache Spark (RUS)” — Vad...
Data Summer Conf 2018, “Mist – Serverless proxy for Apache Spark (RUS)” — Vad...Data Summer Conf 2018, “Mist – Serverless proxy for Apache Spark (RUS)” — Vad...
Data Summer Conf 2018, “Mist – Serverless proxy for Apache Spark (RUS)” — Vad...Provectus
 
SharePoint Saturday Ottawa 2015 - Office 365 and PowerShell - A match made in...
SharePoint Saturday Ottawa 2015 - Office 365 and PowerShell - A match made in...SharePoint Saturday Ottawa 2015 - Office 365 and PowerShell - A match made in...
SharePoint Saturday Ottawa 2015 - Office 365 and PowerShell - A match made in...Sébastien Levert
 
Serverless archtiectures
Serverless archtiecturesServerless archtiectures
Serverless archtiecturesIegor Fadieiev
 
Extending Oracle E-Business Suite with Ruby on Rails
Extending Oracle E-Business Suite with Ruby on RailsExtending Oracle E-Business Suite with Ruby on Rails
Extending Oracle E-Business Suite with Ruby on RailsRaimonds Simanovskis
 

Similar to Federico Feroldi - Scala microservices (20)

Let's play with adf 3.0
Let's play with adf 3.0Let's play with adf 3.0
Let's play with adf 3.0
 
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
 
Quick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase ServerQuick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase Server
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss
 
Scala45 spray test
Scala45 spray testScala45 spray test
Scala45 spray test
 
2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...
2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...
2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...
 
Scala & sling
Scala & slingScala & sling
Scala & sling
 
Full Stack Scala
Full Stack ScalaFull Stack Scala
Full Stack Scala
 
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineGoogle Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
 
Webinar - Office 365 & PowerShell : A Match Made in Heaven
Webinar - Office 365 & PowerShell : A Match Made in HeavenWebinar - Office 365 & PowerShell : A Match Made in Heaven
Webinar - Office 365 & PowerShell : A Match Made in Heaven
 
Cutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQueryCutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQuery
 
API gateway setup
API gateway setupAPI gateway setup
API gateway setup
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
 
Function as a Service in private cloud
Function as a Service in private cloud Function as a Service in private cloud
Function as a Service in private cloud
 
Mist - Serverless proxy to Apache Spark
Mist - Serverless proxy to Apache SparkMist - Serverless proxy to Apache Spark
Mist - Serverless proxy to Apache Spark
 
Data Summer Conf 2018, “Mist – Serverless proxy for Apache Spark (RUS)” — Vad...
Data Summer Conf 2018, “Mist – Serverless proxy for Apache Spark (RUS)” — Vad...Data Summer Conf 2018, “Mist – Serverless proxy for Apache Spark (RUS)” — Vad...
Data Summer Conf 2018, “Mist – Serverless proxy for Apache Spark (RUS)” — Vad...
 
SharePoint Saturday Ottawa 2015 - Office 365 and PowerShell - A match made in...
SharePoint Saturday Ottawa 2015 - Office 365 and PowerShell - A match made in...SharePoint Saturday Ottawa 2015 - Office 365 and PowerShell - A match made in...
SharePoint Saturday Ottawa 2015 - Office 365 and PowerShell - A match made in...
 
Serverless archtiectures
Serverless archtiecturesServerless archtiectures
Serverless archtiectures
 
Spark ML Pipeline serving
Spark ML Pipeline servingSpark ML Pipeline serving
Spark ML Pipeline serving
 
Extending Oracle E-Business Suite with Ruby on Rails
Extending Oracle E-Business Suite with Ruby on RailsExtending Oracle E-Business Suite with Ruby on Rails
Extending Oracle E-Business Suite with Ruby on Rails
 

More from Scala Italy

Alessandro Abbruzzetti - Kernal64
Alessandro Abbruzzetti - Kernal64Alessandro Abbruzzetti - Kernal64
Alessandro Abbruzzetti - Kernal64Scala Italy
 
Alberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.jsAlberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.jsScala Italy
 
Andrea Lattuada, Gabriele Petronella - Building startups on Scala
Andrea Lattuada, Gabriele Petronella - Building startups on ScalaAndrea Lattuada, Gabriele Petronella - Building startups on Scala
Andrea Lattuada, Gabriele Petronella - Building startups on ScalaScala Italy
 
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...Scala Italy
 
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaScala Italy
 
Daniela Sfregola - Intro to Akka
Daniela Sfregola - Intro to AkkaDaniela Sfregola - Intro to Akka
Daniela Sfregola - Intro to AkkaScala Italy
 
Mirco Dotta - Akka Streams
Mirco Dotta - Akka StreamsMirco Dotta - Akka Streams
Mirco Dotta - Akka StreamsScala Italy
 
Phil Calçado - Your microservice as a function
Phil Calçado - Your microservice as a functionPhil Calçado - Your microservice as a function
Phil Calçado - Your microservice as a functionScala Italy
 
Scalatra - Massimiliano Dessì (Energeya)
Scalatra - Massimiliano Dessì (Energeya)Scalatra - Massimiliano Dessì (Energeya)
Scalatra - Massimiliano Dessì (Energeya)Scala Italy
 
Scala: the language of languages - Mario Fusco (Red Hat)
Scala: the language of languages - Mario Fusco (Red Hat)Scala: the language of languages - Mario Fusco (Red Hat)
Scala: the language of languages - Mario Fusco (Red Hat)Scala Italy
 
Reflection in Scala Whats, Whys and Hows - Walter Cazzola (Dipartimento di In...
Reflection in Scala Whats, Whys and Hows - Walter Cazzola (Dipartimento di In...Reflection in Scala Whats, Whys and Hows - Walter Cazzola (Dipartimento di In...
Reflection in Scala Whats, Whys and Hows - Walter Cazzola (Dipartimento di In...Scala Italy
 
Simplifying development-short - Mirco Dotta (Typesafe)
Simplifying development-short - Mirco Dotta (Typesafe)Simplifying development-short - Mirco Dotta (Typesafe)
Simplifying development-short - Mirco Dotta (Typesafe)Scala Italy
 
Scala in pratica - Stefano Rocco (MoneyFarm)
Scala in pratica - Stefano Rocco (MoneyFarm)Scala in pratica - Stefano Rocco (MoneyFarm)
Scala in pratica - Stefano Rocco (MoneyFarm)Scala Italy
 

More from Scala Italy (13)

Alessandro Abbruzzetti - Kernal64
Alessandro Abbruzzetti - Kernal64Alessandro Abbruzzetti - Kernal64
Alessandro Abbruzzetti - Kernal64
 
Alberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.jsAlberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.js
 
Andrea Lattuada, Gabriele Petronella - Building startups on Scala
Andrea Lattuada, Gabriele Petronella - Building startups on ScalaAndrea Lattuada, Gabriele Petronella - Building startups on Scala
Andrea Lattuada, Gabriele Petronella - Building startups on Scala
 
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
 
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of Scala
 
Daniela Sfregola - Intro to Akka
Daniela Sfregola - Intro to AkkaDaniela Sfregola - Intro to Akka
Daniela Sfregola - Intro to Akka
 
Mirco Dotta - Akka Streams
Mirco Dotta - Akka StreamsMirco Dotta - Akka Streams
Mirco Dotta - Akka Streams
 
Phil Calçado - Your microservice as a function
Phil Calçado - Your microservice as a functionPhil Calçado - Your microservice as a function
Phil Calçado - Your microservice as a function
 
Scalatra - Massimiliano Dessì (Energeya)
Scalatra - Massimiliano Dessì (Energeya)Scalatra - Massimiliano Dessì (Energeya)
Scalatra - Massimiliano Dessì (Energeya)
 
Scala: the language of languages - Mario Fusco (Red Hat)
Scala: the language of languages - Mario Fusco (Red Hat)Scala: the language of languages - Mario Fusco (Red Hat)
Scala: the language of languages - Mario Fusco (Red Hat)
 
Reflection in Scala Whats, Whys and Hows - Walter Cazzola (Dipartimento di In...
Reflection in Scala Whats, Whys and Hows - Walter Cazzola (Dipartimento di In...Reflection in Scala Whats, Whys and Hows - Walter Cazzola (Dipartimento di In...
Reflection in Scala Whats, Whys and Hows - Walter Cazzola (Dipartimento di In...
 
Simplifying development-short - Mirco Dotta (Typesafe)
Simplifying development-short - Mirco Dotta (Typesafe)Simplifying development-short - Mirco Dotta (Typesafe)
Simplifying development-short - Mirco Dotta (Typesafe)
 
Scala in pratica - Stefano Rocco (MoneyFarm)
Scala in pratica - Stefano Rocco (MoneyFarm)Scala in pratica - Stefano Rocco (MoneyFarm)
Scala in pratica - Stefano Rocco (MoneyFarm)
 

Recently uploaded

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Recently uploaded (20)

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

Federico Feroldi - Scala microservices

  • 1. A BLUEPRINT FOR SCALA MICROSERVICES FEDERICO FEROLDI CTO / MEASURENCE.COM @CLOUDIFY
  • 2. WHO IS THIS GUY? 20 years ago C / C++ / x86 ASM 15 years ago C / C++ / Perl / PHP 10 years ago Ruby / Perl / JS / Java last 5 years Scala / Ruby / JS / LUA FoundedWorkedatTechnologies
  • 3. OUR GOAL Empower developers with tools and process to own a service from development to production.
  • 4. RATIONALE Small team: time is scarce Heavy use of open source Automate al the things Sane standards, easy override
  • 5. MAIN TOPICS Minimum Viable Service Deployment & Discovery Best practices
  • 6. MINIMUM VIABLE SERVICE Business Logic REST API Configuration Health / Monitoring Releasing / Versioning Packaging
  • 7. BUSINESS LOGIC = AKKA ACTORS Sum
 Service HTTP API SumOp SumRes “ask” pattern
  • 8. BUSINESS LOGIC = AKKA ACTORS object SumService { def props = Props(classOf[SumService]) ! case class SumOp(a: Int, b: Int) case class SumRes(result: Int) } ! class SumService extends Actor { import SumService._ ! def receive: Receive = { case SumOp(a, b) => sender() ! SumRes(a + b) } }
  • 9. REST API = SPRAY.IO Sum
 Service SPRAY API SumOp SumRes GET /v1/sum JSON
  • 10. REST API = SPRAY.IO case class SumApiResponse(result: Int) ! object SumProtocol extends DefaultJsonProtocol { implicit val sumApiResponseFormat = jsonFormat1(SumApiResponse) } ! class SumHttpServiceV1(services: Services) { import SumProtocol._ ! def route = path("v1" / "sum") { get { parameters('a.as[Int], 'b.as[Int]) { (a, b) => def future = (services.sumService ? SumOp(a, b)).mapTo[SumRes] onSuccess(future) { response => complete(SumApiResponse(response.result)) } } } } }
  • 11. API DOCS = SWAGGER SPRAY- SWAGGER GET / HTML/JSON docs
  • 12. API DOCS = SWAGGER @Api(value = “/v1/sum", description = "Sum numbers.") class SumHttpServiceV1(services: Services) { … }
  • 13. API DOCS = SWAGGER ! @ApiOperation(value = "Returns the sum”, httpMethod = “GET") ! @ApiImplicitParams(Array( new ApiImplicitParam( name="a", required=true, dataType="integer", paramType=“query" ), new ApiImplicitParam( name="b", required=true, dataType="integer", paramType=“query" ) )) ! @ApiResponses(Array( new ApiResponse( code=200, message="The sum", response=classOf[SumApiResponse] ) )) ! def route = path("v1" / "sum") { … }
  • 14. API DOCS = SWAGGER @ApiModel(description = "Result of the sum") case class SumApiResponse( @(ApiModelProperty @field)(value = "The sum of a and b") result: Int )
  • 15. REST API = SPRAY.IO + SWAGGER
  • 16. CONFIG = TYPESAFE CONFIG application.conf development.conf testing.conf staging.conf production.conf
  • 17. CONFIG = TYPESAFE CONFIG akka.loglevel = "INFO" ! metrics.carbon = "graphite.local:2003" ! acme { environment = "production" ! svc-calculator { hostname = “0.0.0.0” port = "9999" } } application.conf
  • 18. CONFIG = TYPESAFE CONFIG include "application" production.conf
  • 19. CONFIG = TYPESAFE CONFIG include "application"
 ! akka.loglevel = "DEBUG" metrics.carbon = "localhost:2003" ! acme { environment = "development" ! svc-calculator { hostname = "127.0.0.1" } } development.conf
  • 20. CONFIG = TYPESAFE CONFIG val config = ConfigFactory.defaultApplication() $ sbt -Dconfig.resource=development.conf run Loads application.conf by default Loads development.conf
  • 21. CONFIG = TYPESAFE CONFIG { mysql_username=${MYSQL_USERNAME} mysql_password=${MYSQL_PASSWORD} } PRO-TIP
 Don’t store passwords with source code! Instead make use ENV vars substitution and keep passwords in a safe place.
  • 22. HEALTH = SPRAY + HAPROXY SPRAY GET /ping Load Balancer Are you ok?
  • 23. HEALTH = SPRAY + HAPROXY def route = get { path("ping") { complete("pong") } }
  • 24. PERFMON = METRICS + GRAPHITE CODAHALE METRICS data points GRAPHITE CARBON
  • 25. PERF.MON. = METRICS + GRAPHITE object MetricsInstrumentation { val metricRegistry = new MetricRegistry() } ! trait Instrumented extends InstrumentedBuilder { val metricRegistry = MetricsInstrumentation.metricRegistry } ! class Actor extends Actor with Instrumented { val meter = metrics.meter("requests") ! def receive: Receive = { ! case Request => meter.mark() ! } }
  • 26. PERFMON = METRICS + GRAPHITE
  • 27. RELEASING = SBT-RELEASE SNAPSHOT/RELEASE artifacts Semantic versioning version.sbt + Git tags publishing of artifacts 100% customizable process interactive OR automated
  • 28. PACKAGING = ASSEMBLY + DOCKER JVM SERVICE (fat jar) HTTP Requests METRICS “Immutable” container Other Svc HTTP Reqs
  • 29. PACKAGING = SBT-ASSEMBLY + SBT-DOCKER docker <<= (docker dependsOn assembly) ! dockerfile in docker := { val artifact = (outputPath in assembly).value val artifactTargetPath = s"/app/${artifact.name}" new Dockerfile { from(“acme/javabase") expose(9999) add(artifact, artifactTargetPath) entryPoint("java", "-jar", artifactTargetPath) } } ! imageNames in docker := Seq( ImageName( namespace = Some(organization.value), repository = name.value, tag = Some("v" + version.value) ) )
  • 30. MINIMUM VIABLE SERVICE Business Logic = Akka REST API = Spray + Swagger Configuration = Typesafe Config Health / Monitoring = Metrics Packaging = Assembly & Docker
  • 31. DEPLOYMENT & DISCOVERY Continuous Integration Deployment Service Discovery
  • 32. CI/DEPLOY = JENKINS + SBT + ANSIBLE Git repo Jenkins Jobs + sbt Test Release Dockerize Deploy Commit Staging / Production Ansible
  • 34. { "id": "/svc-calculator", "container": { "type": "DOCKER", "docker": { "image": "docker.com/svc-calculator:1.0.0", "network": "BRIDGE", "portMappings": [{ "containerPort": 9999, "protocol": "tcp" }] } }, "env": {"JAVA_ARGS": “-Dconfig.resource=production"}, "cpus": 1, "mem": 1024, "instances": 2 } HOSTING = MESOS/MARATHON
  • 36. DISCOVERY = ? mesos1 /svc-calculator /svc-calculator mesos2 /web-app mesos3 HOST:PORT?
  • 37. DISCOVERY = BAMBOO + HAPROXY mesos1 /svc-calculator /svc-calculator mesos2 /web-app mesos3 BAMBOO + HAPROXY BAMBOO + HAPROXY BAMBOO + HAPROXY MARATHON http://localhost/svc-calculator :80 :30001:30002
  • 38. DEPLOYMENT & DISCOVERY CI = Jenkins + sbt Deploy = Ansible + Marathon Discovery = Bamboo + HAProxy
  • 39. FINAL TIPS DRY + keep team aligned Zero friction on new services
  • 40. DRY: CUSTOM SBT PLUGIN package com.acme.sbt.plugin import sbt._ import Keys._ object AcmePlugin extends AutoPlugin { lazy val acmeBuildSettings = Seq( scalacOptions ++= Seq( "-unchecked", "-deprecation", "-feature", "-Xlint", "-Ywarn-dead-code", "-target:jvm-1.7" ) ) } AcmePlugin.scala
  • 41. FINAL TIP: CUSTOM SBT PLUGIN import com.acme.sbt.plugin.AcmePlugin._ ! Seq(acmeBuildSettings:_*) ! // custom project settings build.sbt
  • 42. ZERO FRICTION: GITER8 TEMPLATES % g8 file://g8-svc-spray/ --name=svc-calculator -—servicePort=9999 ! Template applied in ./svc-calculator ! % ls svc-calculator build.sbt project src version.sbt
  • 43. Recap
  • 44.
  • 45.
  • 46. Thank you! WE’RE HIRING! JOBS@MEASURENCE.COM