Fast Avro de/serializer for .NET
Introducing Avro to the projects brings three main benefits:
- Reduction of data size and storage cost
- Decrease of the communication time and the network traffic between microservices
- Increased security - the data is not visible in plain text format
AvroConvert | Apache.Avro | Newtonsoft.Json | |
---|---|---|---|
Rapid serialization | ✔ | ✔ | ✔ |
Easy to use | ✔ | X | ✔ |
Built-in compression | ✔ | ✔ | X |
Low memory allocation | ✔ | ✔ | ✔ |
Support for C# data structures: Dictionary, List, DateTime... | ✔ | X | ✔ |
Support for compression codecs | Deflate & GZip | Deflate | X |
Readable schema of data structure | ✔ | ✔ | ✔ |
Data encryption | ✔ | ✔ | X |
Results of BenchmarkDotNet:
Converter | Request Time [ms] | Allocated Memory [MB] | Compressed Size [kB] |
---|---|---|---|
Json | 642.1 | 151.45 | 6044 |
Avro | 254.3 | 71.27 | 2623 |
Json_Gzip | 194.7 | 85.45 | 514 |
Avro_Gzip | 131.5 | 64.15 | 104 |
Avro format combines readability of JSON and data compression of binary serialization. Apache Wiki Apache Avro format documentation
- Serialization
byte[] avroObject = AvroConvert.Serialize(object yourObject);
- Deserialization
CustomClass deserializedObject = AvroConvert.Deserialize<CustomClass>(byte[] avroObject);
- Read schema from Avro object
string schemaInJsonFormat = AvroConvert.GetSchema(byte[] avroObject)
- Deserialization of large collection of Avro objects one by one
using (var reader = AvroConvert.OpenDeserializer<CustomClass>(new MemoryStream(avroObject)))
{
while (reader.HasNext())
{
var item = reader.ReadNext();
// process item
}
}
- Generation of C# models from Avro file or schema
string resultModel = AvroConvert.GenerateModel(avroObject);
- Conversion of Avro to JSON directly
var resultJson = AvroConvert.Avro2Json(avroObject);