Protocol Buffer Fantásticos y donde encontrarlos

karesti 328 views 26 slides Apr 13, 2021
Slide 1
Slide 1 of 26
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26

About This Presentation

La serialización de Java es el caballo de batalla de la JVM, donde los fallos de seguridad no parecen llegar a su fin. Además, con las arquitecturas de microservicios en la nube, el intercambio de información entre múltiples plataformas de forma rápida y segura se ha vuelto mas indispensable qu...


Slide Content

Protocol Buffers Fantásticos
y donde encontrarlos
Katia Aresti, Infinispan Team, Red Hat

@karesti
Objetivo y reto de la próxima hora

Compartir el interés de utilizar Protocol Buffers en Java.

Mostrar ejemplos de proyectos que lo utilizan.

@karesti

@karesti
Serialization / Marshalling
_Heart_ Heart

@karesti
Serialization in Java - Desde 1997
public class PersonalShopper implements Serializable
{
private String id;
private String name;
private City city;

...
-ObjectInputStream
-ObjectOutputStream

@karesti
“The gift that keeps on giving”
"Ask The Architect" session from the
Devoxx UK 2018 conference,
Oracle's chief architect, Mark
Reinhold, shared his thoughts
about Java’s serialization
mechanism which he called a
“horrible mistake” and a
virtually endless source of security
vulnerabilities.
https://www.infoq.com/articles/java-serialization-aug18/

@karesti
Alternativas
-JSON
-XML
-Apache Thrift (Facebook)
-Apache Avro
-Microsoft Bond
-Protocol Buffers (Google)

@karesti
JSON

✅ HTTP/JSON es el estandard en la web, REST API standard
✅ Formato que podemos leer los seres humanos
✅ Javascript Nativo

❗ Marshalling lento para formatos numéricos (problemas de latencia)
❗No es tan eficiente en la red (compresión de datos ayuda)
❗Sistema de tipos pobre
❗Java <-> Json Jackson, Gson

@karesti

@karesti
Protocol buffers - Protobuf
●Google (utilizado masivamente en interno)
●Formato Binario
●Open Source desde 2008
●Interoperabilidad entre muchos lenguajes languages: C++, C#, Java, Dart,
Python,Go
●Estructurado tipo XML, más ligero, compacto y rápido
●Mejor rendimiento que JSON

https://github.com/protocolbuffers/protobuf

@karesti
Paso 1: Define tu *.proto esquema

syntax = "proto2";
package mycompany;
message PersonalShopper {
optional string id = 1;
optional string name = 2;
optional string city = 3;
}

@karesti
Paso 2: Compila y genera el código
People.PersonalShopper shopper1 =
People.PersonalShopper.newBuilder()
.setId(UUID.randomUUID().toString())
.setCity("BILBAO")
.setName("Oihana").build();



shopper1.writeTo(output);

@karesti
Demo
Protoc

@karesti
Algunos lugares donde encontramos Protobuf

●gRPC
●Kafka
https://docs.confluent.io/platform/current/schema-registry/serdes-develop/serdes-protobuf.html
●Twitter
https://github.com/twitter/elephant-bird
●Infinispan
http://infinispan.org

@karesti
Algunos lugares donde encontramos Protobuf

●gRPC
●Kafka
https://docs.confluent.io/platform/current/schema-registry/serdes-develop/serdes-protobuf.html
●Twitter
https://github.com/twitter/elephant-bird
●Infinispan
http://infinispan.org

@karesti
Caso 1: gRPC
Remote Procedure Call (g-google)


https://grpc.io/docs/what-is-grpc/introduction/

gRPC Conf 2020

@karesti
gRPC + Quarkus
https://quarkus.io/blog/quarkus-grpc/ by Clément Escoffier

@karesti
Demo
gRPC

@karesti
Caso 2: Infinispan (Datagrid )
●100% Open-source, In-memory Distributed Data
Store*
○~ Redis, Apache Ignite, Hazelcast
●Cachés distribuidas con múltiples casos de uso
●Diseñado para soportar 50.000 peticiones en
paralelo
●High Availability/High Scalability

@karesti
Client/Server
Data
Data lives here
Defines encodings
Client APP
Connect a client
(Java, Node, C#...)
Use a marshaller

@karesti
Comparing Cache Encodings



Marshalled
Java
Text Protobuf
Infinispan Server Web Console ✅ + ❌ ✅ ✅
REST Client ✅ ✅ ✅
Java Hotrod* Client ✅ ✅ ✅
Other Hotrod Clients (C#, Node…) ❌ ✅ ✅
Search ✅ + ❌ ❌ ✅
Custom Java Objects - ❌ ✅
* Hot Rod is the Infinispan binary communication protocol implemented by Infinispan Server

@karesti
Protobuf Caches - Infinispan Protostream

@karesti
Demo
Spring-Boot
Infinispan Java Caches
Infinispan Protobuf Caches

@karesti
To go further
●Protobuf
https://developers.google.com/protocol-buffers


●gRPC
https://grpc.io/


●Infinispan Getting Started
https://infinispan.org/get-started/

●Demo with Spring-Boot
https://github.com/karesti/protobuf-marshalling-guide

@karesti
Conclusiones

Que la serialización de Java descanse en paz pronto.

Protobuf es una muy buena opción que merece la pena
utilizar en vuestros sistemas distribuidos.

@karesti
Alguna pregunta ... y gracias!