Binary Serialization And Codecs
Asked of: Software Engineer
Last updated

What's being tested
These problems test reversible serialization: converting maps, strings, or KV-store state into bytes and reconstructing the exact original data. Interviewers probe whether you can design binary-safe codecs that handle arbitrary bytes, Unicode, empty values, large inputs, malformed payloads, and format evolution without relying on fragile delimiters.
Patterns & templates
-
Length-prefix encoding — write
len(key) | key | len(value) | value;O(total_bytes)time, delimiter-free, handles arbitrary characters. -
Fixed-width integer headers — use
uint32oruint64lengths with explicit endianness; reject negative, overflowed, or truncated lengths. -
Type-length-value (
TLV) layout — encodetype | length | payloadfor extensible records; useful for versioned KV entries and metadata. -
Round-trip invariant — always test
deserialize(serialize(x)) == x; include empty map, empty string, Unicode, null bytes, duplicates, and huge values. -
Streaming parser — maintain an
offset, bounds-check before every read, and fail fast on trailing bytes or incomplete records. -
Versioned format header — prefix with
magic | version | flags; enables backward-compatible changes and early rejection of invalid data. -
Persistent mutation log — append
PUT/DELETErecords and replay into a map; optionally add checksums and compaction for robustness.
Common pitfalls
Pitfall: Using
:or,delimiters breaks as soon as keys or values contain the delimiter; prefer length-prefixing or escaping with strict decoding.
Pitfall: Forgetting bounds checks lets malformed input panic, over-read, or allocate massive buffers; validate every declared length before slicing.
Pitfall: Treating strings as characters instead of bytes causes Unicode bugs; serialize UTF-8 bytes and define whether keys/values are
stror rawbytes.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Featured in interview prep guides
Practice questions
- Implement Persistent KV Store SerializationOpenAI · Software Engineer · Technical Screen · hard
- Implement map serialization and deserializationOpenAI · Software Engineer · Onsite · medium
- Implement delimiter-free string codecOpenAI · Software Engineer · Technical Screen · medium
- Implement KV store serializationOpenAI · Software Engineer · Technical Screen · Medium
- Parse and build binary data in PythonOpenAI · Software Engineer · Technical Screen · Medium
- Implement in-memory KV store with serializationOpenAI · Software Engineer · Technical Screen · Medium
- Implement a serializable key-value storeOpenAI · Software Engineer · Technical Screen · Medium
Related concepts
- Serialization, Binary Encoding, And Persistent KV StoresCoding & Algorithms
- Deterministic Tree Encoding And DecodingCoding & Algorithms
- RLE And Bit-Packing CompressionCoding & Algorithms
- Composite Data Structures and O(1) OperationsCoding & Algorithms
- Arrays, Strings, Hash Maps, And Frequency CountingCoding & Algorithms
- Coding, Data Structures, And Parsing