What Is Serialization?
Serialization is a foundational technique in distributed systems, letting applications capture an object's state and move it between processes, machines, and data stores. But what is serialization exactly, and how does serialization work? We'll go over all the details in this article.
What Is Serialization? How Does Serialization Work?
Serialization is the process of converting a data object — a combination of code and data held within a region of memory — into a series of bytes that saves the object's state in an easily storable or transmittable form. Once an object is serialized, the resulting byte stream can be written to disk, placed in a cache, or delivered across a network to another application or key-value store. The reverse operation, reconstructing the object from those bytes, is called deserialization.
An object in memory can contain nested fields, references, and structure, so saving or sending all of its parts by hand would require significant custom code. Serialization provides a standard, repeatable way to flatten all of that into a single portable byte stream, and to recreate the object faithfully at its destination.
Why Is Serialization Important?
Serialization is what allows objects to leave the boundaries of a single application. With it, you can transfer objects over the wire for messaging, pass them between services through REST APIs or RPC, move them across domains and firewalls, persist them to a database, and store them in a cache for later reuse.
It is especially critical in distributed systems, where data and its replicas are spread across multiple nodes. Whenever an object leaves the local JVM — added to a distributed map, pushed onto a queue, published to a pub/sub topic, or replicated to another cluster member — it must first be serialized, then deserialized on the receiving side.
Common Serialization Formats
Serialized data is often represented as JSON or XML, which are human-readable and portable across programming languages, or as a compact binary format, which tends to be faster and more space-efficient because it carries less markup. Many popular languages — including Java, .NET, C++, Python, and Go — provide either native serialization support or libraries that add it.
Java offers built-in serialization through the Serializable interface, but purpose-built libraries such as Kryo, Jackson, Protobuf, and Avro are widely used instead, offering better performance, smaller payloads, schema versioning, or cross-language compatibility that native Java serialization does not.
Serialization in Redis, Valkey, and Redisson
Redis and Valkey store data as raw bytes, so any Java object must be serialized before it can be written and deserialized when it is read back. Because Redis and Valkey are not compatible with Java out of the box, many developers use a third-party Java client such as Redisson, which handles this conversion automatically through a pluggable codec layer.
By default, Redisson uses the Kryo5Codec, a compact binary codec that is typically faster and more space-efficient than standard JDK serialization. Redisson also supports many other codecs, including Jackson (JSON), Avro, Smile, CBOR, MsgPack, Amazon Ion, Protobuf, and JDK serialization, along with LZ4 and Snappy compression wrappers. A codec can be configured globally or per object, letting you choose the right trade-off between speed, payload size, and cross-language readability for each use case. See the Redisson data serialization guide for the full list and configuration details.