liveBook · Manning

Serialization

As explained in Latency

Serialization is the conversion of in-memory data structures or objects into a representation suitable for storage or transmission.

Serialization converts an in-memory data structure into a representation suitable for network transport or storage. Deserialization reverses that conversion so an application can work with the data again. Both transformations can consume CPU time and involve memory copies, making them important to inspect when reducing latency. section 7.3

An order crossing system boundaries

A client can serialize an order as JSON and send it to a REST API. The server deserializes it for processing, then may serialize it again for a data store or encode it as Protocol Buffers for an RPC. Each boundary is a place to ask whether another conversion is necessary. section 7.3

Figure 7.2 Serialization transforms the in-memory representation of data (shown on the left as a Rust struct) to a serialized format such as JSON (shown on the right). Deserialization performs the opposite transformation from a serialized format to an in-memory representation.
Figure 7.4: Serialization transforms in-memory representation to a serialized format such as JSON. Deserialization performs the opposite transformation from serialized format to in-memory representation.

Compare the Rust struct with its JSON representation: the same order fields have different in-memory and transport forms. section 7.3

Start optimization by profiling the application, then locate where serialization and deserialization occur. Look for redundant transformations and copies before changing formats. Serialization should not be confused with serializability, which concerns whether concurrent database transactions have results equivalent to sequential execution. section 7.1 section 7.3 section 9.4.1

How Latency covers it

How deep it goes
Defines both conversion directions and illustrates byte representation, but does not provide a serialization implementation.
Examples
Traces an online-store order through JSON transport, server processing, storage, and a possible Protocol Buffers RPC.
What it assumes
Assumes familiarity with application data and client-server communication while explaining the conversion between in-memory and transported representations.
What you can do after
Diagnose/debug with it by profiling conversion work and checking for redundant serialization, deserialization, or memory copies.
How it connects
Connects deserialization with REST APIs, JSON, RPC, Protocol Buffers, and application latency.

Also explained in

Compare how 24 books explain serialization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Latency. The section links point to the parts of the book it draws on.