Proposal: Ballerina SerDes module #2964
Labels
module/serdes
Issues related to the Ballerina serdes module
Status/Implemented
Implemented proposals
Type/Proposal
Summary
Proposing an effective way to serialize/deserialize Ballerina
anydata
type to send them efficiently over the wire.Goals
Motivation
Ballerina language supports the concept of anydata, which can be sent across the network. In order to do so, it is required to serialize/deserialize anydata in some form. Converting anydata to JSON and sending it over the wire is the current approach. Even though this approach is appropriate in certain use cases, there are more efficient ways to serialize/deserialize data such as proto3 (by Google) or avro (by Hadoop).
Description
As mentioned in the Goals section, the primary goal of this proposal is to come up with a standard library package to serialize and deserialize anydata type. Initially
proto3
will be used as the main underlying technology to implement the package. The package will include other technologies such asAvro
in future.Proto3
Protocol Buffers is a method of serializing structured data developed by Google, and proto3 is the latest version of Protocol Buffers. Protocol Buffers use
.proto
files to define messages (similar to a Ballerina record type) in proto3 syntax and the messages are used to generate the proto schema that can later be populated with data. These generated messages can be serialized/deserialized more efficiently compared to JSON. More information related to proto3 can be found in the official documentation.type
Following are the example of ballerina type to proto message
Primitvie
Array
Union
Record
Map
Table
Tuple
Enum
Ballerina enum is a syntactic sugar of union of constant strings thus enum is handled as union in protobuf level
SerDes API
Ex: Implementing Proto3 version of serialization & deserialization
Similar to the above
Proto3Schema
implementation other versions of serialization & deserialization can be implemented in future (Ex:AvroSchema
)Serialize
Deserialize
Design Considerations
The design of the Standard Library SerDes package can be divided into following 2 phases,
Dynamic Schema creation could be implemented as a separate Java package with the help of Protocol Buffers' Java API. Making this implementation independent of the rest of the code will make it easier to move between different serialization/deserialization technologies such as Avro in the future.
A parser should be implemented to convert Ballerina anydata to proto3 message and vice versa. The parser should be able to map Ballerina anydata types to proto3 field types.
Alternatives
Thrift, Avro are some alternative serialization technologies but proto3 has the fastest performance. Comparison between Avro and Protocol buffer can be found here.
The text was updated successfully, but these errors were encountered: