This question evaluates a candidate's ability to design persistent storage and in-memory data structures, covering serialization of arbitrary values, medium/interface design for byte-level persistence, crash-consistent flushing, error handling, and performance and complexity analysis.
Design and implement an in-memory key-value store with a 'medium' layer that serializes the store to bytes for persistence. Provide four functions: set(key, value), get(key), shutdown(), and restore(). On shutdown(), flush all data to the medium; on restore(), rebuild state from the medium. Specify: (a) the medium interface for writing/reading bytes, (b) the serialization format and handling of arbitrary values, (c) error handling and data integrity (atomic flush, crash consistency), (d) complexity and performance considerations, and (e) minimal tests and example usage.