Akka HTTP

Musings from production

@gamsd

In no time...


                        val images = TableQuery[Images]
                        val query = images.take(100).result
                        val fromDatabase: DatabasePublisher[Image] = db.stream(query)

                        Source(fromDatabase)
                        .map({x => println(x); x})
                        .mapAsyncUnordered(gatherMoreInfo)
                        .map(transformInfo)
                        .mapAsyncUnordered(updateImage)
                        .map(logSuccessOrError)
                        .to(Sink.ignore)
                        .run()
                    

I have no idea what I'm doing...


                        akka {
                        stream {
                        materializer {

                        initial-input-buffer-size = 64
                        max-input-buffer-size = 256

                        dispatcher = "doge-dispatcher"

                        subscription-timeout {
                        mode = cancel
                        timeout = 5s
                        }

                        debug-logging = on
                        output-burst-limit = 1000
                        }

                        }
                        }

                        doge-dispatcher {
                        type = Dispatcher
                        executor = "thread-pool-executor"

                        thread-pool-executor {
                        core-pool-size-min = 4
                        core-pool-size-factor = 4.0
                        core-pool-size-max = 20
                        }

                        throughput = 1
                        }
                    

Custom directives


                        val routes = requestLogging {
                        {your open routes} ~
                        authenticateBasic(realm = "YOUR_REALM", BasicAuthenticator.authenticate) {
                        user =>
                        {your protected routes}
                        }
                        }
                    

Implicits FTW


                        implicit def responseWithBody(r: (StatusCode, JsValue)): ToResponseMarshallable = {
                        r._1 -> HttpEntity(`application/json`, r._2.prettyPrint)
                        }
                    

Monitoring Akka HTTP

Annotating the code

Relying on general data

Contributing to Kamon.io

Gatling Simulation


                        val httpConf = http.baseURL("http://localhost:8081")

                        val scn = scenario("Simple Scenario")
                        .during(5 minutes) { exec(http("Simple Get").get("/resources")) }

                        setUp(scn.inject(atOnceUsers( x )).protocols(httpConf))
                    

But after all, did we solve our problems or not?

No. We won't solve our distributed problems writing just one or two small APIs.

But we're on a better path now.

Explicit Asynchronicity

Akka HTTP, Dispatch, ReactiveMongo

Always returns Futures

Error/failure handling

Futures encapsulate failures

You handle errors wherever you want

You keep context information

We can still mess up everything

“Given different Turing-complete languages, it is what they make idiomatic that truly sets them apart.”

Performance and elasticity

We won't need to scale these APIs for a long time

If they ever go down due to load, I'll be more excited than worried

Backpressured clients

We still haven't done this

Might let a node to deal with high load

Without crashing overloaded

Would I use Akka HTTP again?

Am I happy with the whole experience?

Wrapping up...

We had no strong requirements

Exciting early results

Promise of Akka HTTP

Wrapping up...

I believe we made a good choice

Wrapping up...

Promising technology

Experience was close to what could have been with other libraries

Community can make it better

Keep building and sharing experiences

Write and discuss elaborate code samples

Write documentation, engage in the mailing lists

Write blogs posts, documentation, engage in the mailing lists

Speak more, show your faces, tell your history

This is not over

Let's take the discussion online

Dive deeper into the problems and how to solve them

Build and improve Akka HTTP community together

Thank you!
Q => A

Akka HTTP

Musings from production

@gamsd

http://engenharia.vivareal.com.br