Slide 1

Slide 1 text

Scala Server Toolkit How to Write FP Microservice Step-by-step Jakub Janeček, Avast Software LambdaConf 2020 Global Edition June 23, 2020 sca.la/server-toolkit

Slide 2

Slide 2 text

A Bit of History » Scala at Avast since around 2011. » Better Java → idiomatic Scala → FP. » Diverse codebases lacking unified approach. » Lots of in-house solutions.

Slide 3

Slide 3 text

Issues » Lack of common style. » Hard to get newcomers up to speed. » Maintenance of internal libraries.

Slide 4

Slide 4 text

"Solution" » Focus on open source. » Unify the way components/libraries are initialized. » Provide missing integration pieces. » ! Scala Server Toolkit

Slide 5

Slide 5 text

ZIO Sidenote » ZLayer should have been available before! » SST would probably not emerge. » On the other hand: » Constructor-based injection is more approchable to newcomers. » Useful to people not wanting to go full ZIO.

Slide 6

Slide 6 text

Design » Modular based on dependencies. » Functional programming. » Type safe configuration. » Proper resource management. » No DI framework - just constructors.

Slide 7

Slide 7 text

What is available? » http4s server/client (Blaze) » JVM - console, random, thread pools » doobie (JDBC) » Cassandra (official Datastax driver) » Flyway (DB migrations) » Micrometer - JMX, StatsD » PureConfig » Bundles for ZIO and Monix

Slide 8

Slide 8 text

Module object ComponentModule { def make[F[_]](config: ComponentConfig, someDependency: Dependency): Resource[F, Component] = { !!" } }

Slide 9

Slide 9 text

Module Composition for { a !" ComponentAModule.make[Task] b !" ComponentBModule.make[Task](a) c !" ComponentCModule.make[Task](a, b) } yield a

Slide 10

Slide 10 text

Demo

Slide 11

Slide 11 text

Q&A Thank you. » https://github.com/avast/scala-server-toolkit » https://github.com/jakubjanecek » @jakubjanecek All used photos are from Unsplash.