Serialization
Сериализация
Serialization turns data from a running program into text or bytes that can be stored or sent to another program. Deserialization reads that representation back into usable data.
Why programs serialize data
Imagine a web server has an order in memory. It can't send the browser a reference to that order: the reference only makes sense inside the server process. Instead, the server writes the relevant values in a format both sides understand. The browser can read those values into its own data structures, even if it runs a different programming language.
What goes into the serialized form?
A serializer takes values such as strings, numbers, and lists and represents them according to a format's rules. The result might be JSON text or a binary message such as Protocol Buffers. The receiving code decodes the representation, checks that it meets the application's requirements, and converts values to application-specific types where needed. Parsing and validation are different steps: {"quantity": -1} is valid JSON, but an ordering API may reject it.
Example: a JSON round trip in Python
import json
order = {"id": 42, "items": ["notebook", "pen"]}
text = json.dumps(order) # A JSON string
copy = json.loads(text) # A new dictionary
assert copy == order
assert copy is not order
The values survive this round trip because their types map directly to JSON. That's not true of every Python type. For example, a tuple serializes as a JSON array and comes back as a list. If the distinction matters, the receiving code needs a rule for converting the list back to a tuple.
Where it's used and what can go wrong
Web APIs serialize response bodies, workers serialize jobs before putting them on a queue, and apps serialize state they need to reload after a restart. JSON is easy to inspect by hand. Protocol Buffers is often more compact and uses an explicit schema, which is useful when services need a shared contract for field types and numbers.
Serialization is not encryption. If an API response includes an internal field, encoding it as JSON or a binary message doesn't hide it. Select which fields leave the application rather than serializing an entire internal object by default. On input, validate data against the contract and avoid object deserializers that can execute code when reading untrusted input.
What interviewers look for
Expect questions about what happens when the sender and receiver run different versions. For example, can a new worker read a job that was queued yesterday, before a field was added? Decide how to handle missing fields and whether older readers accept unknown ones. Then test with messages from both versions: a same-version round trip doesn't test compatibility across a rollout.