In-Memory Object-Oriented API Design
Asked of: Software Engineer
Last updated

What's being tested
These problems test object-oriented API design for stateful, in-memory systems: modeling entities, enforcing invariants, and exposing clean CRUD/query methods. You must demonstrate nested data structures, deterministic sorting/search, ID generation, permissions, expiration, quotas, and evolving APIs without tangled state management.
Patterns & templates
-
Use layered classes such as
`Storage`,`Folder`,`File`,`Recipe`, or`Task`; keep ownership, validation, and mutation responsibilities explicit. -
Represent hierarchy with
`dict[id, object]`plus parent-child collections; maintain indexes when queries must be faster thanO(n)scans. -
Normalize case-insensitive fields once with
lower()orcasefold(); preserve original display text while comparing canonical values. -
Generate IDs centrally using a monotonic counter or UUID; never derive identity from mutable names, positions, or timestamps alone.
-
Implement prioritized sorting with a stable composite key, for example
(-priority, due_date, created_at, id); specify tie-breaking explicitly. -
Model TTL using
expires_at = created_at + ttl; inject a clock for tests and remove expired entries lazily or viapurge(). -
Enforce quotas and time windows atomically within one method; validate before mutating so rejected operations leave state unchanged.
-
Return copies or immutable views from getters; otherwise callers can bypass permissions, indexes, and invariants through shared mutable references.
Common pitfalls
Pitfall: Mixing storage, authorization, search, and formatting in one method makes API changes fragile; separate domain operations from presentation.
Pitfall: Forgetting empty collections, duplicate names, missing parents, expired objects, equal priorities, and edits by unauthorized users causes hidden-test failures.
Pitfall: Claiming
O(1)lookup while scanning nested lists undermines the design; state the actual complexity and add indexes only when justified.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Practice questions
- Implement a multi-level digital recipe managerRamp · Software Engineer · Online Assessment · medium
- Multi-Level Warehouse Storage with Weighted RetrievalRamp · Software Engineer · Online Assessment · medium
- Implement multi-level task manager APIsRamp · Software Engineer · Online Assessment · medium
- Design an in-memory cloud storage systemRamp · Software Engineer · Online Assessment · hard
Related concepts
- In-Memory Stateful API DesignCoding & Algorithms
- Stateful In-Memory Domain APIsSoftware Engineering Fundamentals
- In-Memory Databases And Query ProcessingSystem Design
- Stateful In-Memory Data StructuresCoding & Algorithms
- In-Memory Databases And Query EnginesSystem Design
- Stateful Data Structures And OOP API DesignCoding & Algorithms