Serialization and Deserialization: From First Principles

Software developer with a strong foundation in React, Node.js, PostgreSQL, and AI-driven applications. Experienced in remote sensing, satellite image analysis, and vector databases. Passionate about defense tech, space applications, and problem-solving. Currently building AI-powered solutions and preparing for a future in special forces.
Why Data Needs to Be Translated Before It Can Travel
Modern backend systems are fundamentally about communication.
A frontend written in JavaScript talks to a backend written in Python, Java, or Go.
These systems may run on different machines, different operating systems, and different architectures.
Yet, somehow, they understand each other.
This blog answers a deceptively simple question:
How does data move from one program to another across a network, and still make sense on the other side?
The answer lies in serialization and deserialization.
1. The Core Problem: Programs Can’t Send Objects
Let’s start from first principles.
A program works with in-memory objects:
JavaScript objects
Python dictionaries
Java classes
These objects:
Live in RAM
Have language-specific structure
Depend on compiler/runtime internals
Important Insight
Memory structures are not portable. You cannot take a Python object in memory and “send” it directly to another machine.
Networks only transmit bytes.
So the fundamental problem is:
How do we convert rich in-memory data structures into a sequence of bytes — and back again?
2. Client–Server Communication Basics
In a typical backend system:
A client (browser, mobile app) sends a request
A server processes it and sends a response
They communicate using protocols like:
HTTP / REST
WebSockets
gRPC
Let’s focus on HTTP for simplicity.
For example:
GET /users
POST /users { data }
The client and server must agree on how data is represented.
Agreement is impossible without standardization.
3. Why Raw Memory Cannot Cross the Network
Imagine this JavaScript object on the frontend:
{
name: "Shiv",
age: 22
}
Internally:
JavaScript represents this in a JS engine–specific memory layout
Python represents dictionaries completely differently
Critical Constraint
Different languages, runtimes, and CPUs interpret memory differently.
So instead of sending memory, we send data representations.
4. What Is Serialization?
Serialization is the process of converting an in-memory data structure into a standardized format that can be transmitted or stored.
Formally:
Object → Byte Stream
Intuition
Serialization is like converting spoken language into written text so it can be mailed.
5. What Is Deserialization?
Deserialization is the reverse process of converting received bytes back into an in-memory data structure.
Formally:
Byte Stream → Object
Intuition
Deserialization is reading the letter and reconstructing the meaning in your head.
6. Where Serialization Fits in the Network Stack
Your notes correctly hint at the OSI model.
Conceptually:
Application Layer → structured data (objects)
Transport & Network Layers → raw bytes
Physical Layer → electrical signals
Serialization happens at the application boundary.

7. Text vs Binary Serialization Formats
Not all serialization formats are the same.
Text-Based Formats
Examples:
JSON
XML
YAML
Characteristics
Human-readable
Easy to debug
Language-agnostic
Larger payload size
Slower parsing
Binary Formats
Examples:
Protocol Buffers (Protobuf) used in gRPC
Avro
MessagePack
Characteristics
Compact
Faster to parse
Strict schemas
Not human-readable
Rule of Thumb
Public APIs → JSON
Internal microservices → Protobuf
8. JSON as a Concrete Example
Example
{
"name": "Shiv",
"age": 22
}
On the Frontend (JavaScript)
const data = {
name: "Shiv",
age: 22
};
const serialized = JSON.stringify(data);
On the Backend (Python)
import json
data = json.loads(serialized)
What happened?
JavaScript object → JSON string → bytes over network
Bytes → JSON string → Python dictionary
That conversion process is serialization + deserialization.
9. Under the Hood: What Actually Happens
Step-by-step:
Client creates an object
Object is serialized into JSON text
JSON is encoded into bytes (UTF-8)
Bytes travel over TCP/IP
Server receives bytes
Bytes decoded into text
Text parsed into native object
Important Insight
Serialization is not the same as transport.
Transport moves bytes. Serialization gives bytes meaning.
10. Trade-offs, Edge Cases, and Common Mistakes
Common Mistakes
Assuming order in JSON objects
Sending language-specific types (Date, BigInt)
Forgetting versioning
Breaking backward compatibility
Edge Cases
Floating point precision
Character encoding issues
Optional vs required fields
Schema evolution
11. Real Backend Use Cases
Serialization appears everywhere:
REST APIs (JSON)
gRPC microservices (Protobuf)
Message queues (Kafka, RabbitMQ)
Database storage
Caching (Redis)
Backend Reality
Most backend performance issues at scale involve serialization overhead, not business logic.
12. Summary
Let’s compress everything into first principles:
Programs cannot send memory
Networks only move bytes
Serialization converts objects → bytes
Deserialization converts bytes → objects
Standards (JSON, Protobuf) make communication possible
Every backend system depends on this abstraction
If backend systems are cities, serialization is the language everyone agrees to speak.


