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

PyConES2018: Python & gRPC, el conquistador de microservicios

PyConES2018: Python & gRPC, el conquistador de microservicios

Python & gRPC, el conquistador de microservicios
Empezar de cero con microservicios puede ser un reto. ¿que escribimos primero? ¿Qué lenguaje de programación utilizamos? ¿Cuál protocolo utilizamos? Las nuevas tecnologías open source para el stack de APIs son HTTP/2, Protocol buffers y gRPC.

En esta charla aprenderás a conquistar los microservicios utilizando gRPC y Python sobre HTTP/2 haciendo uso de protocol buffers y a la vez asegurando que lo que desarrollas es mantenible, escalable y fácil de implantar en distintas arquitecturas y plataformas. Además, serviremos simultáneamente nuestras API en formato JSON/REST sobre HTTP/1.1.

Esteban Dorado Roldan

October 07, 2018
Tweet

More Decks by Esteban Dorado Roldan

Other Decks in Programming

Transcript

  1. Python & gRPC El conquistador de microservicios Esteban Dorado Software

    Engineer @Mr_Esti Ricardo Vegas Software Architect @ricardovegas
  2. Scenario - A currency service Currency Service Currency Lookup Mobile

    Android Mobile iOS Backend Processes Desktop Report tool Website Backend Android Java/Kotlin Objective-C Java, Python, Scala C#, Java NodeJS
  3. RESTful API non-RESTful API GET /user/69 { “Id” : 123456,

    “name” : ”Esteban”, . . . } GET /last_user?page=15 { “items” : [ . . . ] . . . }
  4. What is gRPC? • Google open sourced in Feb 2015

    • Transport: HTTP/2 • Wire format: Protocol Buffers v3 (Binary) • Service definition: Protocol Buffers IDL • Libraries in ~10 languages (native C, Go, Java) • Microservices framework • Part of Cloud Native Computing Foundation cncf.io • Pre-defined error status codes • Secure Connection by default
  5. HTTP/2 - Multiplexed • multiple reqs/resps can be in-flight over

    one conn • avoid multiple TCP conns to make parallel requests
  6. • 'independent, bidirectional sequence of frames exchanged between the client

    and server within an HTTP/2 connection' • beyond request/response • effectively supersedes 'websockets' HTTP/2 - Streams
  7. Protocol Buffers (a.k.a. protobuf) • Mechanism for serializing structured data

    • Interface Definition Language (IDL) • Binary, compact, fast • Versioned • strongly typed
  8. Protobuf workflow Protobuf definitions Protoc compiler Python Golang Java gRPC

    server gRPC client 1 - Define 2 - Compile 3 - Implement Generate Stubs protoc --go_out=plugins=grpc
  9. Example - Generate Server and Client • Install Python of

    gRPC: $ pip install grpcio • Build protos: $ python -m grpc_tools.protoc -I . --python_out=. --grpc_python_out=. ./api.proto
  10. Backwards (HTTP) Compatibility • Run a reverse proxy JSON API

    in front of gRPC server • Generate via github.com/gengo/grpc-gateway
  11. Additional gRPC Features • Extensible middleware API using interceptors and

    tap handlers • Intercept requests to implement retry/backoff logic • Add tracing using interceptors • Add HTTP stream taps to implement rate limits • Support for pluggable authorization • Add monitoring and metrics using interceptors (e.g. Prometheus)
  12. Q&A