In this chapter
We'll meet serialization — the real, necessary process of turning a structured, in-memory object into storable bytes — and its exact reverse, deserialization, seeing exactly how GreenMart's own event objects make this real, consequential journey before a storage engine ever touches them.
The Problem in Real Life
Now that the event log lives on Cassandra, Sarah turns to a real, different question. "Every event we write starts as a real, in-memory object in the app's own code," she says. "Before it can be stored anywhere at all, something has to turn that object into actual bytes."
Mike hadn't thought about that step. "I guess I assumed that just... happens automatically?"
How does an object in our app's code actually turn into bytes we can store?
Mike
An Object in Memory vs. A Real Sequence of Storable Bytes
A real, necessary translation step
An in-memory object is meaningless outside its own process — serialization makes it a portable, storable sequence of bytes.
A genuinely different layer from storage engines
Serialization decides what bytes look like; a storage engine decides how those already-serialized bytes get organized on disk.
Serialization & Deserialization
Serialization is the real, deliberate process of converting a structured, in-memory object into a real sequence of bytes suitable for storage or transmission. Deserialization is the exact real reverse: turning those stored bytes back into a usable, in-memory object. Every write to any real storage system GreenMart has ever used — this whole course franchise — quietly depends on this real step.
- Why this real step is necessary at all. An in-memory object — a real class instance, a nested structure with references — exists in a form specific to the running program's own memory layout, genuinely meaningless outside that process. Serialization produces something real, portable, and storable instead: a flat, self-contained real sequence of bytes that any process, any system, any real storage engine can actually write, read, or transmit.
- A real, concrete example: GreenMart's own event. A stock-change event in the app's own code is a real object — a product ID, a quantity, a timestamp, maybe nested details about which warehouse. Serializing it means converting all of that into one real, linear sequence of bytes; deserializing means an application reading it back later reconstructing that same real object from those bytes, faithfully.
- Choices that genuinely matter, made during serialization. How are real numbers represented — as text digits, or as compact binary values? How is a real field's name and structure preserved — spelled out every time, or referenced by a real, shared schema known in advance? These aren't minor details; they directly determine the real, resulting size of the serialized bytes, and how much real work deserialization later has to do — exactly the real trade-off the next chapter goes deep on.
- A genuinely different concern from the last four chapters. Storage engines (B-trees, LSM trees) decide how already-serialized bytes get organized and found on disk. Serialization decides what those bytes actually look like in the first place, before they ever reach a storage engine at all — two real, separate, complementary layers, not the same real question asked twice.
GreenMart now has the real, missing step between "an object in the app's own code" and "bytes a storage engine can actually write" — a real, deliberate process with real, consequential choices, not something that simply happens by magic.
Key Takeaway
Serialization turns a structured, in-memory object into a real, portable sequence of bytes, and deserialization reverses it — a genuinely distinct real layer from how a storage engine organizes those bytes on disk, with real choices (like number and field representation) that directly determine size and processing cost.
Why This Matters
Every real event GreenMart's own app writes to Cassandra, every real API response the storefront sends a browser, passes through this exact real step — understanding it is what lets GreenMart make deliberate, informed choices about format instead of accepting whatever a library happens to default to.
GreenMart now has the real, necessary concept of serialization and deserialization — the step between an object and storable bytes. The next chapter goes deep on the real, concrete choice that step actually involves: JSON versus binary formats.
