Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scalable Microservices by Sandeep Dinesh

Scalable Microservices by Sandeep Dinesh

More Decks by API Strategy & Practice Conference

Other Decks in Technology

Transcript

  1. @sandeepdinesh Scalable Microservices gRPC and Kubernetes and Containers oh my!

    @sandeepdinesh Sandeep Dinesh, Cloud Developer Advocate
  2. @sandeepdinesh “Write programs that do one thing, and do it

    well. Write programs that work together” - Unix Philosophy UNIX
  3. Everything at Google runs in containers We launch over 2

    billion containers per week. • Gmail, Web Search, Maps, ... • MapReduce, batch, ... • GFS, Colossus, ...
  4. @sandeepdinesh JavaScript var http = require('http'); var server = http.createServer(function

    (request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.end("Hello World\n"); }); server.listen(3000); App
  5. @sandeepdinesh Bash $ docker build -t gcr.io/<project>/frontend:1.0 $ gcloud docker

    push gcr.io/<project>/frontend:1.0 Build the Container
  6. @sandeepdinesh YAML apiVersion: v1 kind: ReplicationController metadata: labels: name: frontend

    name: frontend spec: replicas: 2 selector: name: frontend Frontend Replication Controller template: metadata: labels: name: frontend spec: containers: - image: gcr.io/project-id/frontend:1.0 name: frontend ports: - containerPort: 3000 name: http-server
  7. @sandeepdinesh YAML apiVersion: v1 kind: Service metadata: name: frontend labels:

    name: frontend spec: type: LoadBalancer Frontend Service ports: - port: 80 targetPort: 3000 protocol: TCP selector: name: frontend
  8. @sandeepdinesh “The biggest issue in changing a monolith into microservices

    lies in changing the communication pattern.” - Martin Fowler
  9. message HelloRequest { string greeting = 1; } message HelloResponse

    { string reply = 1; } service HelloService { rpc SayHello(HelloRequest) returns (HelloResponse); } IDL (Interface definition language) Describe once and generate interfaces for any language. Data Model Structure of the request and response. Binary format for network transmission. Wire Format Protocol Buffers
  10. Multiplexing Bidirectional Streaming Flow Control HTTP/2 No more polling, sockets,

    or clunky SSE Control your congestion Single TCP connection
  11. @sandeepdinesh ProtoBuff package geo; service GeoService { rpc DistanceBetween (Points)

    returns (Distance) {} } message Point { float lat = 1; float lng = 2; } message Points { Point origin = 1; Point destination = 2; } message Distance { float distance = 1; } .proto
  12. @sandeepdinesh JavaScript var server = new GeoService({ 'geo.GeoService': { distanceBetween:

    function(call, callback) { callback(null, getDistance(call.request)); } } }); Backend Code
  13. @sandeepdinesh Bash $ docker build -t gcr.io/<project>/backend:1.0 $ gcloud docker

    push gcr.io/<project>/backend:1.0 Build the Container
  14. @sandeepdinesh JavaScript var request = { origin: { lat: 0,

    lng: 0 }, destination: { lat: 15, lng: 15 } } Frontend Code
  15. @sandeepdinesh JavaScript client.distanceBetween(request, function(error, distance) { if (error) { response.end(JSON.stringify(error));

    } else { response.end("Distance = " + JSON.stringify(distance) + "\n"); } }); Frontend Code
  16. @sandeepdinesh Bash $ docker build -t gcr.io/<project>/frontend:2.0 $ gcloud docker

    push gcr.io/<project>/frontend:2.0 Build the Container
  17. @sandeepdinesh YAML apiVersion: v1 kind: ReplicationController metadata: labels: name: backend

    name: backend spec: replicas: 4 selector: name: backend Backend Replication Controller template: metadata: labels: name: backend spec: containers: - image: gcr.io/project-id/backend:1.0 name: backend ports: - containerPort: 50051 name: grpc-server
  18. @sandeepdinesh YAML apiVersion: v1 kind: Service metadata: name: backend labels:

    name: backend spec: Backend Service ports: - port: 50051 targetPort: 50051 selector: name: backend
  19. Thank you! Thank you! Kubernetes: k8s.io gRPC: grpc.io Code: git.io/v4S8y

    Me: @sandeepdinesh Slack: bit.ly/gcp-slack Cloud: cloud.google.com