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

What's being tested
These problems test stateful in-memory API design: choosing data structures, defining method semantics, and preserving correctness across updates, expiration, snapshots, and state transitions. Interviewers are probing whether you can turn ambiguous product-like operations into deterministic code with clear invariants, edge-case handling, and stated complexity.
Patterns & templates
-
Primary map + secondary indexes — store canonical objects by
id, then maintainuser_id, prefix, status, or priority indexes; update all indexes atomically. -
Lazy TTL expiration — implement
isExpired(now, item)and purge on read/write; cheaper than background cleanup, but scans must filter expired entries. -
Snapshot semantics —
backup(timestamp)should serialize only live records;restore(timestamp)usually restores the latest backup at or before target time. -
State machine validation — define allowed transitions like
OPEN -> FILLED/CANCELED; make invalid or repeated transitions explicit no-ops or errors. -
Idempotent operations — repeated
cancel(order_id)orassign(task_id)should not corrupt counters, balances, quotas, or indexes. -
Sorted retrieval — use
heapq,bisect,TreeMap-style structures, or sorted lists for priority/top-k/prefix scans; state complexity clearly. -
Command/API parsing layer — separate parsing from core methods like
create_account,transfer,set_with_ttl,list_tasks; this keeps tests targeted and readable.
Common pitfalls
Pitfall: Updating the primary dictionary but forgetting to update secondary indexes, causing stale results in
list_by_user, prefix scans, or status queries.
Pitfall: Treating TTL as deletion only at write time; reads, backups, restores, and scans must all respect expiration at the provided timestamp.
Pitfall: Hand-waving complexity with “it’s in memory”; interviewers expect
O(1)lookup,O(log n)indexed updates, orO(n)scans to be stated precisely.
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 an In-Memory DatabaseCoinbase · Software Engineer · Take-home Project · hard
- Implement a crypto order management systemCoinbase · Software Engineer · Onsite · hard
- Design a task management system with TTLCoinbase · Software Engineer · Take-home Project · medium
- Design an in-memory banking systemCoinbase · Software Engineer · Take-home Project · medium
- Implement cloud storage with quotas and compressionCoinbase · Software Engineer · Technical Screen · medium
- Implement a versioned recipe management systemCoinbase · Software Engineer · Take-home Project · medium
- Design an in-memory database with TTL and backupsCoinbase · Software Engineer · Take-home Project · medium
- Implement a Simple Banking LedgerCoinbase · Software Engineer · Onsite · Medium
- Implement banking ops: transfer, top-k, cashback, mergeCoinbase · Software Engineer · Take-home Project · Medium
- Implement bank balance operationsCoinbase · Software Engineer · Technical Screen · Medium
- Design order stream with state transitionsCoinbase · Software Engineer · Onsite · Medium
Related concepts
- In-Memory Stateful Data ModelingCoding & Algorithms
- Stateful In-Memory Data StructuresCoding & Algorithms
- In-Memory Databases And Query ProcessingSystem Design
- Caching And Stateful Data Structure DesignCoding & Algorithms
- Stateful Data Structures And OOP API DesignCoding & Algorithms
- Idempotent API DesignSystem Design