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

Manage microservices like a Chef

Manage microservices like a Chef

Mathieu Acthernoene

May 30, 2018
Tweet

More Decks by Mathieu Acthernoene

Other Decks in Technology

Transcript

  1. Manage microservices
    like a Chef

    View Slide

  2. Mathieu Acthernoene
    @zoontek

    View Slide

  3. Microservices are
    awesome ✨

    View Slide

  4. Microservices are awesome ✨
    Each service is an app implementing its own
    business logic
    service
    database
    SaaS 1 SaaS 2

    View Slide

  5. Microservices are awesome ✨
    Separated by concern, easier to understand
    what's going on
    auth email sms …

    View Slide

  6. Microservices are awesome ✨
    They can evolve apart, deploy at different
    frequencies
    service 1 service 2 service 3 service 4
    service 1 service 4
    service 4

    View Slide

  7. Microservices are awesome ✨
    If one breaks, you don't have to reboot everything
    service 1 service 3 service 4

    View Slide

  8. Microservices are awesome ✨
    Scales according to the service needs, not globally
    CPU
    intensive
    service
    RAM
    intensive
    service
    GPU
    intensive
    service

    View Slide

  9. Microservices are awesome ✨
    Each service team is free to use the right tools
    service
    using
    couchDB
    service
    using
    JavaScript
    service
    using
    Golang

    View Slide

  10. But

    View Slide

  11. But

    View Slide

  12. Just as you think you're
    making microservices

    View Slide

  13. You might just not

    View Slide

  14. You are not building
    microservices when… #

    View Slide

  15. You are not building
    microservices when… #
    Changes needs to be synced
    service 1 service 1
    change
    service 2

    View Slide

  16. Deploys needs to be synced
    You are not building
    microservices when… #
    service 1 service 1
    deploy
    service 2

    View Slide

  17. The same developers work across a large
    number of them
    service 1
    Kévin
    Sylvie
    Amine
    You are not building
    microservices when… #
    service 2
    Kévin
    Luc
    Clarisse
    service 3
    Kévin
    Zhang
    Nicolas

    View Slide

  18. They share a datastore
    You are not building
    microservices when… #
    service 1
    database
    service 2

    View Slide

  19. They share a lot of the same code / models
    You are not building
    microservices when… #
    service 1
    type User {}
    service 2
    type User {}
    service 3
    type User {}

    View Slide

  20. You just created a distributed
    monolith
    crypto
    REST
    logging
    REST
    email
    REST
    sms
    REST
    storage
    REST
    billing
    REST

    View Slide

  21. View Slide

  22. Managing microservices is
    like managing a restaurant

    View Slide

  23. waiter
    REST
    sous-chef
    REST
    pastry chef
    REST
    wine waiter
    REST
    washer
    REST
    chef
    REST

    View Slide

  24. View Slide

  25. How does a restaurant
    manage services?

    View Slide

  26. View Slide

  27. The “simple” gateway solution
    crypto
    REST
    logging
    REST
    email
    REST
    sms
    REST
    storage
    REST
    billing
    REST
    gateway
    REST

    View Slide

  28. One interlocutor
    passing messages to
    the right services

    View Slide

  29. The REST / JSON gateway issues ⚠
    If a first API is RESTful, the twelfth iteration
    is RESTish
    service API v1

    service API v3

    … service API v9


    View Slide

  30. Latency caused by serialization / deserialization
    service 1 service 2
    API gateway
    decode
    JSON
    understand
    message
    create
    message
    encode
    JSON
    The REST / JSON gateway issues ⚠

    View Slide

  31. You embed your model schemas in every messages
    {
    "login": "octocat",
    "avatar_url": "https://github.com/images/error/octocat_happy.gif",
    "gravatar_id": "",
    "url": "https://api.github.com/users/octocat",
    "html_url": "https://github.com/octocat",

    The REST / JSON gateway issues ⚠

    View Slide

  32. As a service owner, you have to wait for a complete
    implementation of another one to start using it
    service 1
    is finished &
    deployed
    the API
    gateway
    implements
    service 1
    service 2 starts
    implementing
    its usage of
    service 1
    The REST / JSON gateway issues ⚠

    View Slide

  33. As JSON types are basic (JavaScript interop…), a
    documentation is mandatory
    The REST / JSON gateway issues ⚠

    View Slide

  34. How does a restaurant
    manage communication?

    View Slide

  35. View Slide

  36. People working in the
    kitchen don't
    necessarily have the
    same mother tongue

    View Slide

  37. They don't force their
    coworkers to use their
    language

    View Slide

  38. Protobuf ↔

    View Slide

  39. Protobuf ↔
    Created by, and for Google in 2001

    View Slide

  40. A binary format for typed exchanges
    Protobuf ↔

    View Slide

  41. Protobuf ↔
    Generate clients for C++, Java, Python, Go,
    Ruby, C#, JS, ObjC, PHP, Dart…

    View Slide

  42. Offers backward compatibility for free
    Protobuf ↔

    View Slide

  43. Offers a JSON mapping
    Protobuf ↔

    View Slide

  44. Tooling and linters are available
    Protobuf ↔

    View Slide

  45. Allows RPC methods definition
    Protobuf ↔

    View Slide

  46. How to write a .proto file

    View Slide

  47. syntax = "proto3";

    View Slide

  48. package storage;

    View Slide

  49. import "google/protobuf/timestamp.proto";
    import "google/api/annotations.proto";

    View Slide

  50. option java_package = "com.scaleway.storage";

    View Slide

  51. message Bucket {
    enum Attributes {
    LAZY = 0;
    DELUXE = 1;
    }
    string id = 1;
    google.protobuf.Timestamp created_at = 2;
    repeated Attributes attributes = 3;
    int32 old_field = 4 [deprecated=true];
    }

    View Slide

  52. service Storage {
    rpc ListBuckets(ListBucketsRequest) returns (stream Bucket) {
    option (google.api.http) = { get: "/buckets" };
    }
    rpc GetBucket(GetBucketRequest) returns (Bucket) {
    option (google.api.http) = { get: "/buckets/{id}" };
    }
    }
    message ListBucketsRequest { string user_id = 1; }
    message GetBucketRequest { string id = 1; }

    View Slide

  53. syntax = "proto3";
    package storage;
    option java_package = "com.scaleway.storage";
    service Storage {
    rpc ListBuckets(ListBucketsRequest) returns (stream Bucket) {
    option (google.api.http) = { get: "/buckets" };
    }
    rpc GetBucket(GetBucketRequest) returns (Bucket) {
    option (google.api.http) = { get: "/buckets/{id}" };
    }
    }
    message Bucket {
    enum Attributes {
    LAZY = 0;
    DELUXE = 1;
    }
    string id = 1;
    google.protobuf.Timestamp created_at = 2;
    repeated Attributes attributes = 3;
    int32 old_field = 4 [deprecated=true];
    }
    message ListBucketsRequest { string user_id = 1; }
    message GetBucketRequest { string id = 1; }

    View Slide

  54. View Slide

  55. I get Protobuf, but what is gRPC ?
    HTTP/2 clients for Protobuf messages transport

    View Slide

  56. Unaries, uni- and bi-directional streams
    I get Protobuf, but what is gRPC ?

    View Slide

  57. Blocking & Non-Blocking messages
    I get Protobuf, but what is gRPC ?

    View Slide

  58. Authentification (per call, and TLS for trusted
    services)
    I get Protobuf, but what is gRPC ?

    View Slide

  59. Cancellation and timeout handling
    I get Protobuf, but what is gRPC ?

    View Slide

  60. Smart retries with backoff
    I get Protobuf, but what is gRPC ?

    View Slide

  61. Error handling with standardized status codes
    I get Protobuf, but what is gRPC ?

    View Slide

  62. Lameducking for graceful shutdowns
    I get Protobuf, but what is gRPC ?

    View Slide

  63. A huge ecosystem

    View Slide

  64. A huge ecosystem
    Used by Google, Lyft, Uber, Square, Netflix, CoreOS,
    Docker, Cockroachdb, Cisco, Juniper Networks…

    View Slide

  65. A huge ecosystem
    Supported by nginx, kubernetes, envoy, etcd, istio…

    View Slide

  66. A huge ecosystem
    A lot of middlewares available

    View Slide

  67. A huge ecosystem
    A HTTP+JSON interface available

    View Slide

  68. A new service is created
    protos
    monorepo
    crypto
    gRPC
    logging
    gRPC
    email
    gRPC
    sms
    gRPC
    storage
    gRPC
    billing
    gRPC
    service
    discovery
    ML
    gRPC

    View Slide

  69. And for the front-end?

    View Slide

  70. How does a restaurant
    expose services to a client?

    View Slide

  71. View Slide

  72. GraphQL

    View Slide

  73. A request example
    (developer.github.com/v4/explorer)

    View Slide

  74. dashboard
    CLI
    API gateway
    mobile app
    GraphQL
    adapter
    protos
    monorepo
    crypto
    gRPC
    gRPC
    logging
    gRPC
    email
    gRPC
    sms
    gRPC
    storage
    gRPC
    billing
    gRPC
    service
    discovery
    gRPC REST

    View Slide

  75. View Slide

  76. Keep in mind that there's
    no silver bullet

    View Slide

  77. This technologies allow
    you to create a factory of
    products / services

    View Slide

  78. Thank you!
    Questions?

    View Slide