Scala Server Toolkit: How to Write FP Microservice Step-by-step

Scala Server Toolkit: How to Write FP Microservice Step-by-step

The world of Scala is full of many options but it is very hard for new Scala developers or teams to know which path to choose. We were dealing with the very same issue with our teams at Avast so after many years of Scala development we codified our best practices into a ""toolbox"" called Scala Server Toolkit (https://github.com/avast/scala-server-toolkit). SST was designed to help with delivering backend microservices written in FP style more quickly and in unified way. It gives your application the necessary structure and leads you to proper tools such as effect data types (ZIO, Monix), resource safety, type safe configuration and composition. Overall you and your team should become more productive.

In this talk I will shortly introduce Scala Server Toolkit and explain why and how it was created. Then I will show you how to write a full-blown microservice using SST.

6048e3cd01eb6e6aaa0c469b6ed7ad08?s=128

Jakub Janeček

June 23, 2020
Tweet

Transcript

  1. 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
  2. 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.
  3. Issues » Lack of common style. » Hard to get

    newcomers up to speed. » Maintenance of internal libraries.
  4. "Solution" » Focus on open source. » Unify the way

    components/libraries are initialized. » Provide missing integration pieces. » ! Scala Server Toolkit
  5. 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.
  6. Design » Modular based on dependencies. » Functional programming. »

    Type safe configuration. » Proper resource management. » No DI framework - just constructors.
  7. 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
  8. Module object ComponentModule { def make[F[_]](config: ComponentConfig, someDependency: Dependency): Resource[F,

    Component] = { !!" } }
  9. Module Composition for { a !" ComponentAModule.make[Task] b !" ComponentBModule.make[Task](a)

    c !" ComponentCModule.make[Task](a, b) } yield a
  10. Demo

  11. Q&A Thank you. » https://github.com/avast/scala-server-toolkit » https://github.com/jakubjanecek » @jakubjanecek All

    used photos are from Unsplash.