From Monolith to Microservice: Building APIs with gRPC & golang

From Monolith to Microservice: Building APIs with gRPC & golang

Case study & tutorial on how to break up a legacy monolith codebase into microservices using gRPC + Protobuf + golang + the language of your choice!

045d790f605ea8d482380c5075d802d5?s=128

Cecy C.

June 09, 2018
Tweet

Transcript

  1. 4.
  2. 8.
  3. 11.
  4. 14.
  5. 15.

    The “RPC” part stands for “remote procedure call,” and it’s

    essentially the same as calling a function in JavaScript, PHP, Python and so on, taking a method name and arguments. Source: Smashing Magazine
  6. 20.
  7. 24.

    Why gRPC? • Use HTTP/2 • Language agnostic • Highly

    efficient / scalable • Handle large amounts of data
  8. 25.
  9. 26.
  10. 31.

    Who is using it? • Google • Netflix • Docker

    • Square • CoreOS • Twitch (Twirp)
  11. 32.
  12. 36.

    What we will do • Use protobuf to define your

    service • Use protoc to generate client and server stubs based on your service definition • Create a gRPC server to handle requests
  13. 40.
  14. 41.
  15. 46.

    project-dir ├── client | └── client.go|js|rb|py ... ├── proto |

    └── service.proto ├── server | └── server.go|js|rb|py ... └── libs └── ruby └── python └── ...
  16. 48.
  17. 50.
  18. 52.
  19. 53.

    *Note: you will need to install some stuff to get

    started in PHP • composer install grpc as a dependency • pecl install grpc / protobuf • Full instructions on getting started: https://grpc.io/docs/quickstart/php.html
  20. 54.
  21. 55.
  22. 58.
  23. 59.

    Pain points • Legacy codebase (~10 years old) • Monolith

    codebase • Heavily coupled == hard to unit test • Scaling problems
  24. 60.

    How gRPC helped • Replace small pieces of functionality with

    microservices • Easy to do by “resource”
  25. 61.

    From REST to microservice GET /discovery Discovery service GET /user/:id/contacts

    Contacts service GET | POST /user/:id/webhooks Webhooks service GET | POST /webhooks GET /user/:id/messages Messages services GET /user/:id/folders Folder service
  26. 64.

    This solves... • Feature parity between API and client libraries

    • Feature parity between API and docs • Lack of knowledge in the team around certain languages • Easy for other teams to consume your service
  27. 69.
  28. 72.
  29. 73.
  30. 74.