$30 off During Our Annual Pro Sale. View Details »

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.

Jakub Janeček

June 23, 2020
Tweet

More Decks by Jakub Janeček

Other Decks in Programming

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

    View Slide

  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.

    View Slide

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

    View Slide

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

    View Slide

  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.

    View Slide

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

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

  10. Demo

    View Slide

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

    View Slide