protocol buffers and microservices
TRANSCRIPT
Protocol buffers and Microservices
Vladimir Dejanović
Voxxed Days Bristol 02Mar2017
@VladimirD_42#VDB17
Agenda
Before Protocol Buffers
Protocol Buffers
Should I care about Protocol Buffers
@VladimirD_42#VDB17
Agenda
Before Protocol Buffers
Protocol Buffers
Should I care about Protocol Buffers
Questions
@VladimirD_42#VDB17
Fast Forward to 1996
XML - Extensible Markup Language
@VladimirD_42#VDB17
Both Human-readable and Machine-readable
@VladimirD_42#VDB17
<attendee> <firstName>John</firstName> <lastName>Doe</lastName> <address> <city>Bristol</city> <street>Canon's Road</street> <number>1</number> </address></attendee>
XML Example
@VladimirD_42#VDB17
<attendee> <firstName>John</firstName> <lastName>Doe</lastName> <address> <city>Bristol</city> <street>Canon's Road</street> <number>1</number> </address></attendee>
XML Example
@VladimirD_42#VDB17
<attendee> <firstName>John</firstName> <lastName>Doe</lastName> <address> <city>Bristol</city> <street>Canon's Road</street> <number>1</number> </address></attendee>
XML Example
@VladimirD_42#VDB17
<xsd:element name="attendee" type="AttendeeType"/> <xsd:complexType name="AttendeeType"> <xsd:sequence> <xsd:element name="firstName" type="xsd:string"/> <xsd:element name="lastName" type="xsd:string"/> <xsd:element name="address" type="AddressType"/> </xsd:sequence> </xsd:complexType>
<xsd:complexType name="AddressType"> <xsd:sequence> <xsd:element name="city" type="xsd:string"/> <xsd:element name="street" type="xsd:string"/> <xsd:element name="number" type="xsd:decimal"/> </xsd:sequence> </xsd:complexType>
@VladimirD_42#VDB17
<attendee> <firstName>John</firstName> <lastName>Doe</lastName> <address> <city>Bristol</city> <street>Canon's Road</street> <number>1</number> </address></attendee>
XML Example
@VladimirD_42#VDB17
<attendee> <firstName>John</firstName> <lastName>Doe</lastName> <address> <city>Bristol</city> <street>Canon's Road</street> <number>1</number> </address></attendee>
XML Example
159
@VladimirD_42#VDB17
<attendee> <firstName>John</firstName> <lastName>Doe</lastName> <address> <city>Bristol</city> <street>Canon's Road</street> <number>1</number> </address></attendee>
XML Example
159
68
Fast Forward to 2000 ( sort of )
@VladimirD_42#VDB17
JSON“JavaScript Object Notation” (sometimes)
Both Human-readable and Machine-readable
Fast Forward to 2000 ( sort of )
@VladimirD_42#VDB17
JSON“JavaScript Object Notation” (sometimes)
Both Human-readable and Machine-readable
Developer Friendly
JSON Example
@VladimirD_42#VDB17
{ firstName : "John", lastName: "Doe", address: {
city: "Bristol",street: "Canon's Road",number: 1
}}
JSON Example
@VladimirD_42#VDB17
{ firstName : "John", lastName: "Doe", address: {
city: "Bristol",street: "Canon's Road",number: 1
}}
90 vs 159
JSON Example
@VladimirD_42#VDB17
{ firstName : "John", lastName: "Doe", address: {
city: "Bristol",street: "Canon's Road",number: 1
}}
90 vs 159
68
No JSON Schema
@VladimirD_42#VDB17
JSON Schema is an Internet Draft currently in its 5th version, which was released on October 13, 2016
No JSON Schema
@VladimirD_42#VDB17
JSON Schema is an Internet Draft currently in its 5th version, which was released on October 13, 2016
http://json-schema.org/latest/json-schema-core.html
Fast Forward some more ….
@VladimirD_42#VDB17
Welcome to Microservice Era
Monolith is OUT
(Present Time)
Fast Forward some more ….
@VladimirD_42#VDB17
Welcome to Microservice Era
Micro is IN
Monolith is OUT
(Present Time)
XML vs JSON
@VladimirD_42#VDB17
XML - security for valid messages ( XSD )
JSON - we hope all messages will be good
Protocol Buffer
@VladimirD_42#VDB17
Protocol buffers are a flexible, efficient, automated mechanism for serializing
structured data – think XML, but smaller, faster, and simpler.
Protocol Buffer
@VladimirD_42#VDB17
Protocol buffers are a flexible, efficient, automated mechanism for serializing
structured data – think XML, but smaller, faster, and simpler.
@VladimirD_42#VDB17
syntax = "proto2";package voxxed.bristol;option java_package = "com.voxxed.bristol.pojo";option java_outer_classname = "AttendeeProto";
message Attendee { required string first_name = 1; required string last_name = 2; message Address { required string city = 1; required string street = 2; required int32 number = 3; } optional Address address = 3;}
@VladimirD_42#VDB17
syntax = "proto2";package voxxed.bristol;option java_package = "com.voxxed.bristol.pojo";option java_outer_classname = "AttendeeProto";
message Attendee { required string first_name = 1; required string last_name = 2; message Address { required string city = 1; required string street = 2; required int32 number = 3; } optional Address address = 3;}
@VladimirD_42#VDB17
syntax = "proto2";package voxxed.bristol;option java_package = "com.voxxed.bristol.pojo";option java_outer_classname = "AttendeeProto";
message Attendee { required string first_name = 1; required string last_name = 2; message Address { required string city = 1; required string street = 2; required int32 number = 3; } optional Address address = 3;}
@VladimirD_42#VDB17
syntax = "proto2";package voxxed.bristol;option java_package = "com.voxxed.bristol.pojo";option java_outer_classname = "AttendeeProto";
message Attendee { required string first_name = 1; required string last_name = 2; message Address { required string city = 1; required string street = 2; required int32 number = 3; } optional Address address = 3;}
@VladimirD_42#VDB17
syntax = "proto2";package voxxed.bristol;option java_package = "com.voxxed.bristol.pojo";option java_outer_classname = "AttendeeProto";
message Attendee { required string first_name = 1; required string last_name = 2; message Address { required string city = 1; required string street = 2; required int32 number = 3; } optional Address address = 3;}
@VladimirD_42#VDB17
syntax = "proto2";package voxxed.bristol;option java_package = "com.voxxed.bristol.pojo";option java_outer_classname = "AttendeeProto";
message Attendee { required string first_name = 1; required string last_name = 2; message Address { required string city = 1; required string street = 2; required int32 number = 3; } optional Address address = 3;}
@VladimirD_42#VDB17
syntax = "proto2";package voxxed.bristol;option java_package = "com.voxxed.bristol.pojo";option java_outer_classname = "AttendeeProto";
message Attendee { required string first_name = 1; required string last_name = 2; message Address { required string city = 1; required string street = 2; required int32 number = 3; } optional Address address = 3;}
@VladimirD_42#VDB17
syntax = "proto2";package voxxed.bristol;option java_package = "com.voxxed.bristol.pojo";option java_outer_classname = "AttendeeProto";
message Attendee { required string first_name = 1; required string last_name = 2; message Address { required string city = 1; required string street = 2; required int32 number = 3; } optional Address address = 3;}
@VladimirD_42#VDB17
syntax = "proto2";package voxxed.bristol;option java_package = "com.voxxed.bristol.pojo";option java_outer_classname = "AttendeeProto";
message Attendee { required string first_name = 1; required string last_name = 2; message Address { required string city = 1; required string street = 2; required int32 number = 3; } optional Address address = 3;}
@VladimirD_42#VDB17
syntax = "proto2";package voxxed.bristol;option java_package = "com.voxxed.bristol.pojo";option java_outer_classname = "AttendeeProto";
message Attendee { required string first_name = 1; required string last_name = 2; message Address { required string city = 1; required string street = 2; required int32 number = 3; } optional Address address = 3;}
@VladimirD_42#VDB17
syntax = "proto2";package voxxed.bristol;option java_package = "com.voxxed.bristol.pojo";option java_outer_classname = "AttendeeProto";
message Attendee { required string first_name = 1; required string last_name = 2; message Address { required string city = 1; required string street = 2; required int32 number = 3; } optional Address address = 3;}
@VladimirD_42#VDB17
syntax = "proto2";package voxxed.bristol;option java_package = "com.voxxed.bristol.pojo";option java_outer_classname = "AttendeeProto";
message Attendee { required string first_name = 1; required string last_name = 2; message Address { required string city = 1; required string street = 2; required int32 number = 3; } optional Address address = 3;}
@VladimirD_42#VDB17
syntax = "proto2";package voxxed.bristol;option java_package = "com.voxxed.bristol.pojo";option java_outer_classname = "AttendeeProto";
message Attendee { required string first_name = 1; required string last_name = 2; message Address { required string city = 1; required string street = 2; required int32 number = 3; } optional Address address = 3;}
@VladimirD_42#VDB17
syntax = "proto2";package voxxed.bristol;option java_package = "com.voxxed.bristol.pojo";option java_outer_classname = "AttendeeProto";
message Attendee { required string first_name = 1; required string last_name = 2; message Address { required string city = 1; required string street = 2; required int32 number = 3; } optional Address address = 3;}
Generated Code
static Attendee parseFrom(byte[] data)
static Attendee parseFrom(InputStream input)
@VladimirD_42#VDB17
Backward Compatibility Don'ts
Change the tag numbers of any existing fields
Add or Delete any required fields
@VladimirD_42#VDB17
Backward Compatibility Do's
Delete optional or repeated fields.
Add new optional or repeated fields
@VladimirD_42#VDB17
Backward Compatibility Do's
Delete optional or repeated fields.
Add new optional or repeated fields (But you must use fresh tag numbers )
@VladimirD_42#VDB17
Conclusion
Protocol Buffers would not be a good way to model a text-based document with markup
@VladimirD_42#VDB17