Serialization and Deserialization for Backend Engineers
Language-agnostic wire communication, OSI application layer boundaries, JSON structure rules, and text vs binary serialization formats.
Serialization converts in-memory objects into a standard wire format (like JSON or Protobuf) for network transmission; Deserialization reconstructs wire bytes back into native objects. This common standard allows frontend apps in JavaScript and backends in Rust, Go, or Python to communicate seamlessly.
1. The Core Problem: Heterogeneous Languages Across Networks
In modern software architecture, client and server applications are almost always written in completely different programming languages. A frontend client running JavaScript in Google Chrome might communicate with a backend microservice written in Rust, Go, Python, or Java.
Because JavaScript objects and Rust typed structs have completely different memory layouts, machines cannot simply pass raw internal memory pointers across a network wire. They need a shared, language-agnostic common standard.
2. What is Serialization & Deserialization?
1Serialization (Encoding / Marshalling)
2Deserialization (Decoding / Unmarshalling)
// Client: JavaScript Object in Browser Memory
const newBook = { title: "Designing Data-Intensive Applications", author: "Martin Kleppmann" };
// Serialized into wire string:
JSON.stringify(newBook);
// ➔ '{"title":"Designing Data-Intensive Applications","author":"Martin Kleppmann"}'// Server: Deserialized into Rust Struct in Server Memory
#[derive(Deserialize, Serialize)]
struct BookDto {
title: String,
author: String,
}
// let book: BookDto = serde_json::from_str(&wire_payload)?;3. The Backend Mental Model & The OSI Layer Boundary
The Open Systems Interconnection (OSI) model describes network communication across 7 distinct layers, from the Application Layer (Layer 7) down to the Physical hardware layer (Layer 1).
As network packets travel across the internet, operating systems and routers convert application data into data frames, IP packets, and raw electrical/optical bits (010101). However, as a backend engineer, you operate at the Application Layer.
4. Serialization Standards: Text-Based vs. Binary Formats
Serialization standards generally fall into two primary architectural categories: text-based formats and binary formats:
| Format | Category | Primary Use Case & Characteristics |
|---|---|---|
| JSON | Text-Based | Universal standard (~80% of Web & REST APIs). Completely human-readable, lightweight, and native to all major languages. |
| YAML | Text-Based | Human-friendly configuration files (Kubernetes manifests, Docker Compose, CI/CD pipelines). |
| XML | Text-Based | Tag-heavy legacy enterprise format (SOAP web services, banking mainframes). Highly verbose. |
| Protocol Buffers (Protobuf) | Binary Format | High-performance binary serialization used with gRPC for low-latency internal microservices. ~40-60% smaller than JSON. |
| MessagePack / Avro | Binary Format | Compact schema-driven binary encoding for fast event streaming and analytics pipelines. |
5. JSON Structure & Syntax Rules
JSON (JavaScript Object Notation) is the most widely used serialization format for HTTP REST APIs. It is strictly governed by fundamental syntax rules:
1Enclosing Braces
{ and end with a matching closing brace }.2Keys Must Be Quoted Strings
"name": "Sachin"). Single quotes or unquoted keys are invalid JSON.3Supported Value Types
true/false), Arrays ([...]), Nested Objects ({...}), or null.6. End-to-End Request & Response Serialization Flow
Here is the complete lifecycle of a client-server interaction from first principles:
// 1. CLIENT SENDS REQUEST (Serialized JSON Body)
POST /api/books HTTP/1.1
Host: api.example.com
Content-Type: application/json
{
"id": 6,
"title": "Database Internals",
"author": "Alex Petrov"
}// 2. SERVER RESPONDS (Serialized JSON Response Array)
HTTP/1.1 201 Created
Content-Type: application/json
{
"status": "success",
"data": [
{ "id": 1, "title": "Designing Data-Intensive Applications" },
{ "id": 6, "title": "Database Internals" }
]
}17. JSON Wire Serialization & Parsing
Sends a structured JSON payload, inspects server-side deserialization into memory, and observes re-serialized JSON response.
18. Format Comparison: JSON vs YAML vs XML vs Protobuf
Compares text-based formats (JSON, YAML, XML) with binary wire formats (Protobuf) showing byte compactness and parsing differences.