Interview conceptCoding & Algorithms

In-Memory Object-Oriented API Design

Asked of: Software Engineer

Last updated

Architecture diagram showing an in-memory object-oriented API: validated requests flow through domain objects into indexed state, with permissions, quotas, IDs, sorting, and TTL managed explicitly.

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 than O(n) scans.

  • Normalize case-insensitive fields once with lower() or casefold(); 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 via purge().

  • 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

Related concepts