Serialization
Serialization options in GridGain.NET, including IBinarizable, IBinarySerializer, ISerializable, and Ignite reflective serialization.
Most of the user-defined classes going through the GridGain.NET API will be transferred over the network to other cluster nodes. These classes include:
Cache keys and values
Cache processors and filters (
ICacheEntryProcessor,ICacheEntryFilter,ICacheEntryEventFilter,ICacheEntryEventListener)Compute functions (
IComputeFunc), actions (IComputeAction) and jobs (IComputeJob)Services (
IService)Event and Message handlers (
IEventListener,IEventFilter,IMessageListener)
Passing objects of these classes over the network requires serialization. Ignite .NET supports the following ways of serializing user data:
Apache.Ignite.Core.Binary.IBinarizableinterfaceApache.Ignite.Core.Binary.IBinarySerializerinterfaceSystem.Runtime.Serialization.ISerializableinterfaceIgnite reflective serialization (when none of the above applies)
IBinarizable
IBinarizable approach provides a fine-grained control over serialization. This is a preferred way for high-performance production code.
First, implement the IBinarizable interface in your class:
public class Address : IBinarizable
{
public string Street { get; set; }
public int Zip { get; set; }
public void WriteBinary(IBinaryWriter writer)
{
// Alphabetic field order is required for SQL DML to work.
// Even if DML is not used, alphabetic order is recommended.
writer.WriteString("street", Street);
writer.WriteInt("zip", Zip);
}
public void ReadBinary(IBinaryReader reader)
{
// Read order does not matter, however, reading in the same order
// as writing improves performance.
Street = reader.ReadString("street");
Zip = reader.ReadInt("zip");
}
}IBinarizable can also be implemented in raw mode, without field names. This provides the fastest and the most compact serialization, but disables SQL queries:
IBinarySerializer
IBinarySerializer is similar to IBinarizable, but separates serialization logic from the class implementation. This may be useful when the class code can not be modified, and serialization logic is shared between multiple classes, etc. The following code has exactly the same serialization as in the Address example above:
The Serializer should be specified in the configuration like this:
ISerializable
Types that implement the System.Runtime.Serialization.ISerializable interface will be serialized accordingly (by calling GetObjectData and serialization constructor). All system features are supported: IObjectReference, IDeserializationCallback, OnSerializingAttribute, OnSerializedAttribute, OnDeserializingAttribute, OnDeserializedAttribute.
The GetObjectData result is written into the Ignite binary format. The following three classes provide identical serialized representation:
Ignite Reflective Serialization
Ignite reflective serialization is essentially the IBinarizable approach where the interface is implemented automatically by reflecting over all fields and emitting write/read calls.
There are no requirements for this mechanism, any class or struct can be serialized including all system types, delegates, expression trees, or anonymous types.
Use the [NonSerialized] attribute to filter out specific fields during serialization.
The raw mode can be enabled by specifying BinaryReflectiveSerializer explicitly:
Otherwise, BinaryConfiguration is not required.
Performance is identical to manual the IBinarizable approach. Reflection is only used on startup to iterate over the fields and emit efficient IL code.
Types marked with [Serializable] attribute but without ISerializable interface are written with Ignite reflective serializer.
Using Entity Framework POCOs
The Entity Framework POCOs can be used directly with Ignite.
However, POCO proxies cannot be directly serialized or deserialized by Ignite, because the proxy type is a dynamic type.
Make sure to disable proxy creation when using EF objects with Ignite:
More Info
See Ignite Serialization Performance blog post for more details on serialization performance of various modes introduced on this page.
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

