SlideShare a Scribd company logo
Codemotion 2015,
Berlin, Germany
Building a
Reactive RESTful API
with Akka Http & Slick
Dan Persa - @danpersa
Dan Persa
● Senior Software Engineer
● Twitter: @danpersa
● dan.persa@zalando.de
EUROPE’S LEADING ONLINE FASHION PLATFORM
15 countries
3 fulfillment centers
16+ million active customers
2.2+ billion € revenue 2014
130+ million visits per month
9.000+ employees
Visit us: tech.zalando.com
Building a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & Slick
ZALANDO
TECHNOLOGY
Building a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & Slick
500+
Apps
800+
Tech employees
August
Building a Reactive RESTful API with Akka Http & Slick
Conway’s Law
“organizations which design systems
...are constrained to produce designs
which are copies of the
communication structures of these
organizations”
ARCHITECTURE
AN
ARCHITECTURE
FOR
INNOVATION
API FIRST
REST
SAAS
MICRO SERVICES
CLOUD
OPEN SOURCE
Building a Reactive RESTful API with Akka Http & Slick
THE SHOP
MONOLITH
http://blog.codinghorror.com/new-programming-jargon/
We call it
“Jimmy”
Thousands of Java classes, undocumented features
Business logic on all layers (including the database)
MICROSERVICES
Internet
LB
SKIPPER
SKIPPER
SKIPPER
SKIPPER
JIMMY
MOSAIC
INNKEEPER
INNKEEPER
INNKEEPERLB
REST
APIs
HIGHLY AVAILABLE
0 DOWNTIME
RELIABLE
FAST
INNKEEPER
github.com/zalando/innkeeper
API FIRST
REST
FORMAL
SPECIFICATION
FOR
RESTful APIs
The World's Most Popular Framework for APIs.
Building a Reactive RESTful API with Akka Http & Slick
REST RESOURCES
GET /routes
GET /routes/{id}
POST /routes
DELETE /routes/{id}
GET /updated-
routes/{id}
GOING
REACTIVE
Building a Reactive RESTful API with Akka Http & Slick
MODEL DBCONTROLLER
BUFFERBUFFER
DB RecordsDTOsJSON
CLIENT
TRADITIONAL APPLICATION
HTTP Request Method Call SQL
Blocking IO
MODEL DBCONTROLLER
DB StreamDTOsJSON
CLIENT
REACTIVE APPLICATION
HTTP Request Method Call SQL
Non-Blocking IO
StreamStreamStream
Scala
Typesafe
Composable
Meet
Separation of I/0
Resilience
Reactive Streams
Meet
def routesModifiedSince(localDateTime: LocalDateTime):
DatabasePublisher[RouteRow] = {
}
val routesTable = TableQuery[RoutesTable]
val q = for {
routeRow <- routesTable
if (routeRow.createdAt > localDateTime
| routeRow.deletedAt > localDateTime)
} yield routeRow
db.stream {
q.result
}
Composable
Materializable
Reactive Streams
Meet
Streams
import akka.stream.scaladsl.Source
def findRoutesModifiedSince(localDateTime: LocalDateTime):
Source[Route, Unit] = {
}
Source(
).mapConcat(_.toList)
routesRepo.selectModifiedSince(localDateTime).mapResult { row =>
}
row.id.map { id =>
Route(
id = id,
route = row.routeJson.parseJson.convertTo[NewRoute],
row.createdAt,
row.deletedAt
)
}
val route =
path("hello") {
get {
complete {
<h1>Hello World</h1>
}
}
}
Meet
Http
object Main extends App {
}
implicit val system = ActorSystem("my-system")
implicit val materializer = ActorMaterializer()
val route = ...
val bindingFuture =
Http().bindAndHandle(route, "localhost", 8080)
...
Innkeeper’s AKKA HTTP Routes
val route =
path("updated-routes" / Rest) { lastModifiedString =>
get { complete(…) }
} ~ path("routes") {
get { complete(…) }
~ post { complete(…) }
} ~ path("routes" / LongNumber) { id =>
get { … }
~ delete { … }
}
path("routes") {
get {
complete {
HttpResponse(
)
}
}
}
entity = HttpEntity.Chunked(
MediaTypes.`application/json`,
chunkedStreamSource
)
val chunkedStreamSource =
jsonService.sourceToJsonSource(routesService.allRoutes)
def sourceToJsonSource[T](source: Source[T, Unit])
(implicit writer: JsonWriter[T]):
Source[ChunkStreamPart, ((Unit, Unit), Unit)] = {
val commaSeparatedRoutes: Source[ChunkStreamPart, Unit] =
source
.map(t => Some(t.toJson.compactPrint))
.scan[Option[ChunkStreamPart]](None)({
case (None, Some(sourceElement)) => Some(ChunkStreamPart(sourceElement))
case (_, Some(sourceElement)) => Some(ChunkStreamPart(s", $sourceElement"))
})
.mapConcat(_.toList)
Source.single(ChunkStreamPart("[")) ++
commaSeparatedRoutes ++
Source.single(ChunkStreamPart("]"))
}
SAAS
OAUTH
val route: RequestContext => Future[RouteResult] =
authenticationToken { token =>
authenticate(token, authService) { authenticatedUser =>
path("updated-routes" / Rest) { lastModifiedString =>
get {
hasOneOfTheScopes(authenticatedUser)(scopes.READ) {
...
import akka.http.scaladsl._
import akka.http.scaladsl.server.directives.HeaderDirectives._
trait OAuthDirectives {
def authenticationToken: Directive1[String] =
headerValue(optionalValue("authorization")) |
reject {
AuthenticationFailedRejection(
CredentialsMissing,
HttpChallenge("", "")
)
}
...
CLOUD
STUPS.IO
FROM zalando/openjdk:8u45-b14-5
MAINTAINER Team Spearheads <team-spearheads@zalando.de>
EXPOSE 8080
RUN mkdir -p /opt/innkeeper
ADD target/scala-2.11/innkeeper-assembly-0.0.1.jar
/opt/innkeeper/
WORKDIR /opt/innkeeper
ENTRYPOINT java $(java-dynamic-memory-opts) -Dinnkeeper.env=prod
-server -jar innkeeper-assembly-0.0.1.jar
docker:
sbt assembly
docker build -t innkeper:latest-SNAPSHOT .
docker-push:
docker push innkeper:latest-SNAPSHOT
docker-run:
docker run -p 8080:8080 -t innkeper:latest-SNAPSHOT
test-db:
docker run -e POSTGRES_PASSWORD=innkeeper-test -e POSTGRES_USER=innkeeper-test
-p 5433:5432 postgres:9.4
tick:
senza create senza.yaml tick latest-SNAPSHOT
tock:
senza create senza.yaml tock latest-SNAPSHOT
OPEN
SOURCE
github.com/zalando/innkeeper
DO
OSF
RADICAL AGILITY
TRUST
INSTEAD OF CONTROL
Building a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & Slick
# use Docker-based container (instead of OpenVZ)
sudo: false
cache:
directories:
- $HOME/.sbt
- $HOME/.ivy2
language: scala
script:
- sbt ++$TRAVIS_SCALA_VERSION test
- sbt ++$TRAVIS_SCALA_VERSION it:test
# Trick to avoid unnecessary cache updates
- find $HOME/.sbt -name "*.lock" | xargs rm
scala:
- 2.11.7
jdk:
- oraclejdk8
addons:
postgresql: "9.4"
before_script:
- psql -c 'CREATE ROLE innkeepertest superuser login createdb;' -U postgres
- psql -c 'CREATE DATABASE innkeepertest;' -U postgres
NEXT
STEPS
APPLICATION LOGS: SCALYR
TODO: Screenshot
ZMON
Where to Find Us:
Tech Blog: tech.zalando.com
GitHub: github.com/zalando
Innkeeper: github.com/zalando/innkeeper
Twitter: @ZalandoTech
Instagram: zalandotech
Jobs: http://tech.zalando.com/jobs
THANK YOU!
QUESTIONS?

More Related Content

Similar to Building a Reactive RESTful API with Akka Http & Slick (20)

PDF
DevOps in the era of serverless computing - Alessandro Vozza - Codemotion Ams...
Codemotion
 
PDF
Big Data LDN 2017: Processing Fast Data With Apache Spark: the Tale of Two APIs
Matt Stubbs
 
PPTX
Making Swift even safer
Denis Fileev
 
PDF
The use case of a scalable architecture
Toru Wonyoung Choi
 
PPTX
Intro to Akka Streams
Michael Kendra
 
PDF
A Tour of Building Web Applications with R Shiny
Wendy Chen Dubois
 
PPTX
Dan Persa, Maximilian Fellner - The recipe for scalable frontends - Codemotio...
Codemotion
 
PPTX
Azure F#unctions
☁️ Mikhail Shilkov
 
PDF
Deliver Business Value Faster with AWS Step Functions
Daniel Zivkovic
 
PDF
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
GeeksLab Odessa
 
PDF
PyData Berlin Meetup
Steffen Wenz
 
PDF
Capacity Planning for Linux Systems
Rodrigo Campos
 
PDF
shiny.pdf
Ashwini Kalantri
 
PPTX
.NET Foundation, Future of .NET and C#
Bertrand Le Roy
 
PPTX
Microsoft 2014 Dev Plataform - Roslyn -& ASP.NET vNext
Rodolfo Finochietti
 
PPTX
Meet the squirrel @ #CSHUG
Márton Balassi
 
PDF
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
All Things Open
 
PDF
How to ship customer value faster with step functions
Yan Cui
 
PDF
mobl
zefhemel
 
PDF
Streaming Data Flow with Apache Flink @ Paris Flink Meetup 2015
Till Rohrmann
 
DevOps in the era of serverless computing - Alessandro Vozza - Codemotion Ams...
Codemotion
 
Big Data LDN 2017: Processing Fast Data With Apache Spark: the Tale of Two APIs
Matt Stubbs
 
Making Swift even safer
Denis Fileev
 
The use case of a scalable architecture
Toru Wonyoung Choi
 
Intro to Akka Streams
Michael Kendra
 
A Tour of Building Web Applications with R Shiny
Wendy Chen Dubois
 
Dan Persa, Maximilian Fellner - The recipe for scalable frontends - Codemotio...
Codemotion
 
Azure F#unctions
☁️ Mikhail Shilkov
 
Deliver Business Value Faster with AWS Step Functions
Daniel Zivkovic
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
GeeksLab Odessa
 
PyData Berlin Meetup
Steffen Wenz
 
Capacity Planning for Linux Systems
Rodrigo Campos
 
shiny.pdf
Ashwini Kalantri
 
.NET Foundation, Future of .NET and C#
Bertrand Le Roy
 
Microsoft 2014 Dev Plataform - Roslyn -& ASP.NET vNext
Rodolfo Finochietti
 
Meet the squirrel @ #CSHUG
Márton Balassi
 
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
All Things Open
 
How to ship customer value faster with step functions
Yan Cui
 
mobl
zefhemel
 
Streaming Data Flow with Apache Flink @ Paris Flink Meetup 2015
Till Rohrmann
 

More from Zalando Technology (11)

PDF
Stream Processing using Apache Flink in Zalando's World of Microservices - Re...
Zalando Technology
 
PDF
Powering Radical Agility with Docker
Zalando Technology
 
PDF
High Availability PostgreSQL with Zalando Patroni
Zalando Technology
 
PDF
Reactive Design Patterns: a talk by Typesafe's Dr. Roland Kuhn
Zalando Technology
 
PDF
Zalando Tech: From Java to Scala in Less Than Three Months
Zalando Technology
 
PDF
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
Zalando Technology
 
PDF
Radical Agility with Autonomous Teams and Microservices
Zalando Technology
 
PDF
Order Processing at Scale: Zalando at Camunda Community Day
Zalando Technology
 
PDF
ZMON: Monitoring Zalando's Engineering Platform
Zalando Technology
 
PPTX
Mobile Testing Challenges at Zalando Tech
Zalando Technology
 
PDF
Radical Agility with Autonomous Teams and Microservices in the Cloud
Zalando Technology
 
Stream Processing using Apache Flink in Zalando's World of Microservices - Re...
Zalando Technology
 
Powering Radical Agility with Docker
Zalando Technology
 
High Availability PostgreSQL with Zalando Patroni
Zalando Technology
 
Reactive Design Patterns: a talk by Typesafe's Dr. Roland Kuhn
Zalando Technology
 
Zalando Tech: From Java to Scala in Less Than Three Months
Zalando Technology
 
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
Zalando Technology
 
Radical Agility with Autonomous Teams and Microservices
Zalando Technology
 
Order Processing at Scale: Zalando at Camunda Community Day
Zalando Technology
 
ZMON: Monitoring Zalando's Engineering Platform
Zalando Technology
 
Mobile Testing Challenges at Zalando Tech
Zalando Technology
 
Radical Agility with Autonomous Teams and Microservices in the Cloud
Zalando Technology
 
Ad

Recently uploaded (20)

PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Ad

Building a Reactive RESTful API with Akka Http & Slick