Building testable APIs using functions & meshes

Building testable APIs using functions & meshes

In this live coding talk you will learn about functional techniques that encourage separation of concerns. I will build a stateful HTTP API from highly isolated components that are easier to test than entangled spaghetti-like codebases. I will show you how tests can help us scaffold the architecture and how should we approach testing in the era of microservices. In the session I will use immutability, type parameters and function parameters as tools to implement a very practical example: Pac-Man game web server. I will code in Scala using Akka HTTP and deploy to Kubernetes with Istio service mesh.

6f6dc1b13fd3fe35d36db3adafcb0c8e?s=128

Michał Płachta

May 10, 2018
Tweet

Transcript

  1. 6.

    @miciek Mocking and Stubbing... Mocking interfaces with 3, 4, 5+

    functions... Mocking interfaces with 0 or 1 functions...
  2. 25.

    @miciek HTTP layer requirements POST /games { “gridName”: “msPacManLevel1” }

    200 OK { “gameId”: 1 } 200 OK { "pacMan": { "position": { "x": 2, "y": 1 }, "direction": "east" } } GET /games/1
  3. 32.

    @miciek Holding multiple games at once A concurrent hash-trie or

    TrieMap is a concurrent thread-safe lock-free implementation of a hash array mapped trie. - Scala documentation http://lampwww.epfl.ch/~prokopec/ctries-snapshot.pdf
  4. 40.

    @miciek Testing on Production Backend service PROD Frontend service PROD

    Service Discovery Circuit Breaking Security Scalability & Routing Telemetry App Container App Container
  5. 41.

    @miciek Testing on Production… in Isolation? Backend service PROD Frontend

    service PROD Sidecar Sidecar Service Discovery Circuit Breaking Security Scalability & Routing Telemetry App Container App Container
  6. 42.

    @miciek Service Mesh Backend service PROD Frontend service PROD Sidecar

    Sidecar Another Service PROD Sidecar Service Mesh Control Plane
  7. 43.

    @miciek Testing on Production… in Isolation Backend service PROD Frontend

    service PROD Sidecar Sidecar Backend service v2 (test) Sidecar Routing only test traffic to v2
  8. 45.

    @miciek New Testing Pyramid Real Fast, Stable, Real No HTTP

    Servers Function parameters Abstracting over data Routing test traffic Isolated tests on PROD
  9. 46.

    @miciek Summary functional programming helps with separation of concerns service

    meshes may help with isolated testing ...but they are new & unproven
  10. 47.

    @miciek Next steps ➔ Play around with https://www.github.com/miciek/pacman-multiplayer-fp project ➔

    Play with Kubernetes and Istio using Katakoda https://www.katacoda.com/courses/istio/deploy-istio-on-kubernetes
  11. 49.