Implement a Persistent Array for Cheap Config Snapshots
Last updated: November 29, 2026
Quick Overview
A serving binary keeps a large array of per-shard settings and must hand readers immutable snapshots while writers apply updates; implement a persistent array with path copying so each update costs O(log n) memory instead of copying the whole array.
0
0
0 solved
A serving binary keeps a large array of per-shard settings and must hand readers immutable snapshots while writers apply updates; implement a persistent array with path copying so each update costs O(log n) memory instead of copying the whole array.
Google servers often publish configuration or index snapshots that many request threads read lock free while a background thread prepares the next version. Interviewers use this to test structural sharing, memory accounting, and the trade-off against copy-on-write of the full array.
What the Interviewer Expects
- Contrast full copy-on-write with structural sharing
- Build a fixed-depth tree with a branching factor
- Copy only the root-to-leaf path on update
- Keep old versions valid and unchanged
- Quantify memory and time per update and read
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you choose the branching factor for CPU caches?
- How do readers safely pick up a new root in C++?
- How would you reclaim versions no reader still uses?
- When is a plain RCU copy of the whole array better?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
PArray.from_list(values, branch=32).get(i)in O(log_b n).set(i, v)returns a newPArray; the original is unchanged.- Versions share untouched nodes.
- Report how many nodes an update ...
High-Level Design
Store values in leaves of a tree with branching factor b and depth d = ceil(log_b n). Index i is read in base b: the top digit picks the child of the root, and so on. An update copies the root...